Say I have two divs A and B, which are currently aligned side by side. How can I get A to be separated from B by 50px, while still letting A to take up 70% of the remaining space and B the remaining 30%?
EDIT: Accepted the answer a little early before I actually tried. Whoops.
JSFiddles:
Now separated, but now with the second one on a second line?
I believe your selected answer will not work:
http://jsfiddle.net/cNsXh/
edit:
Sorry, the above example was not correct at first. Now it is.
/edit
As you can see,
div #bwill move underdiv #abecausemargin-left(orpadding-left) will be added to the30%. And because we’re mixing percentage with pixel values here, we will not be able to define values that will guarantee to always add up to exactly 100%.You’ll need to use a wrapper for
div #bwhich will have30%width, and not define a width fordiv #b, but definemargin-left. Because adivis a block element it will automatically fill the remaining space inside the wrapper div:http://jsfiddle.net/k7LRz/
This way you will circumvent the CSS < 3 box-model features which oddly enough was defined such that defining a dimension (width / height) will NOT subtract margins and/or paddings and/or border-width.
I believe CSS 3’s box-model will provide more flexible options here. But, admittedly, I’m not sure yet about cross-browser support for these new features.