>  기사  >  웹 프론트엔드  >  div垂直水平居中代码实例_html/css_WEB-ITnose

div垂直水平居中代码实例_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:29:521361검색

div垂直水平居中代码实例:
本章节分享一段代码实例,它演示了如何让div实现全屏垂直水平居中和指定元素的内容垂直水平居中。
代码实例如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">#main{  position:absolute;  background-color: blue;  width:400px;  height:200px;  left:50%;  top:50%;  margin-left:-200px;  margin-top:-100px;  border:1px solid #00F;}#content{  position:absolute;  background-color:yellow;  width:200px;  height:100px;  left:50%;  top:50%;  margin-left:-100px;  margin-top:-50px;}</style><body><div id="main">  <div id="content"></div></div></body></html>

以上代码实现了我们的要求,能够实现居中效果,代码比较简单,就是基本的逻辑问题。

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

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.