阅3
CSS文字效果
CSS文字效果
1. 文字溢出效果
如果文本内容超出了容器的宽度或高度,可以通过以下方式进行处理,隐藏超出的文本并显示省略号。
单行文本溢出
css.text-over-hidden { white-space: nowrap; /* 禁止换行 */ overflow: hidden; /* 超出部分隐藏 */ text-overflow: ellipsis; /* 溢出显示省略号 */ }
多行文本溢出
css.text-over-hidden { overflow: hidden; word-break: break-all; /* 允许在单词内换行 */ text-overflow: ellipsis; /* 超出部分省略号 */ display: -webkit-box; /* 伸缩盒子模型 */ -webkit-box-orient: vertical; /* 设置伸缩盒子排列方式 */ -webkit-line-clamp: 1; /* 限制显示的行数 */ }
2. 推荐字体
常见字体
cssbody { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; /* 系统字体 */ }
谷歌字体推荐
- Roboto
html<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> <style> body { font-family: 'Roboto', sans-serif; } </style>
- Open Sans
html<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"> <style> body { font-family: 'Open Sans', sans-serif; } </style>
- Lato
html<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap" rel="stylesheet"> <style> body { font-family: 'Lato', sans-serif; } </style>
特殊字体设置
- 淘宝字体
cssfont-family: tahoma, arial, 'Hiragino Sans GB', '\5b8b\4f53', sans-serif;
3. 设置文字反差显示
通过 mix-blend-mode 属性,文字颜色与背景色之间可以实现不同的混合效果,常见的值有 normal, multiply, hard-light, difference 等。
css.text-blend { mix-blend-mode: multiply; /* 设置文字与背景的混合模式 */ }
4. 标题文字颜色与字体设置
根据不同的风格,选择合适的字体和颜色设置,下面是一些常见的推荐。
经典黑白组合
cssh1, h2, h3, h4, h5, h6 { font-family: "Georgia", "Times New Roman", Times, serif; color: #333333; /* 深灰色标题 */ }
柔和的灰色调
cssh1, h2, h3, h4, h5, h6 { font-family: "Lora", "Playfair Display", serif; color: #444444; /* 深灰色标题 */ }
现代深蓝色
cssh1, h2, h3, h4, h5, h6 { font-family: "PT Serif", "Bitter", serif; color: #2C3E50; /* 深蓝色标题 */ }
优雅的深绿色
cssh1, h2, h3, h4, h5, h6 { font-family: "Baskerville", "Crimson Text", serif; color: #2E8B57; /* 深绿色标题 */ }
活泼的橙色
cssh1, h2, h3, h4, h5, h6 { font-family: "Zilla Slab", "Bree Serif", serif; color: #E67E22; /* 橙色标题 */ }
总结
-
文字溢出 :使用
text-overflow: ellipsis和-webkit-line-clamp等属性来处理文本溢出,支持单行或多行显示。 -
推荐字体 :选择适合的字体并考虑字体回退机制,使用系统字体或引入 Google Fonts 的字体。
-
反差效果 :通过
mix-blend-mode来设置文字与背景之间的混合模式,增强视觉对比度。 -
标题颜色与字体 :根据不同风格选择合适的字体与颜色搭配,确保设计风格统一且美观。
这样整理的效果使得文字设计更加清晰和易于管理。
加载中...