手机
当前位置:查字典教程网 >网页设计 > Div+Css教程 >使用css实现div垂直居中的示例
使用css实现div垂直居中的示例
摘要:CSS实现div居中/*外层div居中*/#main{position:absolute;/*极为重要*/background-color:...

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>CSS实现div居中</title>

<style>

/*外层div居中*/

#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;

/*div内部文字居中*/

text-align: center;

line-height:100px; /*行间距和div宽度相同*/

}

</style>

<body>

<div id="main">

<div id="content">

Sun

</div>

</div>

</body>

</html>

【使用css实现div垂直居中的示例】相关文章:

css实现文字层浮在图片之上示例代码

css控制div中元素居中的示例

DIV垂直居中的办法

任意图片实现垂直居中的三种方法(兼容性还不错)

使用css3制作登录表单的步骤

css控制div不能居中的解决办法

用css样式表实现首字大写

用CSS实现垂直居中的3种方法

css实现body背景图片水平垂直居中方法

css中元素水平垂直居中4种方法介绍

精品推荐
分类导航