试图在div中对齐图像

时间:2012-10-10 12:15:03

标签: html css image alignment

好的,现在我的箱子全部排序了,我想尝试对齐图片和图片旁边的一些文字。我希望文本位于顶部,电子邮件徽标位于底部,如下图所示

element alignment

#nav1 {
    width: 1000px;
    height: 100px;
    background-color: #F90;
}

#pic {
    width: 200px;
    height: 67px;
    margin-top: 15px;
    float: right;
    margin-right: 15px;
}

<div id="container">
    <div id="nav1">
        <div id="pic">
            <img src="email.png" />
            <img src="photo.jpg" align="right" />
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

我创建了一个带有虚拟图像的JSFiddle,它以图像显示的方式显示信息。或者接近你想要/需要的东西。

HTML

<div class="user">
    <img class="avatar" src="http://lorempixel.com/64/64/people"/>    
    <div class="name">Mahatma Gandhi</div>
    <div class="people">6</div>
    <div class="emails">1</div>
</div>​

CSS

.user
{
    background-color: #ebebee;
    display: inline-block;
    padding: 5px;
    text-align: right;
}
.avatar {
    float: right;
    margin-left: 6px;
}
.name
{
    height: 48px;
    font-size: 1.25em;
    text-align: right;
    white-space: nowrap;
    margin-right: 70px;
}
.people, .emails
{
    height: 16px;
    display: inline-block;
    margin-right: 10px;
    padding-left: 20px;
    background-position: left top;
    background-repeat: no-repeat;
}
.people { background-image: url(http://lorempixel.com/16/16/1); }
.emails { background-image: url(http://lorempixel.com/16/16/2); }
​
​