So I have been working on my first website, and I'm having lots of fun doing it.
However, I have found it very difficult to achieve centering a paragraph (spanning more than one line) vertically and horizontally inside of it's div container.
The div has a proportional width (96%), and it is not set by pixels. Also, the paragraph has a set amount of padding (ex: 20px top and bottom).
Is there a trick to center vertically and horizontally in this situation?
Thanks a bunch!
You could have simply used text-align: center; on your div.
From you 2 examples:
a single container inside a sized box:
you can use a pseudo to vertical-align pseudo and inside boxe aside each others DEMO
A single or several boxes inside a sized box:
you can use
display:table-cell;
DEMOSee this fiddle - http://jsfiddle.net/zv2Pu/1/
I have centered
p
both horizontally and vertically within thediv
container.Hope this helps!