如何使用CSS将三个项目连续设置为33.3%的三个项目?弯曲或网格(没关系)
这是所有代码示例 - >
https://codepen.io/mihailovic-aio/mihailovic-aleksandar/pen/pen/pen/pen/pen/pen/eyvrewe
需要?首先,我有边距,负边缘的问题。 我需要全宽度为33.3%,
以解决负边距。
我希望每个项目恰好是33.3%,并且要全长。目前对我来说是32%,如果我将其设置为33.3%,那是一条新线路的捷径。
.container {
display: flex;
flex-wrap: wrap;
height: 165px;
width: 100%;
}
.item {
background: red;
display: flex;
align-items: center;
justify-content: center;
width: 32%;
height: 75px;
background: #f4f4f4;
margin: 3px;
border-radius: 10px;
}
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item"> 7</div>
</div>
Here is all code example ->
https://codepen.io/mihailovic-aleksandar/pen/eYVREwE
What do I need? First I have a problem with margin, negative margin.
I need the to item be full width 33.3%
To solve the negative margins.
I want each item to be exactly 33.3% and to be full length. It's 32% for me at the moment, and if I set it to 33.3%, it's a shortcut to a new line.
.container {
display: flex;
flex-wrap: wrap;
height: 165px;
width: 100%;
}
.item {
background: red;
display: flex;
align-items: center;
justify-content: center;
width: 32%;
height: 75px;
background: #f4f4f4;
margin: 3px;
border-radius: 10px;
}
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item"> 7</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使是
的3px
保证金
的3px ,当使用width:33%
时,您的flex项目包裹也将使您的flex项目包裹到新行。您可以使用宽度:calc(100%/3)
使其完全33.33%
,但您必须删除静态的左右Margin
。如果要有间距,则可以使用
宽度:calc(100%/3.1)
onintem
withrangin:auto
,因此它们以中心为中心。.1
帐户有一些间距。另一个选项是使用宽度:calc(100%/3-6px);
来考虑保证金:3px;
。Even a measly
3px
ofmargin
will make your flex items wrap to a new line when usingwidth: 33%
. You can usewidth: calc(100%/3)
to make them exactly33.33%
but you will have to remove the static left and rightmargin
.If you want to have spacing you can use
width: calc(100%/3.1)
onitem
withmargin: auto
so they're centered. The.1
accounts for some spacing. Another option would be to usewidth: calc(100%/3 - 6px);
to account formargin: 3px;
.如果要包含边距(尽管您应该在边距上包括一个差距),则需要使用
calc(33.33%-6px)
作为宽度if you want to include the margin (though you should include a gap over a margin), you need to use
calc(33.33% - 6px)
as width您可以将容器用于项目,并给它们
宽度:33.33%
并将保证金设置为您的项目。这是基于您的笔的示例:
You can use a container for your items and give them
width:33.33%
and set margin to your items.Here is an example based on your pen :