【发布时间】:2018-02-06 04:56:53
【问题描述】:
我是 CSS 网格的新手,这是我的第一次尝试。
在下面的代码中有一个带有网格包装器类的 div 容器。它包含两个子 div,类名为 grid-item。在 CSS 中,它们被称为 grid-item:nth-child(1) 和 grid-item:nth-child(2)。在 grid-wrapper 中,grid-template-areas 正确放置了 grid-item:nth-child(1) 和 grid-item:nth-child(2)。
grid-item:nth-child(2) 有自己的子项,但我无法让它们正确排列。
我确实有一个 FSFiddle 项目。
有人可以启发我吗?提前致谢。
body {
font-family: "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif;
}
.grid-wrapper {
display: grid;
grid-template-columns: repeat(8, {1fr});
grid-template-areas:
". header header header header header header ."
". tabs tabs tabs tabs tabs tabs .";
}
.grid-item:nth-child(1) {
grid-area: header;
background-color: #003566;
padding-top: 30px;
padding-bottom: 30px;
text-align: center;
border-bottom: 2px solid #ff6a00;
}
.grid-item:nth-child(2) {
grid-area: tabs;
background-color: #b3cccc;
padding-top: 10px;
padding-bottom: 10px;
/*grid-template-areas: "tabs tabs";
grid-template-columns: 1fr 1fr;*/
}
.logo {
grid-area: logo;
font-size: 1.3em;
color:#fff;
}
.logo span {
font-weight: 100;
color: #ff6a00;
}
.logo i {
font-size: 5px;
vertical-align: middle;
color: #fff;
}
.grid-item:nth-child(2)>div {
/*grid-area: tabs;*/
color: #003566;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SurEyeDentity Host Services Manager</title>
</head>
<body>
<div class="grid-wrapper">
<div class="grid-item">
<div class="logo">
SurEyeDentity<span> Host<i class="fa fa-circle" aria-hidden="true"></i>Services<i class="fa fa-circle" aria-hidden="true"></i>Manager</span>
</div>
</div>
<div class="grid-item">
<div>
<i class="fa fa-camera"></i> Cameras
</div>
<div>
<i class="fa fa-user" aria-hidden="true"></i> Users
</div>
</div>
</div>
</body>
</html>
【问题讨论】: