我从头开始制作网站。我在w3school看到了网格视图,并想到使用它。无论如何,我用我的.whole元素留下的浮动,但它不工作。我已经尝试改变它清除左侧,但它不工作。有人能帮我把两个.sections元素放在一起吗?如何将两个网格视图放在彼此附近?
* {
box-sizing: border-box;
}
.row::after {
content: "";
clear: both;
display: table;
}
[class*="col-"] {
float: left;
padding: 15px;
}
body {
font-family: "Lucida Sans", sans-serif;
}
.header {
width: 500px;
background-color: #9933cc;
color: #ffffff;
padding: 15px;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.menu li:hover {
background-color: #0099cc;
}
@media only screen and (min-width: 600px) {
/* For desktop: */
.col-3 {
width: 15%;
}
.col-6 {
width: 20%;
}
}
.sections {
width: 1300px;
}
.whole {
float: left;
}
<div class="whole">
<div class="sections">
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<div class="col-3 menu">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-6">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
</div>
</div>
</div>
<div class="sections">
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<div class="col-3 menu">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-6">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
</div>
</div>
</div>
</div>
一边,这绝对已经公布之前,所以检查出这样https://stackoverflow.com/questions/18344904/how-to-align-two-类似的问题divs-side-by-the-float-clear-and-overflow-elements – SMT
[如何将两个div并排使用浮动,清除和溢出元素与固定位置div对齐] (https://stackoverflow.com/questions/18344904/how-to-align-two-divs-side-by-side-using-the-float-clear-and-overflow-elements) –