标签:背景 size 20px sans weight pre value name val
:before是css中的一种伪元素,可用于在某个元素之前插入某些内容。
:after是css中的一种伪元素,可用于在某个元素之后插入某些内容。
举例:
1.结合border写个对话框的样式。
<style>
.test-div{
position: relative; /*日常相对定位*/
width:150px;
height: 36px;
border:black 1px solid;
border-radius:5px;
background: rgba(245,245,245,1)
}
.test-div:before,.test-div:after{
content: ""; /*:before和:after必带技能,重要性为满5颗星*/
display: block;
position: absolute; /*日常绝对定位*/
top:8px;
width: 0;
height: 0;
border:6px transparent solid;
}
.test-div:before{
left:-11px;
border-right-color: rgba(245,245,245,1);
z-index:1
}
.test-div:after{
left:-12px;
border-right-color: rgba(0,0,0,1);
z-index: 0
}
</style>
<div class="test-div"></div>
2.作为内容的半透明背景层。
<style> body{ background: url(ABUIABACGAAg6KijvAUo1PqcwwIwgA84uwU.jpg) no-repeat left top /*这里加了个图片背景,用以区分背景的半透明及内容的完全不透明*/ } .test-div{ position: relative; /*日常相对定位(重要,下面内容也会介绍)*/ width:300px; height: 120px; padding: 20px 10px; font-weight: bold; } .test-div:before{ position: absolute; /*日常绝对定位(重要,下面内容也会略带介绍)*/ content: ""; /*:before和:after必带技能,重要性为满5颗星*/ top:0; left: 0; width: 100%; /*和内容一样的宽度*/ height: 100%; /*和内容一样的高度*/ background: rgba(255,255,255,.5); /*给定背景白色,透明度50%*/ z-index:-1; /*日常元素堆叠顺序(重要,下面内容也会略带介绍)*/ } </style> <!--这里容兽偷个懒,布局简单写写--> <body> <div class="test-div"> <table> <tr> <td>Name</td> <td><input placeholder="your name" /></td> </tr> <tr> <td>Password</td> <td><input placeholder="your password" /></td> </tr> <tr> <td></td> <td><input type="button" value="login" /></td> </tr> </table> </div>
标签:背景 size 20px sans weight pre value name val
原文地址:http://www.cnblogs.com/pyyblogs/p/6017175.html