【问题标题】:navbar won't display horizontally?导航栏不会水平显示?
【发布时间】:2016-09-23 16:27:54
【问题描述】:

my sad navbar here 我无法让导航栏水平显示,并尝试将浮动、位置和 display:inline-block 搞乱。它是 ul 格式,中间有 3 个带有下拉菜单的按钮。如果您发现我做错了什么,请告诉我,谢谢!

    /* NAVIGATION BAR */
#nav {
    width: 1100px;
    height: 200px;
    float: left;
    font-weight: bold;
    font-size: 24px;
    float: left;
    }

# nav button {
    display: inline-block;
    position: relative;
    width: 100%;
    float: left;
    }

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    width: 100%
    background-color: white;
    color: rgb(36,60,131);
    font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
    display: inline-block;
    }

li {
    float: left;
    }

/* nav bar hover */
li a {
    display: inline-block;
    color: #000;c
    text-align: center;
    padding: 8px 16px;
    background-color: white;
    color: rgb(36,60,131);
    text-decoration: none;
    font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
    float: left;
    border-left: 1px solid #bbb;
    border-right: 1px solid #bbb;
    }

/* changes link color on hover */
li a:hover, .dropdown:hover .dropbtn {
    background-color: rgb(36,60,131);
    color: white;
    }

/* highlights active page on nav bar */
.active {
    background-color: rgb(36,60,131);
    color: white;
    }

li.dropdown {
    display: inline-block;
    }

/* dropdown menu */
.dropbtn {
    display: inline-block;
    background-color: white;
    text-align: center;
    padding: 8px 16px;
    color: rgb(36,60,131);
    font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
    text-decoration: none;
    font-size: 24px;
    border: none;
    font-weight: bold;
    border-left: 1px solid #bbb;
    border-right: 1px solid #bbb;
    }

.dropdown-content {
    display: none;
    position: absolute;
    background-color: rgb(36,60,131);
    color: white;
    min-width: 160px;
    }

.dropdown-content a {
    padding: 8px 16px;
    background-color: white;
    color: rgb(36,60,131);
    text-decoration: none;
    display: block;
    text-align: left;
    }

.dropdown-content a:hover {
    background-color: rgb(36,60,131);
    color: white;
    }

.dropdown:hover .dropdown-content {
    display: block;
    }


and my HTML is here

<!DOCTYPE html>
<head>
    <link rel="stylesheet" type="text/css" href="css/saferide.css">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">

</head>

<div id="nav">
    <ul>
        <li style="float:left"><a href="index.html">home</a></li>
        <div class="dropdown">
            <button class="dropbtn">about us</button>
            <div class="dropdown-content">
                <a href="history.html">safe ride history</a>
                <a href="#">meet our dispatchers</a>
                <a href="#">core staff</a>
            </div>
            </div>
        <div class="dropdown">
            <button class="dropbtn">how we operate</button>
            <div class="dropdown-content">
                <a href="#">rules &amp; policies</a>
                <a href="#">how to schedule a ride</a>
                <a href="#">safe ride boundaries</a>
            </div>
            </div>
        <div class="dropdown">
            <button class="dropbtn">get involved</button>
            <div class="dropdown-content">
                <a href="#">volunteer or intern</a>
                <a href="#">resources</a>
            </div>
        </div>
        <li><a href="contact.html">contact us</a></li>
    </ul>
</div>

【问题讨论】:

    标签: html css navbar


    【解决方案1】:

    给你:https://jsfiddle.net/2uj2u5g5/

    您忘记将; 添加到width:100% 之一,因此CSS 无法正常工作。您还做了li.dropdown,而您的下拉类不在li 内,所以这也不起作用。我强烈建议您在导航面板中添加更多结构并牢记 HTML 标准。请关注一些像这样的知名文章:http://www.w3schools.com/css/css_navbar.asp

    祝你好运。

    【讨论】:

      猜你喜欢
      • 2017-05-30
      • 1970-01-01
      • 2017-07-09
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 2019-03-02
      相关资源
      最近更新 更多