I have done this fiddle, where I’m trying to solve it with CSS, but it doesn’t seem to work out.
The thing I want to do is have the paragraph beeing vertically centered. The parents height depends on the height of the image, which is responsive. I have tried table, table-cell but it is not working out for me.
I guess you could use javascript to estimate the height of the paragraph then put margin-top: - half that amount, the thing is I don’t know how to do this.
hehe hmm I think there is a slight difference between my topics at least=) Considering i couldn’t solve this issue with the solution for the other centering problem=)
Thanks for your solution btw, BUT the image and the paragraph has to stay in their separate parents, So I can’t inline them I guess?
I believe I solved all your other centering questions that I contributed in. You haven’t yet replied to the last answer I gave in one of your other threads.
Thanks for your solution btw, BUT the image and the paragraph has to stay in their separate parents, So I can’t inline them I guess?
No difference. Just apply the styles to the parent of those two elements instead.
e.g.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body, html, p {
padding: 0;
margin: 0;
}
.parent {
width: 100%;
background: #eee;
overflow: hidden;
}
.child {
width: 49%;
vertical-align:middle;
display:inline-block;
*display:inline;/* ie7 hack for inline-block remove if not supported*/
*zoom:1.0;/* ie7 hack for inline-block remove if not supported*/
}
.child img{width:100%;height:auto}
.parent p {margin:5px;}
</style>
</head>
<body>
<div class="parent">
<div class="child"><img src="http://placehold.it/350x150"></div>
<div class="child"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et odio est. Suspendisse pulvinar blandit urna, a adipiscing est porttitor nec. </p></div>
</div>
</body>
</html>
or with display:table-cell.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
body, html, p {
padding: 0;
margin: 0;
}
.parent {
width: 100%;
background: #eee;
overflow: hidden;
}
.child {
width: 49%;
vertical-align:middle;
display:table-cell;
*display:inline;/* ie7 hack for inline-block remove if not supported*/
*zoom:1.0;/* ie7 hack for inline-block remove if not supported*/
}
.child img{width:100%;height:auto}
.parent p {margin:5px;}
</style>
</head>
<body>
<div class="parent">
<div class="child"><img src="http://placehold.it/350x150"></div>
<div class="child"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et odio est. Suspendisse pulvinar blandit urna, a adipiscing est porttitor nec. </p></div>
</div>
</body>
</html>