I have a problem with css. I have (parent) div and inside, another (child) div. I want align inner (child) div to the TOP-RIGHT corner of the (parent) div.
<div id="parent">
<div id="child">
</div>
</div>
I need something like:
#child{
position: absolute;
top: 0;
right 0;
}
but this css code puts my "child" div into top-right corner of body element!
Please help, TNX! :)
Your parent container needs to be set as relative positioning.
#parent {position:relative}
#child {position:absolute; top:0; right:0}
将#parent的样式设置为position: relative
#parent{
background-color:#FF0000;
position: absolute;
height:200px;
width:500px;
}
#child{
background-color: #3300FF;
position: absolute;
height:50px;
width:100px;
top: 0;
right:0;
}
<div id="parent" >div1
<div id="child">DIV2
</div>
</div>
#child{
float:right;
}
<div id="parent" >Parent
<div id="child">Child
</div>
<div style="clear:both;"></div>
</div>
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.