为什么我的标题和导航在不同页面上的行为方式不同? 我试图制作另一个与主页面具有相同导航和标题的页面,但出于某种原因,即使它使用相同的CSS,它在我试图制作的第二页上的行为也不同。
第一页 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Amanda Farrington</title>
<link rel="stylesheet" href="css/demo.css" />
<link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="header">
<div id="leftHeader">
<img src="assets/logo2.jpg" alt="Logo" style="width:65px;height:65px">
<h1>Amanda Farrington</h1>
</div>
<div id="nav">
<ul>
<li><a href="index.html">About</a></li>
<li><a href="#workJump">Work</a></li>
<li><a href="mentally.html">Contact</a></li>
</ul>
</div>
</div>
<div id="hero">
<div id="heroImage">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:10%">
</div>
<div id="overlay">
<h2>Amanda Farrington</h2>
<h3>Graphic Artist | Web Designer</h3>
</div>
</div>
<a name="workJump"></a>
<div id="work">
<div id="label">
<h4>Work</h4>
</div>
<div id="leftColumn">
<div id= "p2article">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
</div>
<div id="rightColumn">
<div id= "p2article2">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article2">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article2">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
<div id= "p2article2">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:100%">
<div id= "articleinfo2">
<div id= "articleText2">
<span class="title3">Beyond the Bricks 2-2</span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
第二页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Amanda Farrington</title>
<link rel="stylesheet" href="css/demo.css" />
<link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="header">
<div id="leftHeader">
<img src="assets/logo2.jpg" alt="Logo" style="width:65px;height:65px">
<h1>Amanda Farrington</h1>
</div>
<div id="nav">
<ul>
<li><a href="index.html">About</a></li>
<li><a href="tips.html">Work</a></li>
<li><a href="mentally.html">Contact</a></li>
</ul>
</div>
</div>
<div id="hero2">
<h6>Project Type</h6>
<h5>Project Title</h5>
</div>
<div id="workImage">
<img src="assets/trees.jpg" alt="Logo" style="width:100%;height:100%">
</div>
</body>
</html>
CSS
body {
margin: 0px;
padding: 0px;
height: 100%;
background: white;
}
/*----------header styles-------------*/
#header {
color: #D7DADB;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size : 15px;
text-align: left;
width: 100%;
padding-left: 3em;
position: relative;
height: 15%;
box-sizing: border-box;
}
#header img
{
float: left;
padding-left: 3em;
}
h1{
width: 9em;
float: left;
padding-left: 0.5em;
color: #45CCCC;
padding-bottom: 1px;
}
#nav {
width: 40%;
margin:0;
padding:0;
text-align: right;
color: red;
font-size:20px;
float: right;
padding-right: 2em;
}
#nav ul {
padding: 1px;
}
#nav li {
display: inline;
padding: 38px;
}
#nav li a {
color: #2C3E50;
text-decoration: none;
}
#nav li a:hover {
color: #45CCCC;
}
/*----------hero image styles-------------*/
#hero{
width: 100%;
height: 30em;
position: relative;
}
#heroImage
{
top: 9%;
width: 100%;
z-index: 1;
position: absolute;
}
#overlay{
width: 34em;
top: 70%;
margin-left: 30%;
z-index: 2;
position: relative;
clear: left;
}
h2{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 60px;
float: center;
color: white;
opacity: 1.0;
text-shadow: 2px 2px 3px #000000;
text-align: center;
}
h3{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 30px;
color: white;
opacity: 1.0;
text-shadow: 3px 3px 2px #000000;
text-align: center;
}
/*----------work main styles-------------*/
#leftColumn
{
width: 50%;
float: left;
height: 70em;
}
#rightColumn
{
width: 50%;
height: 70em;
float: right;
}
#label{
width: 100%;
height: 2em;
top: 10em;
}
#work{
width: 100%;
height: 10em;
position: relative;
top: 8em;
}
h4{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 40px;
color: #45CCCC;
opacity: 1.0;
text-align: center;
}
#p2article2
{
width: 70%;
height:20em;
float: center;
display: block;
margin-left: auto;
margin-left: 60px;
margin-bottom: 10em;
margin-top: 5em;
border: 1px solid #cccccc;
background: purple;
}
#p2article
{
width: 70%;
height:20em;
float: center;
display: block;
margin-left: auto;
margin-right: 60px;
margin-bottom: 10em;
margin-top: 5em;
border: 1px solid #cccccc;
background: purple;
}
#articleinfo2
{
width:100%;
height:10em;
display: block;
margin-bottom: 5em;
}
#articleText2{
width: 90%;
height:70%;
margin: 5%;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 30px;
color: black;
}
/*----------work page styles-------------*/
#hero2{
width: 100%;
height: 10em;
position: relative;
background: red;
top: 10em;
}
#workImage
{
top: 9%;
width: 100%;
z-index: 1;
position: static;
}
h5{
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 40px;
color: #45CCCC;
float: left;
}
h6{
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 20px;
color: #45CCCC;
float: left;
}
答案 0 :(得分:0)
测试了一下,这似乎是由于没有清除float
,从#header
删除负上边距然后添加最后一行CSS应该解决它:
#overlay {
width: 100%;
height: 30em;
position: relative;
clear: left;
}
您可能希望对#work
执行相同操作,即使它似乎不会影响布局。
如果我可以添加 - 不是所有的花车都是必要的。例如,删除#header
上的那个似乎没有任何影响。我猜它使用的越少越好。如果您愿意,可以使用这段代码摆脱水平滚动条:
#header {
color: #D7DADB;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size : 15px;
text-align: left;
width: 100%;
padding-left: 3em;
position: relative;
height: 15%;
box-sizing: border-box;
}