css实现d窗上下左右居中且背景透明锁定窗口效果

css实现d窗上下左右居中且背景透明锁定窗口效果,第1张

css实现d窗上下左右居中且背景透明锁定窗口效果

有一种简单的css方法实现点击之后的d出框上下左右居中且附加灰色透明遮罩锁定窗口清除滚动条

html代码

<div class="box">
	<div class="boxs">
	    <!-- 白色d窗 -->
	</div>
</div>

css代码

html, body {
     width: 100%;
     height: 100%;
 }
 .box {
     display: none;
     width: 100%;
     height: 100%;
     position: fixed;
     left:0;
     top:0;
     background-color:rgba(0,0,0,0.5);
 }
 .boxs {
     width: 400px;
     height: 300px;
     background: #fff;
     box-shadow: 1px 7px 18px 0px rgba(84, 115, 128, 0.11);
     border-radius: 4px;
     cursor: pointer;
     position: absolute;
     left: 50%;
     top: 50%;
     margin-top: -150px;
     margin-left: -200px;
 }

使用position:fixed固定透明背景元素,可以有效锁定窗口防止滚动条滚动,且可以利用定位在父元素内部实现子元素上下左右居中。


至于d出 *** 作只需把点击事件和外层div的display属性的none以及block联动起来即可。


到此这篇关于css实现d窗上下左右居中且背景透明锁定窗口的文章就介绍到这了,更多相关cssd窗居中背景透明锁定窗口内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/615680.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-14
下一篇 2022-04-14

发表评论

登录后才能评论

评论列表(0条)

保存