【发布时间】:2016-11-27 12:38:54
【问题描述】:
我用 HTML 和 CSS 设计了一个页面布局,但是当我为“Left for logo”div 设置填充时,这个 div 的高度增加了,我失去了页面的排列。
另外,由于我是CSS布局的初学者,请告诉我我的页面是正确的。
HTML
<!doctype html>
<html lang="fa">
<head>
<meta charset="utf-8">
<title>homepage</title>
<link href="css/home-stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header class="header-container">
<div class="header-area"></div>
<div class="logo-ads">
<div class="left">
Left for logo <!-- Set Div As your requirement -->
</div>
<div class="right">
Right for ads<!-- Set Div As your requirement -->
</div>
</div>
</header><!-- end of header -->
<div class="navigation">
navigation
</div><!-- end of nav -->
<div class="main">
main content
</div><!-- end of main -->
<div class="footer-container">
<div class="footer-end">
footer
</div>
</div><!-- end of footer -->
</body>
</html>
CSS
@charset "utf-8";
/* CSS Document */
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
/* header elements */
.header-container {
width: 100%;
}
.header-area {
height: 35px;
width: 100%;
background-color: #bb0700;
padding-right: 0px;
}
.logo-ads {
height: 110px;
width: 1000px;
background-color: #CFD1A9;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
z-index: 0;
}
.left {
float: left;
height: 110px;
width: 30%;
background-color: #F9F9E4;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
box-sizing: border-box;
}
.right {
float: right;
width: 70%;
height: 110px;
}
.navigation {
height: 35px;
width: 1000px;
background-color: #2A2929;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
color: #fff;
z-index: 1;
}
.main {
height: 1000px;
width: 1000px;
background-color: #F7E3E3;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
z-index: 2;
}
.footer-container {
height:35px;
width: 1000px;
background-color: #F2F1F1;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
z-index: 3;
}
.footer-end {
height: 35px;
width: 1000px;
background-color: #bb0700;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
z-index: 4;
}
【问题讨论】:
-
我相信你正在寻找这个:stackoverflow.com/questions/779434/….
-
啊,你刚刚被box-sizing这个东西咬了!您可以设置box-sizing 或更改您的身高。
-
@user3593846,谢谢,这是一个很好的解决方案。