垂直顶部对齐div html中的子子节点

时间:2014-05-27 11:22:28

标签: html css

我正在使用以下代码

    <div style="margin-top: 10px; margin-left: 10px; width: 800px; height:110px; display:inline-block;" >

          <img src="images/about_us_logo.png" alt="" width="104" height="110" />
          <label class="aboutText" ><?php echo $store['description'] ?></label>
    </div>
    <br />
    <div style="margin-top: 10px; margin-left: 10px; display:inline-block;" >

          <img src="images/webaddress_about.png" alt="" width="70" height="67" />
          <label class="aboutText" ><?php echo $store['website'] ?></label>

    </div>

    <br />
    <div style="margin-top: 10px; margin-left: 10px; display:inline-block;" >

          <img src="images/email_about.png" alt="" width="70" height="49" />
          <label class="aboutText" ><?php echo $store['email'] ?></label>

    </div>
    <br />
    <div style="margin-top: 10px; margin-left: 10px; display:inline-block;" >

          <img src="images/phone_about.png" alt="" width="50" height="55" />
          <label class="aboutText" ><?php echo $store['phone'] ?></label>

    </div>



.aboutText
{
    margin: 10px 10x  10px 20px;
    padding: 5px 5px 5px 5px;
    color: #C7C7C7;
    width: 500px;
    height:110px;
    text-align:center;
    font-weight: bold;
}

结果如下

enter image description here

问题是图像和文本没有对齐。我需要将文本放在顶部与图像对齐 2-徽标及其描述与下图重叠,我该怎么做才能解决它

2 个答案:

答案 0 :(得分:2)

您只需添加此css规则以将子子项与顶部对齐:

img,label{
    vertical-align:top; /* vertically align */
}

但我认为middle最适合这个

img,label{
    vertical-align:middle; /* vertically align */
}

Demo with top

Demo with middle

如果描述文本太长,这个场景总是很有用,请这样做,将一些css规则添加到你的标签CSS以及上述规则:

.aboutText
{
    margin: 10px 10x  10px 20px;
    padding: 5px 5px 5px 5px;
    color: #C7C7C7;
 /* width: 110px;*/ /*Get rid of height here
    height:500px;
    text-align:center;
    font-weight: bold;

    word-wrap:break-word;/* added new rule*/
    display:inline-block;/* added new rule*/
    text-align:left;   /* added new rule*/
}

Final Demo

希望你需要这个。

答案 1 :(得分:0)

为图像添加左对齐属性

img
{
 text-align:left;
}