CSS 列不会水平对齐
CSS Columns will not horizontally align
我正在使用列数来让我的文本流入两个不同的列,但第一列(最左边)的顶部低于另一列?
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
我包含了有限的代码部分,即使我用文本填充它,列的顶部仍然存在差异。
使用:
#col h3 {
margin-top: 0;
}
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
#col h3 {
margin-top: 0;
}
<div id="col">
<h3>Options</h3>
<h3>Features and Benefits</h3>
<h3>Specifications</h3>
<h3>hey</h3>
<h3>30 Years Experience</h3>
</div>
一点CSS:
CSS:
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
position:relative;
}
h3{display:inline-block;width:100%;}
// Best would be #col > * , because all direct children must be affected.
HTML:
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
片段:
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
position:relative;
}
h3{display:inline-block;width:100%;}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
#col{
margin-top:0px;
}
#col h3{
display:inline-block;
vertical-align:top; // middle or bottom
}
只需删除 h3 元素的上边距
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
h3 {
margin-top: 0;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
事实上 h3
元素默认有一个 margin-top
,导致了这个问题。删除边距可以修复它,如下面的代码片段所示。
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
h3 {
margin-top: 0;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
我正在使用列数来让我的文本流入两个不同的列,但第一列(最左边)的顶部低于另一列?
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
我包含了有限的代码部分,即使我用文本填充它,列的顶部仍然存在差异。
使用:
#col h3 {
margin-top: 0;
}
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
#col h3 {
margin-top: 0;
}
<div id="col">
<h3>Options</h3>
<h3>Features and Benefits</h3>
<h3>Specifications</h3>
<h3>hey</h3>
<h3>30 Years Experience</h3>
</div>
一点CSS:
CSS:
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
position:relative;
}
h3{display:inline-block;width:100%;}
// Best would be #col > * , because all direct children must be affected.
HTML:
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
片段:
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
position:relative;
}
h3{display:inline-block;width:100%;}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
#col{
margin-top:0px;
}
#col h3{
display:inline-block;
vertical-align:top; // middle or bottom
}
只需删除 h3 元素的上边距
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
h3 {
margin-top: 0;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>
事实上 h3
元素默认有一个 margin-top
,导致了这个问题。删除边距可以修复它,如下面的代码片段所示。
#col {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
h3 {
margin-top: 0;
}
<div id="col">
<h3>
Options
</h3>
<h3>
Features and Benefits
</h3>
<h3>
Specifications
</h3>
<h3>
hey
</h3>
<h3>
30 Years Experience
</h3>
</div>