Jump to content

Put two DIVs side by side while keeping the image vertically centered


Rain Lover
 Share

Recommended Posts

Hi, Sample:

<!DOCTYPE html><html><head><title></title><style type="text/css">#left {display:table-cell; width:448px; height:336px; vertical-align:middle; background:black;}#left img {display:block; margin:0 auto;}#right {width:97px; height:326px; padding:5px; overflow-x:hidden; overflow-y:auto; background:black;}</style></head><body><div id="left"><img src="http://dl.dropbox.com/u/4017788/Labs/image2.jpg" alt=""></div><div id="right">    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a></div></body></html>

If I use div {float:left;}, the large image won't be vertically centered any more. What's the solution? Many thanks in advance!Mike

  • Like 1
Link to comment
Share on other sites

<!DOCTYPE html><html><head><title></title><style type="text/css">#left {display:table-cell; width:448px; height:336px; vertical-align:middle; background:black;}#left img {display:block; margin:0 auto;}#right {width:97px; height:326px; padding:5px; overflow-x:hidden; overflow-y:auto; background:black;}.floatLeft {float:left;}</style></head><body><div class="floatLeft"><div id="left"><img src="http://dl.dropbox.com/u/4017788/Labs/image2.jpg" alt=""></div></div><div id="right">    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb2.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb3.jpg" alt=""></a>    <a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a></div></body></html>

There you go :)You just need to surround the table-cell div with another div that floats left. That way it doesn't interfere with the picture. ~Krewe

Link to comment
Share on other sites

You just need to surround the table-cell div with another div that floats left. That way it doesn't interfere with the picture.
That's what I thought at first and wondered if there was a way to achieve what I'm after without adding another HTML element. Thanks anyway!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...