Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text not centering in my li

Demo link

Not sure why my text in the 2nd list isn't getting centered.

enter image description here

The HTML

<div id="the_target">
    <ul>
        <li>Stephen Marston</li>
        <li>Account Exectutive</li>
        <li>The Company</li>
    </ul>
</div>

SASS:

section {
    #the_requestor {
        margin-top: 40px;
        ul { margin-top: 10px; }
        ul li {
            text-align: center;
            line-height: $px20;
        }
        li:first-child {
            font-family: LatoBold;
            font-size: $px30;
            background: cyan;
        }
    }
    #the_target {
        position: relative;
        margin-top: 40px;
        ul { margin-top: 10px; }
        ul li {
            text-align: center;
            line-height: $px20;
        }
        li:first-child{
            font-family: LatoBold;
            font-size: $px30;
            background: cyan;
        }
    }
}

Any thoughts on what could be forcing Stephen Marston to not center?

like image 520
Leon Gaban Avatar asked Aug 29 '13 19:08

Leon Gaban


People also ask

How do I center text in Li?

To just center the text inside an element, use text-align: center; This text is centered.

Why is text-align center not working?

This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.

How do you center text to float?

To center the text using float we can use margin-left or margin-right and make it 50% , like below.

How do you center a Li in HTML?

Just give the list centered text (e.g. ul. nav { text-align: center; } ) and the list items inline-block (e.g. ul. nav li { display: inline-block; } ). If you want to do it with margin for whatever reason, look into width: fit-content; .


2 Answers

There is an element being floated in #mobile-action-area that is interfering. You need to clear this float. There are a variety of ways to do it. Adding overflow: hidden to #mobile-action-area fixes it. You may also try:

#mobile-action-area:after {
    display: table;
    content: "";
    clear: both;
}
like image 80
Explosion Pills Avatar answered Oct 02 '22 19:10

Explosion Pills


You'll need to clear the float before #the_target

   #the_target {
            position: relative;
            margin-top: 40px;
            clear:both;
    }
like image 29
Slavenko Miljic Avatar answered Oct 02 '22 20:10

Slavenko Miljic