gpt4 book ai didi

html - 下拉菜单不显示和导航不居中

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

示例:http://www.studentbridges.org/new/

我试图让我的导航栏横跨网页顶部,我让 Nav 的 div 横跨网页,但是当我将导航菜单放在 div 中时,下拉菜单停止工作并且无论我做什么,链接都不居中(文本对齐:CSS 中的居中和标题中的标记不起作用)。

这是我的代码:

导航

.access {
clear: both;
display: block;
float: left;
margin: 0 auto 6px;
width: 100%;
}
.access ul {
font-size: 16px;
list-style: none;
margin: 0 0 0 -0.8125em;
padding-left: 0;
}
.access li {
float: left;
position: relative;
}
.access a {
color: #eee;
display: block;
line-height: 3.333em;
padding: 0 1.2125em;
text-decoration: none;
}
.access ul ul {
display: none;
float: left;
margin: 0;
position: absolute;
top: 3.333em;
left: 0;
width: 188px;
z-index: 99999;
}
.access ul ul ul {
left: 100%;
top: 0;
}
.access ul ul a {
background: #EAC57E;
border-bottom: 1px dotted #ddd;
color: #F7E7C6;
font-size: 14px;
font-weight: normal;
height: auto;
line-height: 1.4em;
padding: 10px 10px;
width: 168px;
}
.access li:hover > a,
.access ul ul :hover > a,
.access a:focus {
background: #DBAA4A;
}
.access li:hover > a,
.access a:focus {
background: #DBAA4A; /* Show a solid color for older browsers */;
color: #F7E7C6;
}
.access ul li:hover > ul {
display: block;
}
.access .current-menu-item > a,
.access .current-menu-ancestor > a,
.access .current_page_item > a,
.access .current_page_ancestor > a {
font-weight: bold;
}

顶部导航 DIV:

div#topnav

{
margin: 0px;

overflow: hidden;

width: 100%;

height: 50px;

background: #8D1D1D;

}

如果您能就问题所在提出任何意见,我们将不胜感激!

HTML:

<div id="topnav"><center><div class="access"><ul id="menu-home" class="access"><li id="menu-item-43" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-43"><a href="http://www.studentbridges.org/new/">Home</a></li>
<li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-45"><a href="http://www.studentbridges.org/new/sample-page/">About Us</a>
<ul class="sub-menu">
<li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50"><a href="http://www.studentbridges.org/new/sample-page/history/">History</a></li>
<li id="menu-item-51" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-51"><a href="http://www.studentbridges.org/new/sample-page/resources/">Resources</a></li>
<li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52"><a href="http://www.studentbridges.org/new/sample-page/testimonials/">Testimonials</a></li>
<li id="menu-item-47" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-47"><a href="http://www.studentbridges.org/new/sample-page/community-partnerships/">Community Partnerships</a></li>
<li id="menu-item-49" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-49"><a href="http://www.studentbridges.org/new/sample-page/donors-supporters/">Donors &#038; Supporters</a></li>
<li id="menu-item-48" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-48"><a href="http://www.studentbridges.org/new/sample-page/contribute/">Contribute</a></li>
<li id="menu-item-46" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-46"><a href="http://www.studentbridges.org/new/sample-page/advisory-boards/">Advisory Boards</a></li>
</ul>
</li>
<li id="menu-item-56" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-56"><a href="http://www.studentbridges.org/new/for-umass-students/">For UMass Students</a>
<ul class="sub-menu">
<li id="menu-item-57" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-57"><a href="http://www.studentbridges.org/new/for-umass-students/sb-service-learning-293/">SB Service Learning 293</a></li>
<li id="menu-item-59" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-59"><a href="http://www.studentbridges.org/new/for-umass-students/volunteer-oppertunities/">Volunteer Oppertunities</a></li>
<li id="menu-item-58" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-58"><a href="http://www.studentbridges.org/new/for-umass-students/staff-openings/">Staff Openings</a></li>
</ul>
</li>
<li id="menu-item-53" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-53"><a href="http://www.studentbridges.org/new/access-materials/">Access Materials</a></li>
<li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-54"><a href="http://www.studentbridges.org/new/advocacy/">Advocacy</a></li>
<li id="menu-item-55" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-55"><a href="http://www.studentbridges.org/new/for-community-members/">For Community Members</a></li>
<li id="menu-item-60" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-60"><a href="http://www.studentbridges.org/new/our-staff/">Our Staff</a></li>
<li id="menu-item-61" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-61"><a href="http://www.studentbridges.org/new/photos/">Photos</a></li>
<li id="menu-item-62" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-62"><a href="http://www.studentbridges.org/new/blog/">Blog</a></li>
</ul></div></center></div>

最佳答案

给你:

http://jsfiddle.net/UjEd5/

实际的导航选项本身是不同的,但 CSS 使用相同的 ID/类您正在使用的结构。

你会发现我变了

<div class="access">

<div class="topmenu">

如果您为“topmenu”DIV 和“access”UL 分配相同的宽度,它将居中栏中的导航。

希望这对您有所帮助!

关于html - 下拉菜单不显示和导航不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11903993/

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