我有以下代码,当我使用基于像素的测量时完美工作,但我想使用百分比,而当我使用百分比时,它会破坏我的布局,如下图所示当使用百分比而不是像素时HTML5布局
正如你可以看到上面的图片,正文内容和网站标语相互重叠。我需要将标语连同下面的无序列表一起放入蓝色部分。它在基于像素的布局上工作得很好,现在它在应用百分比上搞砸了。
这里是我的HTML 5基于标记
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<link href = "site.css" rel = "stylesheet">
<title>Test Page - Test Title of my homepage</title>
</head>
<body>
<header>
<div id = "SiteTitle">
<h1>This is a test !</h1>
</div>
<div id = "Tagline">
<p>This is a test tagline of the website</p>
</div>
<nav>
<div id = "MainMenu">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</nav>
</header>
<section>
<div id = "MainContent">
Main Site Cotent
</div>
</section>
<footer>
The Footer
</footer>
</body>
</html>
,这里是CSS文件
*{
margin: 0;
padding: 0;
height: 100%;
}
header{
background-color: blue;
height: 15%;
}
nav{
}
#SiteTitle{
color: black;
}
#Tagline{
color: black;
}
#MainMenu ul li{
color: black;
}
#MainContent{
height: 70%;
}
footer{
background-color: green;
height: 15%;
}
'* {身高:100%}'使每一个元件100%的高度,我不认为这是可取的。这不会解决你的问题。我不完全清楚你想达到什么目的。你能画一些东西来澄清你的目标。 – LinkinTED
你想要查看端口高度的70%和15%? –
是这个工作http://jsfiddle.net/4Ze6A/添加明确这两个属性。 –