calc
兼容性:不支持 IE8
unset
column
有關CSS的高級佈局技巧
隨著 IE8 逐漸退出舞台,許多高階的 CSS 特性都已被瀏覽器原生支持,再不學下就要過時了。
用 :empty
登入後複製登入後複製 區分空元素
:empty
兼容性:不支持 IE8
Demo
假如我們有以上列表:
a
b
我們希望可以對空元素和非空元素區別處理,那麼有兩種方案。
用
:empty
選擇空白元素:
.item:empty {
display: none;
}
或用
:not(:empty)
選擇非空元素:
.item:not(:empty) {
border: 1px solid #ccc;
/* ... */
}
用 :*-Of-Type
登入後複製 選擇元素
:*-Of-Type
兼容性:不支持 IE8
舉例說明。
給第一個p 段落加粗:
p:first-of-type {
font-weight: bold;
}
給最後一個img 加邊框:
img:last-of-type {
border: 10px solid #ccc;
}
#為無相連的blockquote 加上樣式:
blockquote:only-of-type {
border-left: 5px solid #ccc;
#padding-left: 2em;
}
讓奇數列的p 段落先死紅:
p:nth-of-type(even) {
color: red;
}
此外,
:nth-of-type
還可以有其他類型的參數:
/* 偶數個*/
:nth-of-type(even)
/* only 第三個*/
:nth-of-type(3)
/* 每第三個*/
:nth-of-type(3n)
/* 每第四加三個,即3, 7, 11, ... */
:nth-of-type(4n+3)
用 calc
登入後複製 做串流佈局
calc
兼容性:不支持 IE8
Demo
左中右的串流佈局:
##nav {
position: fixed; left: 0;
top: 0;
width: 5rem;
height: 100%;}
aside {
position: fixed;
right: 0; top: 0;
width: 20rem;
height: 100%;
}
main {
margin-left: 5rem; width: calc(100% - 25rem);
}
vw
vh
#兼容性:不支持 IE8
登入後複製登入後複製登入後複製登入後複製
兼容性:不支持 IE8
Demo
vw
vh
viewport 而言的,所以不會隨內容和佈局的變化而變。
section {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
1 ##y-content: center;
text-align: center;
background-size
: cover;
background-repeat : no-repeat;
background-attachment: fixed;
}section:nth-of-type(1) {
background-image
: url('
https://unsplash.it/1024/683?image=1068');}section:nth-of-type(2 ) { background-image: url('https://unsplash.it/1024/683?image=1073');
}
section:nth-of-type(3) {
background-image: url('https://unsplash.it/1024/683?image=1047');
}
section:nth-of-type(4) {
background-image : url('https://unsplash.it/1024/683?image=1032');
}
body {
margin: 0;
}
p {
color: #fff;
font-size
: 100px;
font-family: monospace;
}#
用 unset
登入後複製 做 CSS Reset
unset
兼容性:不支持 IE
Demo
body {
color: red;
}
button {
color: white;
border: 1px solid #ccc;
}
/* 取消 section 中 button 的 color 设置 */
section button {
color: unset;
}
用 column
登入後複製 做响应式的列布局
column
兼容性:不支持 IE9
Demo
nav {
column-count: 4;
column-width: 150px;
column-gap: 3rem;
column-rule: 1px dashed #ccc;
column-fill: auto;
}
h2 {
column-span: all;
}
(完)
以上是有關CSS的高級佈局技巧的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

關於Flex佈局中紫色斜線區域的疑問在使用Flex佈局時,你可能會遇到一些令人困惑的現象,比如在開發者工具(d...

在元素個數不固定的情況下如何通過CSS選擇第一個指定類名的子元素在處理HTML結構時,常常會遇到元素個數不�...
