promotion image of download ymail app
Promoted

Why is my simple html and css code not working?

I want to have a plain text with a big background color and then align the text inside in the middle vertically. I tried the vertical align middle and it's not working. Can you please look at my code and tell me why it's not working?

HTML:

<div id="txtinbox">

<span class="intxt">this is a text centered in the middle of a box</span>

</div>

CSS:

#txtinbox {

background-color:tomato;

text-align:center;

height:80px;

margin-left:5em;

margin-right:5em;

}

span.intxt {

color:blue;

vertical-align:middle;

}

The text is not aligned vertically in the middle of the background color. Why?

1 Answer

Relevance
  • Anonymous
    3 days ago
    Favorite Answer

    try adding line-height into #txtinbox

    #txtinbox {

      line-height: 80px;

    }

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.