【发布时间】:2016-04-06 16:04:18
【问题描述】:
我最近一直在玩display:flex,因为我发现它变得越来越流行。在快速测试中,使用 flex 和非 flex CSS 方法,我意识到,在使用 flex 时,我的宽度和边距总是受到尊重。考虑到无论如何我很可能需要元素之间的排水沟,这是一个好方法吗?此外,跨度之间的边距从何而来?这就是我的意思:
HTML
<div class="container">
<div class="box">
<span class="inner-box">This gives me a 30px X 60px</span>
<span class="inner-box">This gives me a 30px X 60px</span>
<span class="inner-box">This gives me a 30px X 60px</span>
</div>
<div class="box2">
<span class="inner-box">This gives me a width larger than the specified 30px</span>
<span class="inner-box">This gives me a width larger than the specified 30px</span>
<span class="inner-box">This gives me a width larger than the specified 30px</span>
</div>
</div>
CSS
.box{
background: orange;
display:flex;
flex-direction:row-reverse;
padding:0 10px;
}
.box2{
background: green;
text-align:right;
padding:0 10px;
}
.inner-box{
width:30px;
background:#fff;
margin:0 0px;
}
【问题讨论】:
-
到底是什么问题?如果
display:flex尊敬width,那么display:inline哪里不行?如果是这样,答案是肯定的,但不是很清楚。 -
@MrLister,你是对的,我错过了添加我对此的主要问题。当我不得不发布这个时,我很着急。我编辑了
-
在你的笔中你有
.box2 span { display: inline-block },它们之间的空间在How to remove the space between inline-block elements?中解释。在你的问题中你没有那个,所以他们有默认的display: inline,所以他们忽略了width,如Setting the width of inline elements中所述。您的问题是其中之一的欺骗。 -
没有欺骗。但如果你愿意,你可以欺骗它。没关系