html - 垂直对齐(行高法)不起作用

标签 html css position alignment

我的 HTML 文件中的代码如下:

#firstblock h1 {
    font-family:'Open Sans';
    font-size: 12vh;
    text-align: center;
}
#firstblock {
    position: relative;
    height: 200px;
    line-height: 200px;
}
<div id="firstblock">
  <div id="title">
    <h1>TITLE</h1>
  </div>
</div>

我看不出垂直对齐不起作用的原因。我将不胜感激任何帮助,但我宁愿不使用表格方法。非常感谢。

最佳答案

你很接近。在 h1 上将边距设置为 0,您将获得预期的结果。

#firstblock {
  position: relative;
  height: 200px;
  line-height: 200px;
  border: 1px dotted blue;
}
#firstblock h1 {
  font-family: 'Open Sans';
  font-size: 12vh;
  text-align: center;
  margin: 0;
}
<div id="firstblock">
  <div id="title">
    <h1>TITLE</h1>
  </div>
</div>

关于html - 垂直对齐(行高法)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28917907/

相关文章:

php - 如何抓取html+css

html - 没有设置高度的 flex-direction 列中的高度相等

css - 使用 padding-bottom 方法规范化列高度会导致使用名称 anchor 出错

javascript - jQuery on page load顺序加载元素

CSS - 扩展类属性

jquery - 如何只使固定定位的 div 的一部分可见?

javascript - 我是否需要担心管理 html5 localStorage 的大小,或者是否会自动删除最近最少使用的项目?

php - 当使用 PHP while 循环创建表行时,如何根据内容更改表单元格的属性

html - 调整窗口大小时保持复选框在表单中的位置

html - 文本和图像定位