Search code examples
csshtmlcss-floatpositioning

CSS: Floating IMGs inside floating divs


I encountered a problem and didn't find a solution for this. I'm pretty confused because I thought this was a very simple requirement.

There are the following elements:

  • a surrounding div#wrapper
  • div#A, floating left and fixed width
  • div#B, floating left (right of #A) and dynamic width
  • Inside of div#B there are plenty of images, floating left and fixed width (and height).

Depending on the screen resolution there should be 1, 2, 3, n columns of images on the right part of the screen (next to div#A). Instead of this, container #B is aligned below container #A and uses the full window width.

My alternative attempt was giving #B a float:right and a margin-left (which was greater than the width of #A), but that also didn't work.

I would like to avoid absolute positioning because the height of the surrounding wrapper should increase with its content.

To visualize what I'm talking about, I made the following diagram: http://abload.de/img/rezeptbilder1k8lsr.png

Many thanks in advance!


Solution

  • this is happening because..you are having dynamic width for your div#B...ans as there are plenty of images and they are aligned next to each other...so eventually div#B grows to 100% width...when it has 100% width then it arrives under the div#A.because 100% + div#A's width cant fit together in a 100% wide screen..you understand???

    1st solution :: you may use width:calc(100% - div#a's width).it will give div#b a width equals to remaining free space besides div#a

    or you may use overflow:hidden in your div#B...now at first this div will grow eventually to take the width of remaining free space with a single row of images and once it has 100% width it will create another row of images..but for this your wrapper must have fixed with with **overflow:auto;** also..overflow:auto; in wrapper will introduce scroll bar when combined with of div A and B is greater than 100%

    EDIT :: CHECK BROWSER SUPPORTS FOR CALC() HERE

    note::if you provide us your try our suggestion will be more appropriate