html - 如何使用 HTML5 和 CSS3 垂直居中和对齐之后的所有内容?

标签 html css

我试图将浏览器中心的第一个 div 及其下方的所有内容垂直对齐到 div 下方。

我可以将这两个 div 包装在另一个 divcentering 中,div 可能会起作用,但我无法更改此 html 结构并且必须实现只有两个 div。第一个 div 是一个动态容器,其中将显示不同的 html。第二个 div 是静态的。

.center {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
<div class="center">
  I'm at the center of the Browser!
</div>
<div>I'm just below the center!</div>

最佳答案

将 width 和 margin: auto 0 添加到 css 类并将其应用于 div 元素。

像这样:

.center {
  margin: 0 auto;
    width: 200px;
}


<div class="center">
  I'm at the center of the Browser!
</div>
<div class="center">I'm just below the center!</div>

关于html - 如何使用 HTML5 和 CSS3 垂直居中和对齐之后的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33651086/

相关文章:

JQuery 输入动态检查

html - 导航菜单中间的中心标志

html - 在具有水平滚动的可变宽度 div 中显示行内 block 元素

css - 为什么 `height: 100%` 和绝对定位在 Flexbox 中不起作用?

javascript - 使用 ionic 触摸事件更新 moment.js 持续时间

html - 如何仅在电子邮件模板中针对 outlook 的样式?

html - 如何制作 2 个柔性 block 和 1 个固定 block ?

html - 在 JSF 2.0 和 IceFace 中的单选按钮之间添加空格

html - 在不使用溢出的情况下摆脱未知边距/填充的最简单方法是什么?

javascript - 悬停的元素宽度会扩展,以便它可以容纳其中的所有内容