我正在寻找一种显示3列内容的方法。我已经找到了一种显示环绕式列的方法,但是我不想在这个页面上使用它。我正在寻找一种说法
<column>
<!-- content -->
</column>
我希望一个页面可以同时显示三列,每列循环展示三次。我能想到的最好的例子是The Verge (http://www.theverge.com/)。请问如何最佳实现?
我正在寻找一种显示3列内容的方法。我已经找到了一种显示环绕式列的方法,但是我不想在这个页面上使用它。我正在寻找一种说法
<column>
<!-- content -->
</column>
我希望一个页面可以同时显示三列,每列循环展示三次。我能想到的最好的例子是The Verge (http://www.theverge.com/)。请问如何最佳实现?
我建议您使用<table>
或CSS。
CSS更加灵活,因此更受推荐。以下是一个示例:
<!-- of course, you should move the inline CSS style to your stylesheet -->
<!-- main container, width = 70% of page, centered -->
<div id="contentBox" style="margin:0px auto; width:70%">
<!-- columns divs, float left, no margin so there is no space between column, width=1/3 -->
<div id="column1" style="float:left; margin:0; width:33%;">
CONTENT
</div>
<div id="column2" style="float:left; margin:0;width:33%;">
CONTENT
</div>
<div id="column3" style="float:left; margin:0;width:33%">
CONTENT
</div>
</div>
jsFiddle: http://jsfiddle.net/ndhqM/
使用float:left可以使得三列贴在一起,从左边进入位于中心的"content box" div。
width
放在样式属性内:style="margin:0 auto; width: 70%;"
。此外,我不知道有哪些浏览器会在默认样式表中对 div
应用 margin,因此在浮动的 div 上使用 margin: 0;
似乎是多余的。 - steveax尽管CSS3包括供应商前缀的使用,但您可能应该考虑使用它。
我已经快速制作了一个演示fiddle,但关键是这个。
<style>
.3col
{
-webkit-column-count: 3;
-webkit-column-gap: 10px;
-moz-column-count: 3;
-moz-column-gap: 10px;
column-count:3;
column-gap:10px;
}
</style>
<div class="3col">
<p>col1</p>
<p>col2</p>
<p>col3</p>
</div>
除了三个浮动列结构(我也建议使用),您还需要插入一种清除浮动的方法,以防止在列容器之后出现布局问题(可以说是保持列容器在流中...)。
<div id="contentBox" class="clearfix">
....
</div>
CSS:
.clearfix { zoom: 1; }
.clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
.clearfix:after { clear: both; }
ul
菜单)布局问题的常见方法。 - Frank van Wijk.col{
float: left;
}
.col + .col{
float: left;
margin-left: 20px;
}
/* or */
.col:not(:nth-child(1)){
float:left;
margin-left: 20px;
}
<div class="row">
<div class="col">column</div>
<div class="col">column</div>
<div class="col">column</div>
</div>
Bootstrap。请在这里查看其精美的网格系统。
使用Bootstrap,您可以做出如下所示的三列布局:
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Multiple Colums</title>
<!-- Styles -->
<style>
.flex-center {
width: 100%;
align-items: center;/*These two properties center vetically*/
height: 100vh;/*These two properties center vetically*/
display: flex;/*This is the attribute that separates into columns*/
justify-content: center;
text-align: center;
position: relative;
}
.spaceOut {
margin-left: 25px;
margin-right: 25px;
}
</style>
</head>
<body>
<section class="flex-center">
<h4>Tableless Columns Example</h4><br />
<div class="spaceOut">
Column 1<br />
</div>
<div class="spaceOut">
Column 2<br />
</div>
<div class="spaceOut">
Column 3<br />
</div>
<div class="spaceOut">
Column 4<br />
</div>
<div class="spaceOut">
Column 5<br />
</div>
</section>
</body>
</html>
align-items: center;
可以防止列标题被向下推。 - Vass网格:
.container {
display: grid | inline-grid;
}
Flex:
.container {
display: flex | inline-flex;
}