I want to develop some kind of utility bar. I can position each element in this bar side by side using float:left;
But I want the second element to be positioned at the very right of the bar. This is hard for me because the width of the bar is not static.
Have a look at my demo: http://jsfiddle.net/x5vyC/2/
It should look like this:
Any idea how to achieve this using css?
To align a div with fixed position on the right side, we set the right CSS property of the div we want to align to the right side. to add a div with the class test . Then in the CSS code, we select the elements with class test , and set the right property on it.
position: Absolute; top: 20px; right 0px; That would work but if you adjust the browser the text moves with it.
Is this what you wanted? - http://jsfiddle.net/jomanlk/x5vyC/3/
Floats on both sides now
#wrapper{ background:red; overflow:auto; } #c1{ float:left; background:blue; } #c2{ background:green; float:right; } <div id="wrapper"> <div id="c1">con1</div> <div id="c2">con2</div> </div>
Just wanna update this for beginners now you should definitly use flexbox to do that, it's more appropriate and work for responsive try this : http://jsfiddle.net/x5vyC/3957/
#wrapper{ display:flex; justify-content:space-between; background:red; } #c1{ background:blue; } #c2{ background:green; } <div id="wrapper"> <div id="c1">con1</div> <div id="c2">con2</div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With