標籤:背景 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>
css :after和:before