我正在使用CSSdisplay: inline-block
。
.container div
{
display: inline-block;
width: calc((100% - 13px) / 2);
margin: 2px;
background: #fff;
border-radius: 10px;
color: #5e5e5e;
cursor: pointer;
margin-bottom: 6px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
border-bottom: 2px solid #80D0C7;
position: relative;
}
.container div:last-child
{
width: 100%;
}
Red
green
blue
orange
black
我把width: 100%
在div上的最后一个孩子。但它提供了额外的填充/余量。我的问题是,如何让div最后一个孩子的宽度达到100%而没有任何额外的填充/边距?
发布于 2021-02-25 02:02:19
使用display: flex
在.container
,然后flex-basis: calc(50% - 4px)
(其中4px
是每个元素的页边距之和。div
)在所有div和最后一个集合中flex-basis: 100%
.container {
display: flex;
flex-wrap: wrap;
}
.container div {
background: #fff;
border-radius: 10px;
color: #5e5e5e;
cursor: pointer;
margin: 2px 2px 6px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
border-bottom: 2px solid #80D0C7;
position: relative;
flex: 0 calc(50% - 4px)
}
.container div:last-child {
flex-basis: 100%;
}
Red
green
blue
orange
black
https://stackoverflow.com/questions/66361345
复制相似问题