CSS两种水平垂直居中示例介绍_ Div+Css教程-查字典教程网
CSS两种水平垂直居中示例介绍
CSS两种水平垂直居中示例介绍
发布时间:2017-01-07 来源:查字典编辑
摘要:第一种:将固定大小的div框相对窗口水平垂直居中,改变浏览器窗口大小时,依然保持水平垂直居中;水平垂直居中.out{width:0px;he...

第一种:将固定大小的div框相对窗口水平垂直居中,改变浏览器窗口大小时,依然保持水平垂直居中;

<!doctype html>

<html lang="en">

<head>

<title>水平垂直居中</title>

<meta charset="utf-8">

<style type="text/css">

.out{width: 0px;

height: 0px;

position: absolute;

left: 50%;

top: 50%;

}

.in{height: 300px;

width: 300px;

position: absolute;

left: -150px;

top: -150px;

background-color: #999;

}

</style>

</head>

<body>

<div>

<div></div>

</div>

</body>

</html>

第二种:让一个自适应大小的div相对浏览器窗口水平垂直居中

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>自适应剧中</title>

<style type="text/css">

.middle{

height: 300px;

width: 300px;

border: 1px solid;

display: table-cell;

text-align: center;

vertical-align: middle;

}

.in{

background-color: red;

height: auto;

width: auto;

min-width: 0px;

min-height: 0px;

display: inline;

}

</style>

</head>

<body>

<div>

<div>内容自适应水平垂直居中</div>

</div>

</body>

</html>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新 Div+Css教程学习
    热门 Div+Css教程学习
    网页设计子分类