[英]Aligning DIVs horizontally and vertically
I'm looking for a way to set up a basic 2 column blog-type layout which allows for divs to be inline horizontally but also to be directly under the div above. 我正在寻找一种方法来设置一个基本的2列博客类型布局,它允许div水平内联,但也可以直接位于上面的div下面。 I've tried with display:inline and also floating the divs, still cant get it to work quite right.
我试过显示:内联和浮动div,仍然无法让它工作得很好。 Am not sure if this can be done with CSS alone, but here's hoping
我不确定这是否可以单独使用CSS,但是希望如此
Please check the links below to see what i mean, as I'm pretty sure I haven't explained it the best way possible. 请检查下面的链接,看看我的意思,因为我很确定我没有尽可能地解释它。
What I'm looking to do: 我想做什么:
What I keep getting: 我一直得到的:
<div style="display:inline-block; width:400px;">
<div style="padding:5px; margin:10px; background:#222;">
<div class="small">date | name</div>
<div class="data">blah blah blah</div>
</div></div>
With the above code the divs sit nicely next to each other but im pulling data from a database so each div will have a different height 使用上面的代码,div很好地相互靠近,但我从数据库中提取数据,因此每个div将具有不同的高度
This thing works : 这件事有效:
http://jsfiddle.net/8mxZe/ http://jsfiddle.net/8mxZe/
HTML : HTML:
<div class="container">
<div class="left-aside">
<div class="block one">ONE</div>
<div class="block two">TWO</div>
<div class="block three">THREE</div>
</div>
<div class="right-aside">
<div class="block one">ONE</div>
<div class="block two">TWO</div>
<div class="block three">THREE</div>
</div>
</div>
CSS : CSS:
.block {
margin: 5px;
background-color: #22CCFF;
}
.left-aside,
.right-aside {
width: 50%;
}
.left-aside {
float: left;
}
.right-aside {
float: right;
}
.left-aside .one {
height: 200px;
}
.right-aside .one {
height: 250px;
}
.left-aside .two {
height: 300px;
}
.right-aside .two {
height: 200px;
}
.left-aside .three {
height: 300px;
}
.right-aside .three {
height: 150px;
}
Use margin: auto;
使用
margin: auto;
in your css code. 在你的css代码中。
<div style="text-align:center">
<div style="margin:auto">Layer, der auch in Firefox und Opera zentriert wird</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.