Skip to content Skip to sidebar Skip to footer

Float 2 Elements Side By Side Inside A Container Div

This is supposed to be an easy task, but I've been looking at it for the last 30 minutes and couldn't figure it out. Here is the html code;
<

Solution 1:

By default, <h3> elements have a top and bottom margin. You should remove them using margin: 0:

<div style="width: 250px;">
    <img style="float: left; width: 20px;" src="public/_images/ok_kutu.jpg" alt="kutu" /> 
    <h3 style="float: left; width: 50px; color: #FFF; font-size: 18px;margin:0">Jobs</h3>
    <div style="clear: left;"></div>
</div>

Also, maybe look into using external CSS, rather than placing all of your style information inline. It will be much easier to maintain in the long run...

Please see this jsFiddle demo


Solution 2:

You can use:

display: inline-block;

Instead of:

float: left;

And everything will work out :)

Here's the demo (change the image): http://jsfiddle.net/JjTfy/2/

P.S - You should really use separate CSS stylesheets instead of inline styling.


Post a Comment for "Float 2 Elements Side By Side Inside A Container Div"