如何将菜单移动到徽标右侧并清理未使用的space?
How to move menu to the right of the logo and to clean up unused space?
我一直在尝试为我的朋友和我的朋友们在一个非营利组织的网站上设置布局,但我不知道如何摆脱菜单上未使用的 space 或如何将菜单移动到徽标的右侧。这是网站现在的样子,没有任何内容:
https://i.gyazo.com/96210e6a810914ef4259d0a690040324.png
我想去掉领导选项卡下方的 space 并使深蓝色背景仅 运行 在领导选项卡上达到一定宽度,因为它与我的子菜单。我也非常感谢有关如何将菜单移动到菜单旁边而不是菜单下方的说明。我的源代码是:
<html>
<head>
<title>Home </title>
<link type="text/css" rel="stylesheet" href="stylesheethome.css"/>
</head>
<body>
<div id="header">
<a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a>
</div> <!-- header !-->
<div id="navigation">
<ul>
<li> <a href="WhoWeAre.php">WHO WE ARE</a>
<ul class="wwedrop">
<li> <a href="BefaAtAGlance.php"> BEFA AT A GLANCE</a> </li>
<li> <a href="Leadership.php"> LEADERSHIP </a>
<ul class="leaders">
<li> <a href="BoardofDirectors.php">BOARD OF DIRECTORS </a> </li>
<li> <a href="ExecutiveOfficers.php">EXECUTIVE OFFICERS </a> </li>
<li> <a href="ManagementCommittee.php"> MAMANGEMENT COMMITTEE </a> </li>
</ul> <!-- These are the links underneath/to the side of the Leadership tab of the Who We Are tab !-->
</li>
</ul> <!-- These are links underneath the "Who We Are" tab !-->
</li>
<li> <a href="Locations.php"> LOCATIONS </a> </li>
<li> <a href="Volunteers.php"> VOLUNTEERS </a> </li>
<li> <a href="Donate.php"> DONATE </a> </li>
<li> <a href="FuturePlans.php"> FUTURE PLANS </a> </li>
<li> <a href="ContactUs.php"> CONTACT US </a> </li>
</ul> <!-- These are the tabs underneath the navigation bar. Right now, only the Who We Are tab has a nested list(s) !-->
</div> <!-- navigation !-->
<div id="container">
<div id="content">
<div id="contentleft">
</div> <!-- contentleft !-->
</div><!-- content !-->
</div><!-- container !-->
<div id="sidebar">
</div>
<div id="footer">
<p> ©2016 Befa Inc. </p>
</div>
</body>
</html>
我的 css 代码是:
img{
border:none;
}
html{
background: url("gradientbackground.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body{
color:#111517;
font-family: Helvetica;
}
header{
width: 50px;
min-height: 60px;
margin: 0 auto;
}
#navigation{
width: 960 px;
margin: 0 auto;
position: relative;
top: 0 px;
right: 0 px;
}
.main-navigation a {
border-bottom: 1px solid #888;
border-top: 1px solid #888;
}
#navigation ul{
margin:0;
padding:0;
list-style-type:none;
}
#navigation ul li{
display:inline-block;
position: relative;
line-height: 20 px;
text-align: left;
font-weight: bold;
font-family: Helvetica;
}
#navigation ul li a{
display: block;
padding: 10px 30px;
color:#111517;
text-decoration:none;
}
#navigation ul li a:hover{
background-color: #000066;
color: #ffffff
}
#navigation ul li ul.wwedrop{
min-width: 125 px;
background: #f2f2f2;
display: none;
position: absolute;
z-index:999;
left:0;
}
#navigation ul li:hover ul.wwedrop{
display: block;
}
#navigation ul li ul.wwedrop li{
display: block;
}
#navigation ul li ul.wwedrop li ul.leaders{
display: none;
}
#navigation ul.wwedrop li:hover ul.leaders{
display:block;
margin-left:175px;
margin-top: -70px;
}
/* the navigation list material goes here and I need to edit it so that it looks like the goldman sachs one by putting sliding feature etc. */
container{
background:#eef7fa;
}
#footer p{
font-size: 11px;
position: absolute;
}
如有任何帮助,我们将不胜感激。谢谢!
在 this JsFiddle 中使用您的代码后,我找到了解决您的问题的方法
- 解决"leadership"菜单项宽度的方法很简单:给
#navigation ul li a:hover
一个max-width
,这样背景就不会再和子菜单重叠了
- 至于菜单位于徽标下方的问题,只需将您的徽标放在
ul
顶部的 li
中即可。
这就是您的代码将变成的样子。
注意:这里的代码post是我改过的代码,完整代码请查看JsFiddle,这是因为你的代码比较长post 在回答中。
HTML
<div id="header">
<!-- <a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a> -->
<!-- Removed this <a> -->
</div> <!-- header !-->
<div id="navigation">
<ul>
<li id="logo"><a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a></li>
<!-- Added the logo here -->
<li> <a href="WhoWeAre.php">WHO WE ARE</a>
</li>
</ul>
</div>
CSS
#navigation ul li a:hover{
background-color: #000066;
max-width:130px; /* Added this to solve the overflowing background -->
color: #ffffff
}
注意:这是一个关于如何修复它的示例,以您认为合适的方式更改它。
希望对您有所帮助!
你可能想为此使用 flexbox 方法(一种解决方案)
参见 fiddle here
我在#navigation ul li
里放了一个word wrap
属性这样当window小的时候就不会出现溢出,单词会在各自的[中换行=21=]。将 window 调大以查看预期结果。
同时去掉 div 的边框(用于测试目的)
我一直在尝试为我的朋友和我的朋友们在一个非营利组织的网站上设置布局,但我不知道如何摆脱菜单上未使用的 space 或如何将菜单移动到徽标的右侧。这是网站现在的样子,没有任何内容: https://i.gyazo.com/96210e6a810914ef4259d0a690040324.png
我想去掉领导选项卡下方的 space 并使深蓝色背景仅 运行 在领导选项卡上达到一定宽度,因为它与我的子菜单。我也非常感谢有关如何将菜单移动到菜单旁边而不是菜单下方的说明。我的源代码是:
<html>
<head>
<title>Home </title>
<link type="text/css" rel="stylesheet" href="stylesheethome.css"/>
</head>
<body>
<div id="header">
<a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a>
</div> <!-- header !-->
<div id="navigation">
<ul>
<li> <a href="WhoWeAre.php">WHO WE ARE</a>
<ul class="wwedrop">
<li> <a href="BefaAtAGlance.php"> BEFA AT A GLANCE</a> </li>
<li> <a href="Leadership.php"> LEADERSHIP </a>
<ul class="leaders">
<li> <a href="BoardofDirectors.php">BOARD OF DIRECTORS </a> </li>
<li> <a href="ExecutiveOfficers.php">EXECUTIVE OFFICERS </a> </li>
<li> <a href="ManagementCommittee.php"> MAMANGEMENT COMMITTEE </a> </li>
</ul> <!-- These are the links underneath/to the side of the Leadership tab of the Who We Are tab !-->
</li>
</ul> <!-- These are links underneath the "Who We Are" tab !-->
</li>
<li> <a href="Locations.php"> LOCATIONS </a> </li>
<li> <a href="Volunteers.php"> VOLUNTEERS </a> </li>
<li> <a href="Donate.php"> DONATE </a> </li>
<li> <a href="FuturePlans.php"> FUTURE PLANS </a> </li>
<li> <a href="ContactUs.php"> CONTACT US </a> </li>
</ul> <!-- These are the tabs underneath the navigation bar. Right now, only the Who We Are tab has a nested list(s) !-->
</div> <!-- navigation !-->
<div id="container">
<div id="content">
<div id="contentleft">
</div> <!-- contentleft !-->
</div><!-- content !-->
</div><!-- container !-->
<div id="sidebar">
</div>
<div id="footer">
<p> ©2016 Befa Inc. </p>
</div>
</body>
</html>
我的 css 代码是:
img{
border:none;
}
html{
background: url("gradientbackground.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body{
color:#111517;
font-family: Helvetica;
}
header{
width: 50px;
min-height: 60px;
margin: 0 auto;
}
#navigation{
width: 960 px;
margin: 0 auto;
position: relative;
top: 0 px;
right: 0 px;
}
.main-navigation a {
border-bottom: 1px solid #888;
border-top: 1px solid #888;
}
#navigation ul{
margin:0;
padding:0;
list-style-type:none;
}
#navigation ul li{
display:inline-block;
position: relative;
line-height: 20 px;
text-align: left;
font-weight: bold;
font-family: Helvetica;
}
#navigation ul li a{
display: block;
padding: 10px 30px;
color:#111517;
text-decoration:none;
}
#navigation ul li a:hover{
background-color: #000066;
color: #ffffff
}
#navigation ul li ul.wwedrop{
min-width: 125 px;
background: #f2f2f2;
display: none;
position: absolute;
z-index:999;
left:0;
}
#navigation ul li:hover ul.wwedrop{
display: block;
}
#navigation ul li ul.wwedrop li{
display: block;
}
#navigation ul li ul.wwedrop li ul.leaders{
display: none;
}
#navigation ul.wwedrop li:hover ul.leaders{
display:block;
margin-left:175px;
margin-top: -70px;
}
/* the navigation list material goes here and I need to edit it so that it looks like the goldman sachs one by putting sliding feature etc. */
container{
background:#eef7fa;
}
#footer p{
font-size: 11px;
position: absolute;
}
如有任何帮助,我们将不胜感激。谢谢!
在 this JsFiddle 中使用您的代码后,我找到了解决您的问题的方法
- 解决"leadership"菜单项宽度的方法很简单:给
#navigation ul li a:hover
一个max-width
,这样背景就不会再和子菜单重叠了 - 至于菜单位于徽标下方的问题,只需将您的徽标放在
ul
顶部的li
中即可。
这就是您的代码将变成的样子。
注意:这里的代码post是我改过的代码,完整代码请查看JsFiddle,这是因为你的代码比较长post 在回答中。
HTML
<div id="header">
<!-- <a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a> -->
<!-- Removed this <a> -->
</div> <!-- header !-->
<div id="navigation">
<ul>
<li id="logo"><a href="home.php"><img src="logo.jpg" alt="BEFA Inc." height="100" width="130" /></a></li>
<!-- Added the logo here -->
<li> <a href="WhoWeAre.php">WHO WE ARE</a>
</li>
</ul>
</div>
CSS
#navigation ul li a:hover{
background-color: #000066;
max-width:130px; /* Added this to solve the overflowing background -->
color: #ffffff
}
注意:这是一个关于如何修复它的示例,以您认为合适的方式更改它。
希望对您有所帮助!
你可能想为此使用 flexbox 方法(一种解决方案)
参见 fiddle here
我在#navigation ul li
里放了一个word wrap
属性这样当window小的时候就不会出现溢出,单词会在各自的[中换行=21=]。将 window 调大以查看预期结果。
同时去掉 div 的边框(用于测试目的)