我正在设计一个网页。我有两个级别的导航,第一级的社交媒体按钮和后来的导航栏。我在导航栏的背景颜色到网页的整个长度时遇到问题,目前它通过导航栏启动和停止。我猜这是一个与clearfix的位置或编码有关的问题?无论如何,我很感激你的建议。我的编码如下,我附上了我网站的照片,以便您可以看到它的外观。
我的Html代码:
<div id="wrapper">
<header id="header" role="banner">
<div id="logo">
<a href="index.html"><img src="Images/title.png" alt="logo" width="1018" height="140"></a>
</div>
<div id="social">
<ul>
<li>
<a href="https://twitter.com/SaveADHCNSW#" target="_blank"><img src="images/twitter.png" alt="Twitter" width="32" height="32"></a>
</li>
<li>
<a href="https://www.facebook.com/Save-NSW-Government-Disability-
Services-ADHC-709029659182219/" target="_blank"><img src="images/facebook.png" alt="Facebook" width="32" height="32"></a>
</li>
<li>
<a href="https://www.youtube.com/channel/UCS0HQwz4LWWGS4AZhb5Ry3w" target="_blank"><img src="images/youtube.png" alt="Youtube" width="32" height="32"></a>
</li>
</ul>
</div>
<div id="clearfix">
</div>
<nav id="page_nav">
<div class="menu">
<ul id="navmenu">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="aboutus.html">About Us</a></li>
<li><a href="#">Get Involved</a><span class="darrow">▼</span>
<ul class="submenu">
<li><a href="socialmedia.html">Social Media</a></li>
<li><a href="unionmeeting.html">Union Meetings</a></li>
<li><a href="rally.html">Rally</a></li>
</ul>
</li>
<li><a href="#">News</a><span class="darrow">▼</span>
<ul class="submenu">
<li><a href="shrewsnews.html">Shrew's News</a></li>
<li><a href="update.html">Update</a></li>
</ul>
</li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="contacts.html">Contact Us</a></l>
</ul>
</div>
<div id="clearfix">
</div>
</div>
</nav>
</header>
</div>
我的Css:
* {
margin: 0px;
padding: 0px;
}
body {
font-family: sans-serif;
background-color: black;
}
#wrapper {
width: 1366px;
height: auto;
background-color: black;
margin: 0 auto;
padding: 10px;
}
#header {
width: 100%;
height: 140px;
background-color: black;
}
#logo {
float: left;
margin: 0px 0px 20px 50px;
padding-left: 100px;
}
#social {
float: right;
top: 0px;
margin: 0 auto;
}
#social ul li {
float: left;
list-style: none;
padding: 5px;
}
#clearfix:after {
display: block;
clear: both;
}
#page_nav {
background-color: #c50a13;
}
ul#navmenu {
list-style-type: none;
width: 800px;
margin: auto auto 5px auto;
}
ul.submenu {
list-style-type: none;
}
ul#navmenu li {
outline: 1px solid white;
width: 125px;
text-align: center;
position: relative;
float: left;
margin-right: 4px;
color: #26b0f1;
}
ul#navmenu a {
text-decoration: none;
display: block;
width: 125px;
height: 25px;
line-height: 25px;
background-color: #c50a13;
border: 1px solid white;
border-radius: 5px;
color: white;
}
ul#navmenu .submenu a {
margin-top: 3px;
}
ul#navmenu li:hover > a {
background-color: white;
color: #c50a13;
}
ul#navmenu ul.submenu {
display: none;
position: absolute;
top: 26px;
left: 0px;
}
ul#navmenu li:hover .submenu {
display: block;
}
.darrow {
font-size: 14pts;
position: absolute;
top: 10px;
right: 1px;
color: dodgerblue;
}
答案 0 :(得分:0)
<强>更新强>
你忘记了CSS #clearfix:after {
display: block;
clear: both;
content: ''; /* add me */
}
中的内容。
<li>
此外,HTML中存在一些错误,这些错误会在不同浏览器中以不同方式影响渲染。
[1] </div>
[2] </nav>
结束前的额外id="clearfix"
。
[3] 重复ID:#clearfix:after {
display: block;
clear: both;
}
首先,修复重复的ID。在你的CSS中,改变这个:
.clearfix:after {
display: block;
clear: both;
}
对此:
<div id="wrapper">
<header id="header" role="banner">
<div id="logo">
<a href="index.html"><img src="Images/title.png" alt="logo" width="1018" height="140"></a>
</div>
<div id="social">
<ul>
<li>
<a href="https://twitter.com/SaveADHCNSW#" target="_blank"><img src="images/twitter.png" alt="Twitter" width="32" height="32"></a>
</li>
<li>
<a href="https://www.facebook.com/Save-NSW-Government-Disability-Services-ADHC-709029659182219/" target="_blank"><img src="images/facebook.png" alt="Facebook" width="32" height="32"></a>
</li>
<li>
<a href="https://www.youtube.com/channel/UCS0HQwz4LWWGS4AZhb5Ry3w" target="_blank"><img src="images/youtube.png" alt="Youtube" width="32" height="32"></a>
</li>
</ul>
</div>
<div class="clearfix">
</div>
<nav id="page_nav">
<div class="menu">
<ul id="navmenu">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="aboutus.html">About Us</a></li>
<li>
<a href="#">Get Involved</a><span class="darrow">▼</span>
<ul class="submenu">
<li><a href="socialmedia.html">Social Media</a></li>
<li><a href="unionmeeting.html">Union Meetings</a></li>
<li><a href="rally.html">Rally</a></li>
</ul>
</li>
<li>
<a href="#">News</a><span class="darrow">▼</span>
<ul class="submenu">
<li><a href="shrewsnews.html">Shrew's News</a></li>
<li><a href="update.html">Update</a></li>
</ul>
</li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="contacts.html">Contact Us</a></li>
</ul>
</div>
<div class="clearfix">
</div>
</nav>
</header>
</div>
这是您的HTML没有错误。
{{1}}