gpt4 book ai didi

html - 为什么我的标题和导航在具有相同 CSS 的不同页面上表现不同

转载 作者:太空宇宙 更新时间:2023-11-04 12:03:36 25 4
gpt4 key购买 nike

为什么我的页眉和导航在不同的页面上表现不同?我试图制作另一个页面,该页面具有与主页相同的导航和标题,但由于某种原因,即使它使用相同的 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;

}

最佳答案

测试了一下,似乎是因为没有清除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;
}

关于html - 为什么我的标题和导航在具有相同 CSS 的不同页面上表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29552062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com