51

I want to move a particular div more to the right side so that the div in the left gets some more space to display the contents in it.

I tried few things in CSS, but I know I am doing something wrong.

In CSS, I have...

login-box {
    width: 200px;
    margin-left: 50px;
} 
2
  • 5
    "Tried few things in css but i know i am doing something wrong." Feel free to share those things with us so we know what you're talking about. :)
    – aquinas
    Oct 3, 2012 at 14:42
  • 2
    Could you give us your current script so to give you a better answer? It's a very vague question.
    – George
    Oct 3, 2012 at 14:42

5 Answers 5

73

You can use float on that particular div, e.g.

<div style="float:right;">

Float the div you want more space to have to the left as well:

<div style="float:left;">

If all else fails give the div on the right position:absolute and then move it as right as you want it to be.

<div style="position:absolute; left:-500px; top:30px;"> 

etc. Obviously put the style in a seperate stylesheet but this is just a quicker example.

3
  • I am using it. that div is already to the right. I want to push it more to right
    – Bala
    Oct 3, 2012 at 14:44
  • 1
    dont kno wy but <div style="position:absolute; left:-500px; top:30px;"> dint work either
    – Bala
    Oct 3, 2012 at 14:57
  • I use float: right;margin-right: 100px; to have the div on the right end with 100px margin.
    – Timo
    Dec 29, 2022 at 13:23
34

I used margin-left: auto; which is more responsive with horizontal resizing.

2
  • This works perfectly for responsive too, thanks. If you use position:absolute sometimes it doesn't work responsively.
    – Spinstaz
    Oct 21, 2021 at 15:56
  • 2
    for margin-left: auto work a width must be given so that it pushes itself to the right end it can be also achieved with flex and is also responsive display: flex; justify-content: end; and float: right give you desired result also
    – vibhu
    Feb 9, 2022 at 5:38
22

This will do the job:

<div style="position:absolute; right:0;">Hello world</div>

0
1
login-box {
    width: 200px;
    margin-left: auto;
} 
2
  • To make your answer a good answer, please explain why your answer works Sep 6, 2022 at 14:17
  • sure sir, I will try to improve myself and my answer thanks for your time
    – Honnappa
    Sep 8, 2022 at 12:49
1

(this adds as much left margin as there is room for)

div{
display: block;
margin-left: auto;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.