美化网页元素
- 有效的传递网页信息
- 美化网页、页面漂亮、才能吸引用户
- 凸显页面的主题
- 提高用户的体验
CSS3字体
使用字体,通过 font-family 属性来引用字体的名称 (myFirstFont):
<style>
@font-face
{
font-family: myFirstFont;
src: url(sansation_light.woff);
}
div
{
font-family:myFirstFont;
}
</style>
使用粗体文字
@font-face
{
font-family: myFirstFont;
src: url(sansation_bold.woff);
font-weight:bold;
}
描述符 | 值 | 描述 |
---|---|---|
font-family | name | 必需。规定字体的名称。 |
src | URL | 必需。定义字体文件的 URL。 |
font-stretch | normal condensed ultra-condensed extra-condensed semi-condensed expanded semi-expanded extra-expanded ultra-expanded | 可选。定义如何拉伸字体。默认是 “normal”。 |
font-style | normal italic oblique | 可选。定义字体的样式。默认是 “normal”。 |
文本样式
-
text-shadow:水平阴影,垂直阴影,模糊的距离,以及阴影的颜色:
h1 { text-shadow: 5px 5px 5px #FF0000; }
-
box-shadow:盒子阴影
div { box-shadow: 10px 10px 5px #888888; } /*给阴影添加颜色*/ div { box-shadow: 10px 10px grey; } /*模糊效果*/ div { box-shadow: 10px 10px 5px grey; } /*在 ::before 和 ::after 两个伪元素中添加阴影效果*/ #boxshadow { position: relative; b ox-shadow: 1px 2px 4px rgba(0, 0, 0, .5); pa dding: 10px; bac kground: white; } #boxshadow img { width: 100%; border: 1px solid #8a4419; border-style: inset; } #boxshadow::after { content: ''; position: absolute; z-index: -1; /* hide shadow behind image */ box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3); width: 70%; left: 15%; /* one half of the remaining 30% */ height: 100px; bottom: 0; } /*使用特例是卡片效果*/ div.card { width: 250px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); text-align: center; }
-
text-overflow:溢出属性指定应向用户如何显示溢出内容
p.test1 { white-space: nowrap; width: 200px; border: 1px solid #000000; overflow: hidden; text-overflow: clip; } p.test2 { white-space: nowrap; width: 200px; border: 1px solid #000000; overflow: hidden; text-overflow: ellipsis; }
-
word-wrap:换行
p {word-wrap:break-word;}
-
word-break 单词拆分换行
p.test1 { word-break: keep-all; } p.test2 { word-break: break-all; }
属性 | 描述 | CSS |
---|---|---|
hanging-punctuation | 规定标点字符是否位于线框之外。 | 3 |
punctuation-trim | 规定是否对标点字符进行修剪。 | 3 |
text-align-last | 设置如何对齐最后一行或紧挨着强制换行符之前的行。 | 3 |
text-emphasis | 向元素的文本应用重点标记以及重点标记的前景色。 | 3 |
text-justify | 规定当 text-align 设置为 “justify” 时所使用的对齐方法。 | 3 |
text-outline | 规定文本的轮廓。 | 3 |
text-overflow | 规定当文本溢出包含元素时发生的事情。 | 3 |
text-shadow | 向文本添加阴影。 | 3 |
text-wrap | 规定文本的换行规则。 | 3 |
word-break | 规定非中日韩文本的换行规则。 | 3 |
word-wrap | 允许对长的不可分割的单词进行分割并换行到下一行。 | 3 |
CSS3边框
-
border-radius
div { border:2px solid; border-radius:25px; }
-
box-shadow
div { box-shadow: 10px 10px 5px #888888; }
-
border-image
允许你指定一个图片作为边框! 用于创建上文边框的原始图像:
div
{
border-image:url(border.png) 30 30 round;
-webkit-border-image:url(border.png) 30 30 round; /* Safari 5 and older */
-o-border-image:url(border.png) 30 30 round; /* Opera */
}
CSS3圆角
属性 | 描述 |
---|---|
border-radius | 所有四个边角 border---radius 属性的缩写 |
border-top-left-radius | 定义了左上角的弧度 |
border-top-right-radius | 定义了右上角的弧度 |
border-bottom-right-radius | 定义了右下角的弧度 |
border-bottom-left-radius | 定义了左下角的弧度 |
-
指定背景颜色的元素圆角
\#rcorners1 { border-radius: 25px; background: #8AC007; padding: 20px; width: 200px; height: 150px; }
-
指定边框的元素圆角
\#rcorners2 { border-radius: 25px; border: 2px solid #8AC007; padding: 20px; width: 200px; height: 150px; }
-
制定本背景图片圆角
1. \#rcorners3 { border-radius: 25px; background: url(paper.gif); background-position: left top; background-repeat: repeat; padding: 20px; width: 200px; height: 150px; }
CSS3背景
- background-image:添加背景图片
- background-size: 背景图片大小
- background-origin:背景图片定位
- content-box,
- padding-box,
- border-box
- background-clip:背景裁剪
其他
- CSS3渐变
- 动画
- 按钮
- 盒子
- 框
- 网格布局
- 网格容器
- 网格元素
-radius: 25px;
background: url(paper.gif);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
### CSS3背景
- background-image:添加背景图片
- background-size: 背景图片大小
- background-origin:背景图片定位
- content-box,
- padding-box,
- border-box
- background-clip:背景裁剪
### 其他
- CSS3渐变
- 动画
- 按钮
- 盒子
- 框
- 网格布局
- 网格容器
- 网格元素