如何将菜单移动到徽标右侧并清理未使用的空间?

时间:2016-01-18 21:49:51

标签: html css menu navigation

我一直试图在网站上为我的朋友非营利组织获得一个布局,我正在开始,但我无法弄清楚如何摆脱菜单上未使用的空间或如何将菜单移动到徽标右侧。这就是网站现在看起来没有任何内容: https://i.gyazo.com/96210e6a810914ef4259d0a690040324.png

我想移开领导标签下面的空间,并使深蓝色背景在领导选项卡上只运行一定宽度,因为它与我的子菜单重叠。我也非常感谢如何将菜单移动到菜单旁边而不是下面的菜单。我的源代码是:

<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> &copy;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;
}

非常感谢任何帮助。谢谢!

2 个答案:

答案 0 :(得分:0)

this JsFiddle中播放您的代码后,我找到了解决问题的方法

  1. “领导”菜单项宽度的解决方案非常简单:向max-width提供#navigation ul li a:hover,以便背景与子菜单不会重叠
  2. 至于菜单位于徽标下方的问题,只需将徽标放在li顶部的ul
  3. 以下是您的代码将成为什么。

    注意:此处发布的代码是我更改的代码,因为完整代码检查了JsFiddle,这是因为您的代码在答案中发布的时间相当长。

    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
    }
    

    注意:这是一个关于如何修复它的示例,以您认为合适的方式进行更改。

    JsFiddle example again

    希望这有帮助!

答案 1 :(得分:0)

您可能希望使用flexbox方法(一个解决方案)

请参阅小提琴here

我在word wrap中放置了一个#navigation ul li属性,这样当窗口很小时,不会看到溢出,这些单词将只包含在它们各自的div中。使窗口变大以查看预期结果。

同时取出div上的边框(用于测试目的)