简体   繁体   English

我如何得到我的 <nav> 栏始终使用CSS3始终位于页面中心?

[英]How do I get my <nav> bar to be centered in the page at all times using CSS3?

How do I get my bar to be centered in the page at all times? 如何使我的栏始终处于页面中心?

And how do I get the color to stretch across as well? 以及如何使颜色也能延伸? (I know I'll need to change the background color of list item, but nothing else seems to work). (我知道我需要更改列表项的背景颜色,但似乎没有其他效果)。

Here is my CSS code: 这是我的CSS代码:

  #nav {font-family: journalregular; 
     width: 90%;
     box-shadow: 0px 7px 22px -6px rgba(0,0,0,0.75);}


#nav ul {
        list-style: none;
        padding: 0;
        margin: 0;  
        background:#ffffff; 
    }

    #nav a {
        font-weight: bold;
        font-size: 250%;
        color: black;
        text-decoration: none;
        cursor: default;
    }

    #nav li li a {
        display: block;
        font-weight: normal;
        font-size: 180%;
        font-weight: bold;
        color: black;
        padding: 10px 10px;
    }

    #nav li li a:hover {cursor:pointer;
                    background: pink;}

    #nav li {
        display: inline-table;
        position: relative;
        width: 10em;
        text-align: center;
        cursor: default;
        background-color: #DEB887;
        /*border: 1px solid #7d6340;
        border-width: 0px 0px 1px 0px;*/
    }

    #nav li ul{
        position: absolute;
        top: 100%;
        width:10em;
        font-weight: normal;
        padding: 0.5em 0 1em 0;
        border: solid 1px #DEB887;
    }

    #nav li>ul {
        top: auto;
        left: auto;
        display: none;
        opacity: 0;
        transition: display .5s;
    }

    #nav li li {
        display: block;
        float: none;
        background-color: white;
        border: 0;
    }

    #nav li:hover > ul{
        display: block;
        opacity: 1;
    }

a{text-decoration: none;}

And my HTML CODE: 还有我的HTML代码:

<link rel="stylesheet" href="css/styles.css">

<nav id="nav">
    <ul>        
        <li>
            <a href="#">Geography</a>
        </li>

        <li>
            <a class="ambMenu" href="#">Ambience</a>
                <ul>
                    <li><a href="#">House</a></li>
                    <li><a href="#">1</a></li>
                    <li><a href="#">2</a></li>
                    <li><a href="#">3</a></li>
                </ul>
        </li>

        <li>
            <a href="#">Pets</a>
                <ul>
                    <li><a href="#">1</a></li>
                    <li><a href="#">2</a></li>
                </ul>
        </li>

        <li>
            <a href="#">Food</a>
                <ul>
                    <li><a href="#">1</a></li>
                    <li><a href="#">2</a></li>
                </ul>
        </li>
    </ul>
</nav>

Use this: 用这个:

.center {
    margin-left: auto;
    margin-right: auto;
    width: 70%;
    background-color: #b0e0e6;
}

It may help. 这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM