1. 程式人生 > >:before,after和其他偽元素新增

:before,after和其他偽元素新增

div:nth-of-type(2)::before{
/*必須新增content屬性,否則後期不可見*/
content: "";
/*預設是行級元素,如果想設定寬高,就必須轉換為塊級元素*/
position: absolute;
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 10px;
left: -10px;
top: -10px;
}
div:nth-of-type(2)::after{
/*必須新增content屬性,否則後期不可見*/
content: "";
/*預設是行級元素,如果想設定寬高,就必須轉換為塊級元素*/
position: absolute;
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 10px;
left: -10px;
bottom: -10px;
}



/*獲取第一個字元:實現首字下沉*/
p::first-letter{
color: red;
font-size: 30px;
float: left;/*文字環繞*/
}

/*獲取第一行內容:如果設定了::first-letter,那麼無法同時設定它的樣式*/
p::first-line{
text-decoration: underline;
}

/*設定當前選中內容的樣式*/
p::selection{
background-color: pink;
color: red;
/*它只能設定顯示的樣式,而不能設定內容大小*/
/*font-size: 30px;*/
}