引导程序需要包含元素来包装站点内容,并且 安置我们的网格系统。您可以从以下两个容器中选择一个 您的项目。请注意,由于填充等原因,两个容器都没有 是可嵌套的。
我可以仅使用一个容器轻松实现此布局吗?
* {
margin: 0;
padding: 0;
}
body {
background-color: silver;
}
section {
background-color: blue;
padding: 20px 0px;
}
section:nth-child(even) {
background-color: blueviolet;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<section>
<!--Here-->
<div class="container">
<h1>Section Title 1</h1>
<p>Content of section 1</p>
</div>
</section>
<section>
<!--Other container... Bad :/ -->
<div class="container">
<h1>Section Title 2</h1>
<p>Content of section 2</p>
</div>
</section>
</body>
</html>
答案 0 :(得分:-1)
您可以使用一个容器,并在其中使用两行。
* {
margin: 0;
padding: 0;
}
body {
background-color: silver;
}
.row {
background-color: blue;
padding: 20px 0px;
}
.row:nth-child(even) {
background-color: blueviolet;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<!--Here-->
<section>
<h1>Section Title 1</h1>
<p>Content of section 1</p>
</section>
</div>
<!--Other container... Bad :/ -->
<div class="row">
<section>
<h1>Section Title 1</h1>
<p>Content of section 1</p>
</section
</div>
</div>
</body>
</html>