原文:https://ishadeed.com/article/defensive-css/
- flex 布局:
- 可以加上
flex-wrap: wrap; 来避免内容溢出
- 使用
gap 代替 space-between
- 溢出:
- 使用 min-height 代替 height
- 使用 min-width 代替 width
- 文本排版:可以给文本溢出加上安全 space
- 文本排版:定宽定高的文本展示区域,加上不换行的限制
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
- 图片排版:使用 object-fit 来避免拉伸
- 图片排版:给所有包含 img 的元素设置
background-color
- 交互:文本滚动溢出
- 限制仅滑动当前元素,不影响父元素
overscroll-behavior-y: contain;
overflow-y: auto;
- CSS 变量:考虑 fallback场景
max-width: calc(100% - var(—actions-width, 70px));
- background 属性:考虑设置
background-repeat: no-repeat,避免图片重复展示
原文:https://ishadeed.com/article/defensive-css/
flex-wrap: wrap;来避免内容溢出gap代替space-betweenmin-height: 100px;min-width: 100px;margin-right: 10px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;object-fit: cover;background-coloroverscroll-behavior-y: contain;overflow-y: auto;max-width: calc(100% - var(—actions-width, 70px));background-repeat: no-repeat,避免图片重复展示