Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position a div container on the right side

Tags:

css

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:

enter image description here

Any idea how to achieve this using css?

like image 710
UpCat Avatar asked Mar 07 '11 16:03

UpCat


People also ask

How do you fix a div on the right side?

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.

How do you display the element on the right side?

position: Absolute; top: 20px; right 0px; That would work but if you adjust the browser the text moves with it.


2 Answers

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>​ 
like image 86
JohnP Avatar answered Sep 20 '22 23:09

JohnP


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>​ 
like image 41
Grms Avatar answered Sep 17 '22 23:09

Grms