Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I vertically centering text inside a responsive box that has a (fluid height) [duplicate]

I am building a responsive website and am using a grid system. The grid boxes of course do not have a set height. they are fluid. The image that is placed within them will define the height ad then it will scale with the available width of the viewport

What I am trying to do is lay text over the image and vertically align the text in the middle of the image.

I have read a ton of posts out there on vertical aligning but none seem to address doing it with a responsive box.

I set up a fiddle using the only the condensed css necessary to replicate my grid system for this example. I am using 2 grey dummy images. I want to lay text over them and align the text vertically. How would this be done? Any ideas? Id prefer to do this only with css unless jquery is absolutely needed but I think css alone can do it.

http://jsfiddle.net/zjDuE/

<div class="grid">
<div class="row">
<div class="c6"><img src="http://dummyimage.com/600x400/cccccc/cccccc.jpg" alt="-" /></div>
<div class="c6"><img src="http://dummyimage.com/600x400/cccccc/cccccc.jpg" alt="-" /></div>
</div>
</div>
like image 438
DC1 Avatar asked Sep 11 '13 22:09

DC1


People also ask

How do I center align text vertically in CSS?

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


1 Answers

I think my codepen could be usefull for you.

http://codepen.io/SzymonDziewonski/pen/gLebo

Try to use vertical-alight with display: table-cell and your center vertical align will work for fluid heights. Good luck :)

Support for table-*

like image 180
Szymon Avatar answered Oct 11 '22 06:10

Szymon