Html5 和 Css3 - 水平导航栏问题
Html5 and Css3 - Horizontal navigation bar issues
我正在设计一个网页。我有两层导航,第一层是社交媒体按钮,然后是导航栏。我在让导航栏的背景颜色覆盖整个网页时遇到问题,目前它以导航栏开始和停止。我猜这是与 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;
}
更新:
您在 CSS clearfix
中忘记了一些东西。
#clearfix:after {
display: block;
clear: both;
content: ''; /* add me */
}
此外,您的 HTML 中存在一些错误,这些错误可能会在不同的浏览器中以不同的方式影响呈现。
[1] <li>
的关闭标签无效
[2] 在您的 </nav>
.
收盘前额外 </div>
[3] 重复 ID:id="clearfix"
首先,修复重复的ID。在您的 CSS 中,更改为:
#clearfix:after {
display: block;
clear: both;
}
为此:
.clearfix:after {
display: block;
clear: both;
}
这是您的 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 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>
我正在设计一个网页。我有两层导航,第一层是社交媒体按钮,然后是导航栏。我在让导航栏的背景颜色覆盖整个网页时遇到问题,目前它以导航栏开始和停止。我猜这是与 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;
}
更新:
您在 CSS clearfix
中忘记了一些东西。
#clearfix:after {
display: block;
clear: both;
content: ''; /* add me */
}
此外,您的 HTML 中存在一些错误,这些错误可能会在不同的浏览器中以不同的方式影响呈现。
[1] <li>
[2] 在您的 </nav>
.
</div>
[3] 重复 ID:id="clearfix"
首先,修复重复的ID。在您的 CSS 中,更改为:
#clearfix:after {
display: block;
clear: both;
}
为此:
.clearfix:after {
display: block;
clear: both;
}
这是您的 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 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>