慣例,我是標(biāo)題:
??在CSS中讨越,我們經(jīng)常需要布局來實現(xiàn)頁面美化两残,那么怎么布局呢,來點小技巧谎痢。
1磕昼、左中右布局(左右布局和左中右差不多卷雕,代碼更簡單一些节猿,少去了中間的一步):
??我們可以簡單的在html里設(shè)置一個整體<div>,里面放置幾個<div>子元素漫雕,并設(shè)置它們的class分別為左中右left\center\right滨嘱,例如:
<body>
?<div class="main">
??<div class="left">左邊</div>
??<div class="middle"> 中間部分</div>
??<div class="right">右邊</div>
?</div>
</body>
同時在css中寫下如下的代碼:
.main{
position:relative;
max-width:360px;
}
.left {
width:120px;
background-color:green;
position:absolute;
height:50px;
top:0;
left:0;
}
.middle {
width:120px;
background-color:yellow;
height:50px;
top:0;
left:120px;
position:absolute;
}
.right {
width:120px;
background-color:green;
position:absolute;
top:0;
right:0;
height:50px;
}
2、垂直居中&水平居中
??若元素是塊級元素或內(nèi)聯(lián)元素浸间,則把它變?yōu)閐isplay:inline-block內(nèi)聯(lián)塊級元素太雨,這樣可以設(shè)置元素的上下左右padding使其能在行內(nèi)垂直居中,然后可以在元素外面套一層標(biāo)簽如<p>標(biāo)簽魁蒜,在<p>標(biāo)簽中設(shè)置text-align:center命令囊扳,便可以水平居中。
3兜看、其他小技巧
??需要背景圖片可以搜索wallhaven
??想要設(shè)計各種圖形可以搜索css-tricks
??設(shè)置各種軟件或社交圖標(biāo)可以搜索iconfont
??有陰影效果可以搜索css shadow generator