html - 为什么 Chrome 在这种情况下不尊重负边距?

标签 html css google-chrome margin

我在使用非常简单的代码时遇到问题。

Chrome 似乎忽略了我正在使用的负 margin-bottom。在 IE11 中按预期工作。

IE 11

How it render in IE11

Chrome 38

How it render in Chrome 38

我只是想对齐它们。我知道我可以使用更多代码来实现,但我想知道我是否期望 margin-bottom 的工作方式与应有的工作方式不同:

<div id="main">
    <select>
        <option value="2014">2014</option>
    </select>
    <button></button>
    <select id="AmbientesSelect">
        <option value="TEST">TESTE</option>
    </select>
    <button></button>
</div>

这是CSS:

#main {
    background-color:red;
}
#main button {
    width: 28px;
    height: 23px;
    border: solid 1px #ccc;
    margin-bottom: -7px;
}

现场再现:http://jsfiddle.net/v4bd7xjy/2/

我搜索了一些问题,但它们太具体或太不同。其中一些:

Why Chrome doesn't respect the margin properly?

Negative margin-bottom rendering not correctly in Chrome

How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?

编辑

如果有的话,我填写了 bug Chromium 元素报告。

最佳答案

尝试添加到您的按钮 vertical-align: top;

关于html - 为什么 Chrome 在这种情况下不尊重负边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25208514/

相关文章:

javascript - 通过查询大量数据减少html 表的加载时间| PHP、HTML、SQLSERVER 2012

google-chrome - 谷歌浏览器和网站图标

html - 具有最大宽度的内联 block 不会有省略号

jquery - 将鼠标悬停在包含 div 上并不总是有效

html - 如何在不影响子元素的情况下更改页面构建器 div 中 bg img 的亮度并更改悬停时的亮度

html - 弄清楚为什么 django 现在找不到我的模板的脚本、样式表和插件

html - 来自外部的 Shadow DOM CSS 样式在 Google Chrome 中不起作用

java - localhost 在 Edge 中有效,但在 Chrome 中无效

html - 水平对齐父元素内的图像

html - 设置具有多个名称的类的属性