Position a div container on the right side

前端 未结 5 1903
粉色の甜心
粉色の甜心 2020-12-25 11:33

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 p

相关标签:
5条回答
  • 2020-12-25 11:49

    This works for me.

    <div style="position: relative;width:100%;">
        <div style="position:absolute;left:0px;background-color:red;width:25%;height:100px;">
          This will be on the left
        </div>
    
        <div style="position:absolute;right:0px;background-color:blue;width:25%;height:100px;">
          This will be on the right
        </div>
    </div>
    
    0 讨论(0)
  • 2020-12-25 11:54

    if you don't want to use float

    <div style="text-align:right; margin:0px auto 0px auto;">
    <p> Hello </p>
    </div>
      <div style="">
    <p> Hello </p>
    </div>
    
    0 讨论(0)
  • 2020-12-25 12:00

    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>​
    
    0 讨论(0)
  • 2020-12-25 12:10
    • Use float: right to.. float the second column to the.. right.
    • Use overflow: hidden to clear the floats so that the background color I just put in will be visible.

    Live Demo

    #wrapper{
        background:#000;
        overflow: hidden
    }
    #c1 {
       float:left;
       background:red;
    }
    #c2 {
        background:green;
        float: right
    }
    
    0 讨论(0)
  • 2020-12-25 12:14

    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>​
    
    0 讨论(0)
提交回复
热议问题