使用CSS将4个水平DIV块居中

时间:2014-05-30 09:44:40

标签: html block center

我有四个div块,我想要水平居中,它们互相堆叠......任何想法我都能做到这一点。

<div class="container">
   <div style="width:78%; margin:0 auto;">
    <div class="block">1. name of the company</div>
    <div class="block">2. name of the company</div>
    <div class="block">3. name of the company</div>
    <div class="block">4. name of the company</div>
</div>

2 个答案:

答案 0 :(得分:0)

据我所知,你希望blocks彼此相邻。

这是你在找什么? Demo

<强> HTML

<div class="container">
    <div class="block-wrapper">
        <div class="block">1. name of the company</div>
        <div class="block">2. name of the company</div>
        <div class="block">3. name of the company</div>
        <div class="block">4. name of the company</div>
    </div>
</div>

<强> CSS

.block-wrapper {
    width: 78%;
    text-align: center;
}
.block {
    display: inline-block;
}

答案 1 :(得分:0)

您可以尝试使用内联块。

http://jsfiddle.net/8Qk5K/

display: inline-block;

这种类型的显示值使每个块占用所需的水平空间(或者它被赋予)。如果您希望它具有响应性,则最适合使用百分比值。

另外,我建议使用http://jsfiddle.net进行演示。每个人都更容易理解!

祝你好运!