html - 如何使用 display inline-block 将元素右对齐?

标签 html css

我的页脚有两个 div 标签。我想要一个在页面的左边,一个在右边。我正在使用 display:inline-block 使两个 div 位于同一行,但我无法使它们 float 。

<div id="footer">
    <div id="phone">
        <img id="pIcon" src="img/phone_icon.png" alt="Phone icon" />  
        <p id="pValue"> # </p>
    </div>
    <div id="email">
       <img id="eIcon" src="img/email_icon.png" alt="Email icon" />
       <p id="eValue"> # </p>
    </div>
</div> <!-- end of footer -->


#footer {
    width:100%;
    bottom:0;
    background-color:rgba(102,51,255,1);
}

#email {

    background-color:rgba(255,255,0,1);}

#phone, #email {
    display:inline-block;
    width:45%;
}

#pIcon, #pValue {
    display:inline-block;
}

#eValue, #eIcon {
    display:inline-block;
}

最佳答案

您需要 text-align 属性。对于你想要的左边是 left,右边是 right

#phone, #email {
    display:inline-block;
    width:45%;
    text-align: left;
    vertical-align: middle; //If you need vertical middle alignment
}
#email {
    text-align: right;
}

Demo

关于html - 如何使用 display inline-block 将元素右对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760053/

相关文章:

PHP - 在 HTML 文件中多次启动/结束 PHP

html - 使用浏览器缩放在 HTML5 Canvas 上绘制清晰的线条

html - 将 img 放在左边,将 h1 放在右边

HTML+CSS 阴影、垂直菜单、文本位置

javascript - 如何在另一个DIV中预览DIV?

html - 为什么我的幻灯片背景图像不显示?

html - 第三行文本居中

html - 如何设置 div 样式以使其与文本一起运行?

html - 用于打印的跨浏览器 CSS

css - 在同一行显示表单域