Home  >  Article  >  Web Front-end  >  将子div定位于父div的右下角的代码实例_html/css_WEB-ITnose

将子div定位于父div的右下角的代码实例_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:30:441707browse

将子div定位于父div的右下角的代码实例:
可能在实际应用中,很少有这样的设置,这里分享这段代码的目的是为了让初学者熟悉一下关于定位的应用。
代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">#father{  width:600px;  height:600px;  background:green;  position:relative}#father #children{  width:200px;  height:200px;  background:red;  position:absolute;  right:0;  bottom:0}</style></head><body><div id="father">  <div id="children">蚂蚁部落</div></div></body></html>

代码实现了我们的要求,可以将子元素定位于父元素的右下角,实现原理非常的简单,就是将父元素设置为相对定位,然后将子元素设置为绝对定位,这样子元素的定位参考对象就是这个父元素,然后再讲子元素的right和bottom属性值设置为0即可实现此效果。
相关阅读:
1.绝对定位可以参阅CSS的绝对定位一章节。 
2.定位参考对象可以参阅position绝对定位以哪个对象为参考一章节。 
3.right属性可以参阅CSS的right属性一章节。
4.bottom属性可以参阅CSS的bottom属性一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11768

更多内容可以参阅:http://www.softwhy.com/divcss/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn