Home  >  Article  >  Web Front-end  >  CSS如何让文字居于div的底部_html/css_WEB-ITnose

CSS如何让文字居于div的底部_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:31:142915browse

CSS如何让文字居于div的底部:
让文字在div中垂直居中比较简单,只要将line-height的属性值设置为div的高度即可,但是让文字在div的底部显示就没有那么简单了,下面对此做一下简单的介绍,代码实例如下:

 

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">#box {  height:300px;  width:300px;  border:1px solid #333333;  text-align:center;  position:relative}#box p {  position:absolute;  bottom:0px;  padding:0px;  margin:0px}</style></head><body><div id="box">  <p>蚂蚁部落欢迎您</p></div></body></html>

 

以上代码实现了我们的功能,就是将p元素设置为绝对定位,父元素设置为相对定位,那么定位参考对象就是父元素,然后将bottom属性值设置为0px,这样就定位div的底部了。

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

更多内容可以参阅: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