html - inline-block 内容在不同的浏览器中显示不同的结果?

标签 html css google-chrome firefox responsiveness

我有一个响应式表单元素,它应该与标题内联,如下所示: enter image description here

这在 Firefox 中很好,因为这正是我要找的。
但是当我们在 Chrome 中看到相同的代码时(编辑,在 Blisk、Yandex 和可能所有的 webkit 浏览器,以及 MS Edge 和 IE11 中看到相同的结果),这就是我得到的:

enter image description here

代码:

h1,
form {
  display: inline-block;
  vertical-align: middle;
}
h1 {
  font-size: 48px;
}
.field {
  display: table-cell;
}
.field,
input {
  width: 100%;
}
input,
.btn {
  padding: 10px 16px;
  box-sizing: border-box;
}
<h1>Inline title</h1>
<form action="">
  <div class="field">
    <input type="text" placeholder="Email Address" />
  </div>
  <div class="field">
    <button class="btn">Submit</button>
  </div>
</form>

或者,看看 the code here (Codepen.io) .
FF 和 Chrome 处理 CSS 的方式不同吗?考虑到 .field 类有 display: table-cell;,我觉得 Chrome 正在显示正确的布局,但我不确定。有没有办法在不移除 input field 响应特性的情况下实现 Firefox 在 Chrome 中显示的内容?

谢谢。

最佳答案

只需删除属性:table-cell 并确保所有内容都是inline-block:

h1,
form {
  display: inline-block;
  vertical-align: middle;
}
h1 {
  font-size: 48px;
}
.field {
  display: inline-block; /* instead of table-cell > inline-block */
}
input,
.btn {
  padding: 10px 16px;
}

在此处查看演示:CODEPEN

关于html - inline-block 内容在不同的浏览器中显示不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39119218/

相关文章:

html - 如何在 OpenCart 中更改 css 代码的特定部分?

javascript - 用于 chrome 扩展协议(protocol)的 XMLHttpRequest

google-chrome - 通过docker的Selenium python库,Chrome错误无法启动:异常退出

javascript - JQuery 绑定(bind)问题

c# - 如何从目录导入视频?

css - 数字边框效果

html - Box Shadow 在 Chrome 中有效,但在 IE 和 Firefox 中无效

css - 使用#href 使用div ID 交换图库图像时如何防止页面跳转?

jQuery 删除子元素不存在的元素

带动画的 CSS 下拉菜单(无 js)