我试图了解 HTML 结构如何影响CSS 网格布局模块规范。我正在使用启用了实验功能的 Chrome Canary。
附加代码按预期工作,但将导航和搜索放在标题标签内只是为了语义会抛出 CSS 网格放置。
我缺少什么能够使用 CSS 网格模块并仍然将我的语义标头与导航、品牌和搜索包装在我的标头标签中?
html {
box-sizing: border-box;
min-height: 2000px;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.wrapper {
width: 100%;
display: grid;
grid-template-columns: 20% auto 20%;
grid-template-rows: 50px auto 50px;
background-color: #fff;
color: #444;
}
.mainheader {
grid-column: 1 / span 3;
grid-row: 1;
background: #39444C;
}
.brand {
height: 100%;
margin: auto;
color: #FFFFFF;
background: #2E3840;
}
.search {
grid-column: 3;
grid-row: 1;
}
.navbar {
grid-column: 2;
grid-row: 1;
background: #39444C;
}
ul {
padding: 12px;
margin: 0;
}
.navbar li {
display: inline;
padding: 10px;
}
.navbar li a {
color: #9CA19A;
text-decoration: none;
font-size: 1.1rem;
}
.navbar a:hover {
color: #00A5D5;
}
.sidenav {
grid-column: 1;
grid-row: 2;
background: #F2F2F2;
}
.content {
grid-column: 2;
grid-row: 2;
background: yellow;
}
.mainfooter {
background: gray;
grid-column: 1 / span 2;
grid-row: 3;
}
.mainheader h1 {
font-size: 2.8vw;
}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="wrapper">
<header class="mainheader">
<h1 class="brand">Simply Expense</h1>
</header>
<nav class="navbar">
<ul>
<li><a href="#">Expenses</a>
</li>
<li><a href="#">Receipts</a>
</li>
<li><a href="#">Reports</a>
</li>
</ul>
</nav>
<div class="search">
<button>test</button>
<input type="text">
</div>
<aside class="sidenav">
Side nav
</aside>
<div class="content">
<button>test</button>
<button>test</button>
<button>test</button>
</div>
<footer class="mainfooter">
Footer
</footer>
</div>
</body>
</html>