首页 > 其他 > 详细

vh属性-- 一个永远垂直居中的弹出框

时间:2015-08-19 19:50:35      阅读:259      评论:0      收藏:0      [点我收藏+]

 

下面的demo,无论浏览器大小如何改变,滚动条是否滚动,弹出框永远水平垂直居中

 

 

<html>
<head>
	<title></title>
</head>
<style type="text/css">
.wrap{
	  position: absolute;
	  top:0;
	  width: 100%;
	  height: 100%;
	  background-color: #CEC6C6;
	  opacity: 0.75;
	  z-index: 999;
	}

.alertbox{
  position: fixed; /*这是关键*/
  z-index: 1000;
  width: 270px;
  height:163px;
  padding: 20px 0;
  background-color: #fff;
  text-align: center;
  top:50vh;
  margin-top: -100px;
  left: 50%;
  margin-left: -135px;
  border-radius: 5px;
}
  .alertbox h2{
    font-size: 17px;
    color: #030303;
    margin: 0 13px;
  }
  .alertbox p{
    font-size: 13px;
    color: #000;
    margin:8px 13px 40px;
  }
  .alertbox .ok-button{
    position: absolute;
    bottom: 20px;
    width: 100%;
    color:#037AFF;
    font-size: 17px;
    height: 30px;
    line-height: 40px;
    border-top:1px solid #B7B7B7;
    cursor: pointer;
  }

</style>
<body>
	<div class=‘wrap-box‘>
		<div class=‘wrap‘></div>
		<div class=‘alertbox‘><h2>hello</h2>
			<p>hello</p>
			<div class=‘ok-button‘>OK</div>
		</div>
	</div>
</body>
</html>

  

vh属性-- 一个永远垂直居中的弹出框

原文:http://www.cnblogs.com/yzg1/p/4742963.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!