I want to make 2 divs beside each other to be aligned on the same horizontal line WITHOUT FLOATs
I've tried Position:relative ,, but no luck
See the example below : http://jsfiddle.net/XVzLK
<div style="width:200px;height:100px;background:#ccc;">
<div style="background:Blue; float:left; width:100px; height:100px;"></div>
<div style="background:red; float:left; margin-left:100px; width:100px; height:100px;"></div>
</div>
From the link above, I need the red box to be on the same line of blue box with no space below ..
EDIT : I want the red box to stay outside the container gray box (just as it is) thanks
Use Position properties when your height and width are fixed
If you want your divs on same line without floats you can use
display: inline-block;
and give some negative margin value to your div because inline-block contains some margin between them.See this fiddle
As your Edited question I have submitted another fiddle here
Or you could simply add
margin-top: -100px;
to your fiddle.Relative
withinline-block
displayEDIT
The code below also works fine. Here, because of comments, the line feed is commented out and ignored.
If you want to avoid
float
,position
andinline-block
, here's a margin-only solution:Updated fiddle
http://jsfiddle.net/XVzLK/22/
Setting position relative on the coloured divs makes their position relative to where they would have been in the document. I think what you wanted to do is make the containing div position relative, and the children divs positioned absolutely within it. I'm assuming that "with now space below" meant "with no space below"
There is a tutorial here that may be of use: http://www.barelyfitz.com/screencast/html-training/css/positioning/