css - 无法水平对齐 div

标签 css html web

我有两个 div,我想将它们水平对齐。我这样做:

CSS:

.horidiv {
    display: inline-block;
    width: 20em;
    height: 20em;
}

HTML:

<div class="horidiv">
    <textarea></textarea>
    <br>
    <input type="text">
    <br>
    <div id="sendbutton">Send</div>
</div>
<div class="horidiv">
    <iframe width="300" height="225" frameborder="0" style="border:0" src="<gMapsAPI"></iframe>
    <p>Some lines of text</p>
</div>

我需要改变什么?

最佳答案

只是缺少 vertical-align:top;

.horidiv {
    display: inline-block;
    width: 20em;
    height: 20em;
    border:1px solid #999;
    vertical-align:top;
}

jsFiddle example (边框添加到可见性)

关于css - 无法水平对齐 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23396690/

相关文章:

html - 如何将特定内容居中?

html - CSS 选择器不起作用?

html - 网站更新疑惑!!需要帮助

javascript - 向数据表添加页面控件,但当代码运行时,页面中没有显示任何内容

javascript - 在网站中重复背景

rest - 选择 SSL 证书

linux - 为什么 Apache 不允许从 index.html 中访问 Web 根目录之外的文件?

javascript - 遍历样式对象中的每个属性

javascript - 保持滚动条始终在底部

jquery - 让 div 像复选框一样工作