将几个div对齐在一起

时间:2013-10-31 13:01:30

标签: html css alignment

有没有一种方法可以将4个div组合在一起,所以它们都是整齐的内联,我有一个div中的图像,另一个div中的标题,文本和其他单独div中的另一个图像但是我希望它们看起来一致。见fiddle

<div id="christmas_product_boxes">
    <div id="christmas_mattress">
        <img src="http://blog.applause.com/wp-content/uploads/2013/05/one_star.jpg" height="100px" width="100px">
    </div>
    <div id="christmas_pillows">
        <img src="http://blog.applause.com/wp-content/uploads/2013/05/one_star.jpg" height="100px" width="100px">
    </div>
    <div id="christmas_beds">
        <img src="http://blog.applause.com/wp-content/uploads/2013/05/one_star.jpg" height="100px" width="100px">
    </div>
</div>
<br>
<br>
<div id="christmas_product_boxes_title">
    <div id="christmas_mattress_title">
        <h2>Title 1</h2>
    </div>
    <div id="christmas_pillow_title">
        <h2>Title 2</h2>
    </div>
    <div id="christmas_beds_title">
        <h2>Title 3</h2>
    </div>
</div>
<div id="christmas_product_boxes_text">
    <div id="christmas_mattress_text">
        <p>This is some text in a p tag!! <br>This is some text in a p tag!! <br>This is some text in a p tag!!</p>
    </div>
    <div id="christmas_pillow_text">
        <p>This is some text in a p tag!! <br>This is some text in a p tag!! <br>This is some text in a p tag!!</p>
    </div>
    <div id="christmas_beds_text">
        <p>This is some text in a p tag!! <br>This is some text in a p tag!! <br>This is some text in a p tag!!</p>
    </div>
</div>
<div id="christmas_product_boxes_buttons">
    <div id="christmas_mattress_button">
        <a href="#"><img src="http://www.downloadclipart.net/large/253-button-blue-design.png" height="30px" width="30px"></a>
    </div>
    <div id="christmas_pillow_button">
        <a href="#"><img src="http://www.downloadclipart.net/large/253-button-blue-design.png" height="30px" width="30px"></a>
    </div>
    <div id="christmas_beds_button">
        <a href="#"><img src="http://www.downloadclipart.net/large/253-button-blue-design.png" height="30px" width="30px"></a>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

这样的事情怎么样:

小提琴:http://jsfiddle.net/6Lrdp/1/

根据小提琴将这些样式应用于大多数容器。

width: 130px;
margin:0 10px 0 50px
text-align: center;

你必须弄乱尺寸。 。

答案 1 :(得分:0)

一个好的开始是改变你创建html结构的方式。您正在尝试水平组织内容。您div将您的“感兴趣对象”(在本例中为方框)分成许多部分。我不是说这是错的,但它看起来很奇怪(至少对我而言)。

“水平方式”: http://jsfiddle.net/felipemiosso/yUgLw/3/

现在,这个:http://jsfiddle.net/felipemiosso/yUgLw/2/

它比其他方式更简单,更容易看到?无论如何...这两个小提琴你给你一个北方你需要改变你的代码工作正常。希望它有所帮助:)

关于代码的说明:您不应在代码中重复id属性。Difference between div id and div class