Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to top align two words with different font sizes the same line?

Tags:

html

css

I need to display two lines of text with different font size, one after another, so that their top lines were at the same vertical position, i.e.:

I tried to use vertical-align: top, but no luck. Instead of expected result I have this:

Is there some standard way to achieve the desired result?

Here is my HTML:

<div id="container">
    <span>TEXT</span> TEXT
</div>

and CSS:

#container {
    font-size: 30px;
}

#container span {
    font-size: 16px;
    vertical-align: top;
}
like image 708
lazyhammer Avatar asked Mar 09 '12 20:03

lazyhammer


People also ask

How do I align two words on the same line in HTML?

Use a <span> with float: left for the left word, and another <span> with float: right for the right word. There are other alignment techniques as well, but I don't think it's possible without separating the words into their own elements. Show activity on this post.


1 Answers

One way would be:

#container span {
    position: relative;
    top: 2px;
    }

Adjust the 2px to suit.

like image 80
Turnip Avatar answered Sep 21 '22 22:09

Turnip