gpt4 book ai didi

css - 移动丑陋的模态

转载 作者:太空宇宙 更新时间:2023-11-04 14:17:18 24 4
gpt4 key购买 nike

美好的一天,

我有这样的 .modal CSS 代码

.modal
{
position: fixed;
top: 10%;
left: 50%;
z-index: 1050;
width: 560px;
margin-left: -280px;
background-color: #fff;
border: 1px solid #999;
border: 1px solid rgba(0,0,0,0.3);
*border: 1px solid #999;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 3px 7px rgba(0,0,0,0.3);
-moz-box-shadow: 0 3px 7px rgba(0,0,0,0.3);
box-shadow: 0 3px 7px rgba(0,0,0,0.3);
-webkit-background-clip: padding-box;
-moz-background-clip: padding-box;
background-clip: padding-box;
outline: 0;
}

但是在手机上是这样的

enter image description here

我需要一种调整模式大小的方法。

最佳答案

我想出了两种方法来存档:

1) 使用media query

Live demo

.modal {
/* original code */
}
@media (max-width:622px) {
.modal {
left:5%;
margin-left:0px;
width:90%;
}
}

622px560px/0.9的结果;

2) 使用百分比和 max- CSS 属性

Live demo

<div class="modal-wrapper"><div class="modal">Some text</div></div>
.modal-wrapper {
position:fixed;
top:10%;
left:50%;
width:560px;
max-width:90%;
overflow:visible;
z-index:1050;
}
.modal {
position: relative;
width: 100%;
margin-left:-50%;
/* background colors and stuffs */
}

方法 1 对您的代码所做的更改最少,但是如果您改变了对 560px 限制的想法,您还必须注意媒体查询 max-width值;

方法 2 对您的代码进行了相当大的更改,但是如果您改变了对 560px 限制的想法,您应该能够快速更改它(甚至是 with JS )。

关于css - 移动丑陋的模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20235874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com