简体   繁体   中英

Place div to bottom right corner

Cant figure out why my div is not in the bottom right corner of my row.

<div class="row">
<div id="col-xs-4">
  <p>pplplplplp</p>
</div>
<div id="col-md-8 pull-right">
  <p>pplplplplp</p>
</div>
<div id="bottomrightcontainer">
  <p>pplplplplp</p>
</div>
</div>

#bottomrightcontainer{
    background-color: white;
    border: 2px solid white;
    border-radius: 2px;
    z-index: 1;

    position: absolute;
    width: 17%;
    height: 29%;
    right: 0px;
    bottom: 0px;
}

This places it to the bottom of the window not the row that is its parent.

position: absolute; as you want it to work needs the parent to be position: relative;

http://jsfiddle.net/5uodkb1u/

.row {
    position: relative;
}

You were just missing position:relative;

This is because absolute is based on the closest relative parent. If no parents are relative, then absolute is based on the browser window.

HTML

<div class="row">
<div id="left">
  <p>pplplplplp</p>
</div>
<div id="right">
  <p>pplplplplp</p>
</div>
<div id="bottomrightcontainer">
  <p>pplplplplp</p>
</div>
</div>

CSS

#bottomrightcontainer{
    background-color: blue;
    border: 2px solid red;
    border-radius: 2px;
    z-index: 1;
    position: absolute;
    width: 17%;
    height: 29%;
    right: 0px;
    bottom: 0px;
}

.row{
    border: 2px solid green;
    position:relative;
}

http://jsfiddle.net/cg8bgvoz/

Adding position: relative to the parent div should work:

JSFiddle: http://jsfiddle.net/ABr/Lxwqkvav/

In the code above bottomrightcontainer is a direct child of the body. It would be at the bottom-right of the body. Then also make it's position relative instead of absolute

You haven't specified css for class row , which is your parent class. So, try to add

.row
{
position: relative;
}

You can do this with html, and css . No javascript required, also no jquery and other complex language required for completing the job . See here: http://goo.gl/PnWvUl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM