文/小魔女css
HTML元素分爲行內、塊狀、行內塊元素三種。html
塊元素和行內塊元素能夠設置寬高前端
行內元素不能夠,高度由內容撐開web
三者是能夠經過display屬性任意轉換的面試
使用demochrome
div {
-ms-transform: rotate(0);
-webkit-transform: rotate(0);
-moz-transform: rotate(0);
-o-transform: rotate(0);
transform: rotate(0);
}
複製代碼
「CSS前綴自動補全:autoprefixer」瀏覽器
❝已知: margin:20px; border:10px; padding:10px; width:200px; height:50px;❞markdown
標準盒模型:
1\. 佔用寬:
margin*2+padding*2+border*2+width
= 20*2+10*2+10*2+200 = 280
2\. 佔用高:
margin*2+padding*2+border*2+height
= 20*2+10*2+10*2+50 = 130
3\. 盒子實際寬度:
padding*2+border*2+width
= 10*2+10*2+200 = 240
4\. 盒子實際高度
padding*2+border*2+height
= 10*2+10*2+50 = 90
複製代碼
怪異盒模型:
1\. 佔用寬:
margin*2+width
= 20*2+200 = 240
2\. 佔用高:
margin*2+height
= 20*2+50 = 90
3\. 盒子實際寬度:
width = 200
4\. 盒子實際高度
height = 50
複製代碼
「IE8及更早版本不兼容問題解決方案:在HTML頁面聲明 」網絡
❝BFC(塊狀格式化上下文,獨立的盒子,佈局不受外部影響,可是若是同一個BFC中,同級塊狀元素的margin-top和margin-bottom會重疊)❞ide
只要元素知足下面的任一條件,都會觸發BFC特徵。
解決問題:
❝元素被當成行內元素排版時,元素直接的空白符會被瀏覽器處理,根據white-spack的處理方式(默認是normal,合併多餘空白),Html代碼在回車換行時被轉成一個空白符,在字體不爲0的狀況下,空白符佔據必定寬度,因此inline-block元素之間就出現了空隙。❞
復現
<ul>
<li>首頁</li>
<li>登錄</li>
<li>資源</li>
<li>社區</li>
<li>幫助</li>
</ul>
複製代碼
解決辦法:
.clearfix:after { display: block; height: 0; visibility: hidden; clear: both; content: ''; }
.clearfix{ //IE6模式下 zoom:1; }
.clearfix:before, .clearfix:after { display: table; content: ''; } .clearfix:after { clear: both; } .clearfix { zoom: 1; //兼容IE6下 }
不一樣級優先級:
同一級別:
「優先級相同時會發生什麼? 樣式被覆蓋」
「normalize.css是一個css reset的替代方案。」
ul>li:nth-child(2n+1) {
background-color: red;
}
ul>li:nth-child(2n) {
background-color: yellow;
}
複製代碼
ul>li:first-child {
border-top: none;
}
複製代碼
本文使用 mdnice 排版