我无法理解为什么我的col4正在低于彼此,而不是连续。 Sec 1和Sec 2应该是彼此相邻的。我试图在我的CSS中定义所有col宽度。我在这里错过了什么?
HTML
<!DOCTYPE html>
<html>
<head>
<title>| Fishing |</title>
<link type="text/css" rel="stylesheet" href="css/build.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="main-header" role="main">
</div>
<div class="row">
<div class="col12">
<h2>Report</h2>
</div>
</div>
<div class="row" role="section">
<div class="col4">
<h4>Sec 1</h4>
</div>
<div class="col4" role="section">
<h4>Sec 2</h4>
</div>
</div>
</body>
</html>
CSS
html, body {
margin: 0px;
padding: 0px;
font-size: 40px;
}
.main-header {
background: url(../img/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 500px;
margin-bottom: 20px;
overflow: hidden;
}
/* Rows */
.row{
margin-left:-15px;
margin-right:-15px;
}
.row{:after{
content:'';
display:block;
clear:both
}
/* General properties of columns */
.col{
padding: 0rem;
float:left;
}
/* Column Definition */
.col1{
width:8.33333333%
}
.col2{
width:16.66666667%
}
.col3{
width:25%
}
.col4{
width:33.33333333%
}
.col5{
width:14.666667%
}
.col6{
width:50%;
}
.col7{
width:58.33333333%
}
.col8{
width:66.6666667%
}
.col9{
width:75%
}
.col10{
width:83.33333333%
}
.col11{
width:91.6666666%
}
.col12{
width:100%;
}
答案 0 :(得分:2)
首先,您遇到语法错误:
.row{:after{
content:'';
display:block;
clear:both
}
应该是:
.row:after{
content:'';
display:block;
clear:both
}
此外,您为.col
定义了一种样式,但它们不会应用于列,因为它们需要在col
类之外添加col4
类,例如:
<div class="col col4">
<h4>Sec 1</h4>
</div>