CSS level 2 doesn't have a property for centering things vertically. There will probably be one in CSS level 3. But even in CSS2 you can center blocks vertically, by combining a few properties. The trick is to specify that the outer block is to be formatted as a table cell, because the contents of a table cell can be centered vertically.
The example below centers a paragraph inside a block that has a certain given height. A separate example shows a paragraph that is centered vertically in the browser window, because it is inside a block that is absolutely positioned and as tall as the window.
I can get the above to align the first line of text to align vertically-middle, but the first line of text aligns vertically, but it doesn't shit up when more lines are added.
i'm going from being curious to pulling my hair out...you know the feeling :?
<div class=\"contain\"> <img src=\"images/newprofiles/image.jpg\" /> <p>Line of text one<br /> Line of text two<br /> Line of text three<br /> </p> </div>
I've run into this problem multiple times and always give up and take the long, more manual way out. I would LOVE to solve this for once and for all.
I'm trying to horizontally align an image and text next to each other....no problem there.
I would like the text to align middle vertically, regardless of how many lines of text there are. Not so easy.
http://i762.photobucket.com/albums/xx262/ontheellipse/test.jpg
Is there an accepted way to do this?
http://www.w3schools.com/css/css_text.asp
.divname p {vertical-align:middle;
}
HTML
I don't think you'll be able to use multiple "<p>" tags and have it work, but I haven't tried it.
Doc, unfortunately, that doesn't work.
http://i762.photobucket.com/albums/xx262/ontheellipse/photo2.gif
the css
.contain {
background-color: blue;
}
.contain img {
float:left;
margin-right:10px;
}
.contain p {
vertical-align:middle;
}
http://www.w3.org/Style/Examples/007/center#vertical
I don't think so...just suggesting is more than appreciated.
Thanks for the above, I'm going to give it a shot in the morning.
I can get the above to align the first line of text to align vertically-middle, but the first line of text aligns vertically, but it doesn't shit up when more lines are added.
i'm going from being curious to pulling my hair out...you know the feeling :?
http://i762.photobucket.com/albums/xx262/ontheellipse/text.gif
.contain {
background-color: blue;
display: table-cell;
height:60px;
vertical-align: middle;
width:500px;
}
.contain img {
float:left;
}
the top line is starting at vertical-middle, but adding lines of text is dropping under. working would look like
http://i762.photobucket.com/albums/xx262/ontheellipse/working.gif
And maybe float the image left.
thought you were onto something there!