2017-04-14 41 views

回答

0

你可以做到這一大堆方法。我想創建一個flexrow佈局中設置的父元素wrapposition: relative,然後讓4個孩子佔據了父母,在5日進行絕對定位在4

body { 
 
    margin: 0; 
 
} 
 
.flex { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    height: 100vh; 
 
    position: relative; 
 
} 
 
div > div { 
 
    flex-basis: 50%; 
 
    height: 50vh; 
 
    background: red; 
 
} 
 
div > div:nth-child(2) { 
 
    background: blue; 
 
} 
 
div > div:nth-child(3) { 
 
    background: green; 
 
} 
 
div > div:nth-child(4) { 
 
    background: yellow; 
 
} 
 
div > div:last-child { 
 
    background: pink; 
 
    position: absolute; 
 
    top: 50%; left: 50%; 
 
    transform: translate(-50%,-50%); 
 
    width: 50vh;; 
 
}
<div class="flex"> 
 
    <div></div> 
 
    <div></div> 
 
    <div></div> 
 
    <div></div> 
 
    <div></div> 
 
</div>

0

有不同的方式來弄完,這樣的一個是在這裏:

<div class="parent"> 
    <div class="block a"></div> 
    <div class="block b"></div> 
    <div class="block c"></div> 
    <div class="block d"></div> 
    <div class="upperBlock"></div> 
</div> 

<style> 
    .block{display:inline-block;width:50%;float:left;height:80px} 
    .a{background:red;} 
    .b{background:blue;} 
    .c{background:black;} 
    .d{background:gold;} 
    .parent{position:relative;height:160px;} 
    .upperBlock{height:80px;width:80px;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);background:white;} 
</style> 

https://jsfiddle.net/vy7th0es/

相關問題