html - h1 在 firefox 的网格布局中具有空大小

标签 html css css-grid

我正在尝试使用网格布局在标题、firefox 浏览器 (v 63.0) 以及 chrome (v 70.0.3538.77) 中显示我的元素,并且所有这些都正确显示,除了尽管单元格对他来说足够大,但 h1 以某种方式保持空大小(但仍然可见,请参阅屏幕截图以了解更多详细信息)(我已经通过将其放在网格之外并检查其大小进行了测试。)

这是 html(在 pug 中)

link(rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous")
link(rel="stylesheet" href="/style/header.css")

header
  h1 3615 MyBlog
  div.innerGrid
      h1 3615 MyBlog
      span.subline Node.js is cool!
      span.admin
          i.fas.fa-cog
          |Administration

header.css

body{
    margin: 0;
}

header{
    width: 100vw;
    height: 100px;
}

.innerGrid{
    width: 90vw;
    height: 90%;
    display: grid;
    margin: auto;
    grid-template-columns: 200px auto 200px;
    grid-template-rows: 10px 40px 20px 20px auto;
    grid-template-areas:
            ". . ."
            "title . button"
            ". . ."
            "subline . ."
            ". . .";
}

.innerGrid h1{
    grid-area: title;
}

.innerGrid .subline{
    grid-area: subline;
}

.innerGrid .admin{
    grid-area: button;
}

.innerGrid {
  border: 1px solid black;
}

.innerGrid > * {
  border: 1px solid red;
}

如您所见,子线和按钮的行为符合预期,但网格外的 h1 大小为 38.4px(在我的计算机上),但网格中的 h1 大小为 0px(而它应该在其中的单元格大小为 40px,明显优于 38.4px)。

edit : 在 css 中添加截图和边框以显示问题

screenshot to show the problem

感谢您的帮助。

最佳答案

问题很可能来自 h1 具有由浏览器设置的默认边距,因此不像您的 span 那样没有任何边距。重置默认边距和填充是常见的做法,请参阅 this link .在您的情况下,您也可以简单地重置此特定元素的边距,如下所示:

.innerGrid h1 {
    margin: 0;
}

关于html - h1 在 firefox 的网格布局中具有空大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53029677/

相关文章:

css - 修复了相对可滚动内容中的按钮位置

html - 如何在不更改 bootstrap.css 文件的情况下管理 Bootstrap 列的宽度?

css - Tailwind 网格插件未安装

javascript - 通过其子项获取项目 ID (vanilla JS)

html - 可以在 CSS 中使用百分比指定页面的某些部分吗?

asp.net - 如何确保在单击 sun-menu 时顶级菜单项的 CSS 类已选中?

CSS Flexbox - CSS 网格中的截断文本(仅限 Firefox)

css - 将网格内容居中,同时将每行的内容左对齐,并具有任意的元素/列宽度

javascript - 如何防止include bootstrap-combined.min.css 后表格样式改变?

javascript - PHP 获取脚本标签之间的值