540 CSS3属性对层叠上下文的影响
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3属性对层叠上下文的影响1</title> <style type="text/css"> /* 层叠上下文元素: html、child + parent parent 其实就是一个普通的块元素 块元素 > 定位 z-index:-1 */ /* 案例一分解 */ .box { display: flex; text-align: center; } /* 【没有定位,普通的块元素】 */ .parent { width: 200px; height: 100px; background: #168bf5; z-index: 1; } .child { width: 100px; height: 200px; margin-top: -20px; background: #32d19c; position: relative; z-index: -1; margin-left: 20px; color: #fff; } </style> </head> <body> <!-- 案例一分解:display:flex/inline-flex; --> <div class="box"> <div class="parent"> 父元素 <div class="child">子元素</div> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3属性对层叠上下文的影响2</title> <style type="text/css"> /* 案例二分解*/ .parent1 { width: 200px; height: 100px; background: #168bf5; opacity: .5; } .child1 { width: 100px; height: 200px; background: #32d19c; position: relative; z-index: -1; } </style> </head> <body> <!-- 案例二分解:opacity --> <div class="parent1"> parent <div class="child1">child</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3属性对层叠上下文的影响3</title> <style type="text/css"> /* 案例三分解*/ .parent3 { width: 200px; height: 100px; background: #168bf5; /* transform的值不为none就可以 */ transform: rotate(5deg); } .child3 { width: 100px; height: 200px; background: #32d19c; position: relative; z-index: -1; } </style> </head> <body> <!-- 案例三分解:transform --> <div class="parent3"> parent <div class="child3">child</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3属性对层叠上下文的影响4</title> <style type="text/css"> /* 案例四分解*/ .parent4 { width: 200px; height: 100px; background: #168bf5; filter: blur(5px); } .child4 { width: 100px; height: 200px; background: #32d19c; position: relative; z-index: -1; } </style> </head> <body> <!-- 案例四分解:filter --> <div class="parent4"> parent <div class="child4">child</div> </div> </body> </html>
相关推荐
wpfeitian 2020-09-28
wangrui0 2020-07-05
qiximiao 2020-07-05
CSSEIKOCS 2020-06-25
邓博学习笔记 2020-06-15
fenxinzi 2020-06-15
bluecarrot 2020-06-15
onlykg 2020-06-14
cwgxiaoguizi 2020-06-14
atb 2020-06-14
Attend 2020-06-14
咏月东南 2020-06-14
citic 2020-06-14
NeverAgain 2020-06-14
heheeheh 2020-06-14
hickwu 2020-06-14
pointfish 2020-06-14
YoungkingWang 2020-06-13
昭君出塞 2020-06-13