简体   繁体   中英

Having some trouble centering the logo inside the div that will hold my menu

I have the following HTML:

<div id="main-menu">
    <a id="main-menu-logo" href="index.html">
        <span style="color:white;">MY NAME</span>
    </a>
    <div id="main-menu-items">
        ......
    </div>
</div>

And the following CSS:

#main-menu{
    margin-left: 1px;
    float: left;
    height: 40px;   
    border: 2px solid black;
    background-color: rgba(0, 0, 0, 0.8);
    width: 120px;
}

#main-menu-items{
    display: none;
}

#main-menu-logo {   
    line-height: 40px;
    display: inline-block;
    padding-left: 10px;
    padding-right: 10px;
    text-align: center; 
}

How can I get the main-menu-logo to be centered inside the main-menu?

Thank you

You can centre using display:table and margin.

#main-menu-logo {   
    line-height: 40px;
    display: inline-block;
    margin: 0 auto;
    display: table;
}

More info here: How to horizontally center a <div> in another <div>?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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