模态弹出窗口在移动设备上无法正确显示

Modal PopUp not showing correctly on mobile devices

提问人:Simeon Arsov 提问时间:11/18/2023 更新时间:11/18/2023 访问量:20

问:

模态弹出窗口在某些手机上无法正确显示。窗口在右侧走得太远,无法关闭,因为关闭按钮位于右上角。我移动了中间的 X 按钮,但模态仍然在最右边。在某些 iPhone 上,例如 11,12,但它显示得很完美。所有代码都在下面。任何帮助将不胜感激。谢谢!

错误地显示图像

      
<style>
    .modal-dialog {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;

}

.modal-box{ font-family: 'Quantico', sans-serif; }
.modal-box .show-modal{
background: linear-gradient(#444,#222);
color: #fff;
font-size: 18px;
font-weight: 400;
text-transform: capitalize;
letter-spacing: 1px;
padding: 12px 20px;
margin: 80px auto 0;
border: none;
outline: none;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
display: block;
transition: all 0.3s ease 0s;
}
.modal-box .show-modal:hover,
.modal-box .show-modal:focus{
color: #fff;
outline: none;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
}
.modal-backdrop.in{ opacity: 0; }
.modal-box .modal-dialog{
width: 450px;
margin: 70px auto 0;
}
.modal.fade .modal-dialog{ transform: translateY(-100px); }
.modal.in .modal-dialog{ transform: translate(0); }
.modal-box .modal-dialog .modal-content{
text-align: center;
border: none;
box-shadow: 0 0 10px rgba(0,0,0,0.2);  
}  
.modal-box .modal-dialog .modal-content:before{
content: "";
background: linear-gradient(to right,#FFA678,#FF1B1A);
border-radius: 6px 6px 0 0;
width: 100%;
height: 20px;
display: block;
clear: both;
}
.modal-box .modal-dialog .modal-content .close{
color: #000;
font-size: 50px;
font-weight: 300;
text-align: center;
line-height: 25px;
width: 50px;
height: 35px;
padding-left: 1px;
border-radius: 0 5px 5px 0;
overflow: hidden;
opacity: 1;
position: absolute;
left: auto;
top: 27px;
right: 0px;
z-index: 1;
transition: all 0.3s ease 0s;
}

.modal-box .modal-dialog .modal-content .close:hover{ color: #555; }
.modal-box .modal-dialog .modal-content .close span{
margin: -6px 0 0;
display: block;
}
div.image::before {
content:url(http://motopara.com/images/EVO_17_Popup.jpg);

}
.modal-box .modal-dialog .modal-content .modal-body .title{
color: #000;
font-size: 37px;
font-weight: 500;
letter-spacing: 1px;
display: block;
text-transform: capitalize;
margin: 0 0 20px;
}
.modal-box .modal-dialog .modal-content .modal-body .title::after{
content: "";
background: linear-gradient(to right,#FFA678,#FF0000);
width: 100px;
height: 6px;
margin: 20px auto 0;
border-radius: 10px;
display: block;
clear: both;
}
.modal-box .modal-dialog .modal-content .modal-body .description{
color: #7c0303;
font-size: 20px;
margin: 0 0 30px;
}
.modal-box .modal-dialog .modal-content .modal-body .btn{
color: #FF1B1A;
background: linear-gradient(#444,#222);
font-size: 20px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
padding: 12px 40px;
margin: 0 auto -57px;
border: none;
border-radius: 5px;
display: block;
transition: all 0.6s;
}
.modal-box .modal-dialog .modal-content .modal-body .btn:hover{
color:#fff;
text-shadow: 0 0 5px #FF1B1A;
box-shadow: 0 0 10px #FF1B1A;
}
.modal-box .modal-dialog .modal-content .modal-body .btn:focus{ outline: none; }
@media only screen and (max-width: 768px){
.modal-dialog{ width: 85% !important; }
}

</style>
<div class="container">
<div class="row">
    <div class="col-md-12">
        <div class="modal-box">
            <!-- Modal --> 
              <div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button><br>

                        <div class="modal-body">
                            <div class="image"></div>
                            <h2 class="title">BLACK FRIDAY DEALS</h2>
                            <p class="description">Get your Rebel paramotor on SPECIAL prices NOW!<br><br>Contact us for more information.</p>
                            <p style="background-color:black;">offers are valid until stock lasts</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
HTML CSS格式

评论

0赞 imhvost 11/18/2023
这很难说,因为您没有提供问题的最小可重现示例。?.modal-dialog{ max-width: 100%!important; }

答:

0赞 krishna 11/24/2023 #1

 .modal-dialog {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;

}

.modal-box{ font-family: 'Quantico', sans-serif; }
.modal-box .show-modal{
background: linear-gradient(#444,#222);
color: #fff;
font-size: 18px;
font-weight: 400;
text-transform: capitalize;
letter-spacing: 1px;
padding: 12px 20px;
margin: 80px auto 0;
border: none;
outline: none;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
display: block;
transition: all 0.3s ease 0s;
}
.modal-box .show-modal:hover,
.modal-box .show-modal:focus{
color: #fff;
outline: none;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
}
.modal-backdrop.in{ opacity: 0; }
.modal-box .modal-dialog{
width: 450px;
margin: 70px auto 0;
}
.modal.fade .modal-dialog{ transform: translateY(-100px); }
.modal.in .modal-dialog{ transform: translate(0); }
.modal-box .modal-dialog .modal-content{
text-align: center;
border: none;
box-shadow: 0 0 10px rgba(0,0,0,0.2);  
}  
.modal-box .modal-dialog .modal-content:before{
content: "";
background: linear-gradient(to right,#FFA678,#FF1B1A);
border-radius: 6px 6px 0 0;
width: 100%;
height: 20px;
display: block;
clear: both;
}
.modal-box .modal-dialog .modal-content .close{
color: #000;
font-size: 50px;
font-weight: 300;
text-align: center;
line-height: 25px;
width: 50px;
height: 35px;
padding-left: 1px;
border-radius: 0 5px 5px 0;
overflow: hidden;
opacity: 1;
position: absolute;
left: auto;
top: 27px;
right: 0px;
z-index: 1;
transition: all 0.3s ease 0s;
}

.modal-box .modal-dialog .modal-content .close:hover{ color: #555; }
.modal-box .modal-dialog .modal-content .close span{
margin: -6px 0 0;
display: block;
}
div.image::before {
content:url(http://motopara.com/images/EVO_17_Popup.jpg);
}
.modal-box .modal-dialog .modal-content .modal-body .title{
color: #000;
font-size: 37px;
font-weight: 500;
letter-spacing: 1px;
display: block;
text-transform: capitalize;
margin: 0 0 20px;
}
.modal-box .modal-dialog .modal-content .modal-body .title::after{
content: "";
background: linear-gradient(to right,#FFA678,#FF0000);
width: 100px;
height: 6px;
margin: 20px auto 0;
border-radius: 10px;
display: block;
clear: both;
}
.modal-box .modal-dialog .modal-content .modal-body .description{
color: #7c0303;
font-size: 20px;
margin: 0 0 30px;
}
.modal-box .modal-dialog .modal-content .modal-body .btn{
color: #FF1B1A;
background: linear-gradient(#444,#222);
font-size: 20px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
padding: 12px 40px;
margin: 0 auto -57px;
border: none;
border-radius: 5px;
display: block;
transition: all 0.6s;
}
.modal-box .modal-dialog .modal-content .modal-body .btn:hover{
color:#fff;
text-shadow: 0 0 5px #FF1B1A;
box-shadow: 0 0 10px #FF1B1A;
}
.modal-box .modal-dialog .modal-content .modal-body .btn:focus{ outline: none; }
@media only screen and (max-width: 768px){
.modal-dialog{ width: 85% !important; }


.modal.fade .modal-content {
    max-height: calc(100vh - 30px);
    overflow: auto;
}
.modal.fade .modal-dialog {
    transform: translateX(0px);
    margin-top: 0;
}


}
<div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="modal-box">
                        <!-- Modal --> 
                          <div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                     <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button><br>
            
                                    <div class="modal-body">
                                        <div class="image"></div>
                                        <h2 class="title">BLACK FRIDAY DEALS</h2>
                                        <p class="description">Get your Rebel paramotor on SPECIAL prices NOW!<br><br>Contact us for more information.</p>
                                        <p style="background-color:black;">offers are valid until stock lasts</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>