display: flex; //Parent element
flex-wrap: wrap; //Direct child elements
每個網格都有填寫的容器寬度的25%,並自動走下來..
,但目前他們並不像柔性包裝:包裝;當有5個網格時,它們的行爲就像是20%的寬度......它有點奇怪,因爲它們設置爲25%?
如果我把Flex-wrap: wrap;
放在父元素上,我現在有display:flex;
它可以工作,但它們不是等高嗎?
在這種情況下我該怎麼辦?我想不出如何執行此操作,
找到實例:http://www.chri126g.wigf1.sde.dk/DUER1/
HTML
<div class="global-wrapper">
<div class="dueWrapper flex">
<div class="dueOuter col25 flex-w-w">
<div class="dueInner flex-d-r">
<img src="img/salg/1.jpg" alt="due">
<table>
<tr>
<td>Navn</td>
<td>Smith</td>
</tr>
<tr>
<td>Far</td>
<td>Jackson</td>
</tr>
<tr>
<td>Mor</td>
<td>Emelie</td>
</tr>
<tr>
<td>Pris</td>
<td>500kr</td>
</tr>
</table>
</div>
</div>
<div class="dueOuter col25 flex-w-w">
<div class="dueInner flex-d-r">
<img src="img/salg/2.jpg" alt="due">
</div>
</div>
<div class="dueOuter col25 flex-w-w">
<div class="dueInner flex-d-r">
<img src="img/salg/3.jpg" alt="due">
</div>
</div>
<div class="dueOuter col25 flex-w-w">
<div class="dueInner flex-d-r">
<img src="img/salg/3.jpg" alt="due">
</div>
</div>
<div class="dueOuter col25 flex-w-w">
<div class="dueInner flex-d-r">
<img src="img/salg/3.jpg" alt="due">
</div>
</div>
</div><!--/DUE-WRAPPER-->
</div><!--/GLOBAL-WRAPPER-->
CSS
.flex {
display: flex;
}
.flex1{
flex: 1;
}
.flex-d-r{
display: flex;
flex-direction: column;
}
.flex-w-w{
display: flex;
flex-wrap: wrap;
}
body{
background-color: lightgrey;
}
.global-wrapper{
padding: 5px;
width: 90%;
min-height: 100vh;
max-width: 1000px;
margin: 0 auto;
background-color: #fff;
}
.dueOuter{
padding: 5px;
}
.dueInner{
outline: 1px solid #000;
min-height: 100px;
transition: 0.3s ease;
-webkit-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
-webkit-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
}
.dueInner:hover{
b: 3px solid #000;
}
.dueInner img{
width: 100%;
}
td{
width: 100%;
}
tr:nth-of-type(odd){
background-color: lightgrey;
}
'flex-wrap'放在容器上,而不是物品。此外,發佈您的代碼,以便我們可以重現您遇到的問題。 –
在這裏檢查https://css-tricks.com/snippets/css/a-guide-to-flexbox/如何使用flex。您正在對錯誤的元素使用flex-wrap。由於flex包裝上的「align-items:stretch」,高度應該與默認值相同。除非你改變了。請將你的代碼放在 – Huangism
那麼我的指南是在父元素上跟着說的Flex,而flex-wrap:包含子元素,如 –