简体   繁体   中英

Why is text not positioned properly within list element?

This is what the problem looks like:

在此处输入图片说明

Here is the mark up:

                    <nav class="padding_bottom">
                        <ul>
                            <li><a class="selected" href="#">Home</a></li>
                            <li><a href="#">Music</a></li>
                            <li><a href="#">Contact</a></li>
                        </ul>
                    </nav>

And the styling:

nav {
    height: 100%;
}

nav li {
    font-size: 3em;
    letter-spacing: -4.5px;
    text-transform: uppercase;
}

nav li:nth-child(2), 
nav li:nth-child(3) {
    margin-left: .25em;
}

nav a {
    color: #dddddd;
}

nav a:hover, .selected {
    color: black;
}

I can;t figure out why this is happening. I've played around wiht a lot of the styling elements to see if anything changed, but the problem persisted.

@MichaelPitluk:

It's caused by the -ve letter-spacing , if you remove it then the background color extends as expected. You may just need to add some padding or margin, whichever works best for your situation, to the <a> elements.

Example Fiddle

Try this please :

nav li {
    font-size: 3em;
    letter-spacing: -4.5px;
    text-transform: uppercase;
    padding: 10px;
    list-style:inside none;
    background-color:#CCC;
    display:inline-block;
}

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