Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically align two pieces of text with different font-sizes using CSS

At the top of my page I want to have the title of the page aligned to the left of the screen with a short nav menu aligned to the right of the screen. I can achieve this using float but the two elements have different baslines i.e. the baseline of the text appears different. Is there any way to get this to work using css? I have a sample of what I'm trying to do up on jsfiddle http://jsfiddle.net/nBPCG/63/

like image 644
user1284664 Avatar asked Mar 21 '12 23:03

user1284664


People also ask

How do I align text in different sizes?

One thing to remember, if you have different sizes of text that you need to align, is to align it to x-height or baseline. If there is a caps font then align them to baseline or cap-height. And remember NEVER to align horizontally different font sizes fonts on the central line.

How do I center align items vertically in CSS?

To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.


1 Answers

Hi you can use display:inline-block in your h1

or see the Fiddle:- http://jsfiddle.net/nBPCG/101/

like image 66
Shailender Arora Avatar answered Nov 15 '22 00:11

Shailender Arora