简体   繁体   中英

Centered Element

I Am Started Learning HTML And CSS And I Wanna Know: How i Could Make This links Home And About And Contact Centered In Header

Html:

 <body>
    <header>
        
        <h1><a href="#">HBT</a> </h1>
        <nav>

            
                <a href="./home.html">Home</a>
                <a href="./about.html">About</a>
                <a href="./contact.html">Contact</a>
            
        </nav>
    </header>
</body>

Style:


*{
    margin:0;
    
}

header{
    background-color:#000;
overflow: hidden;
height:90px;
}

header h1{
    float :left;
}
header nav a{
    float :right;
    padding:10px;
} 

Since <a> is an inline element, you will need to convert that into block element. Further, padding isn't your option here because. You will need 100% height.

a {
    color: #fff;
    display: block;
    height: 100%;
    background: red;
}

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