使用Flexbox使弹出窗口完全响应

时间:2019-03-12 22:27:17

标签: javascript html css flexbox media-queries

我创建了一个模态/弹出窗口,其中包含图片https://www.labtag.ca/。它应该在所有设备上完全响应(手机和Ipad的垂直布局)。它适用于大型设备,并且可以在chrome中模拟所有标准设备尺寸,但是当调整浏览器的大小并检查浏览器的外观时出现乱序(在一定宽度下从大到小进行缩放以及在移动设备中实时进行)时,在滚动条上添加不必要的高度。我使用flex-direction:行用于大型设备,对于小型设备,我使用flex-direction:列。我使用了很多媒体查询(不是一个好主意)来确保padding(所有方向)都很好。关于如何解决这些问题并减少媒体查询的任何见解。这是我的HTML:-

<div id="myModal" class="modal">


  <div class="modal-content">
    <span class="close">&times;</span>
    <div class="content-img-wrapper">
      <div class="img"><img src="https://cdn2.bigcommerce.com/server3300/p3n7fuwd/product_images/uploaded_images/computer.png" alt="ga-popup-img" /></div>
     <div class="content">
       <p>You're missing out <span id= "ga-icons">&#9632; &#9632; &#9632;</span></p>
       <ul>
         <li><i class="arrow right"></i>Access the latest products</li>
         <li><i class="arrow right"></i>Get discounts</li>
         <li><i class="arrow right"></i>Checkout in $CAD</li>
         <li><i class="arrow right"></i>Live Chat</li>
       </ul>
       <a href="https://www.labtag.com/" class="btn-ga">
        Take me to the new website  <i class="arrow-button"></i></a>
      </div>
    </div>
  </div>

</div>

这是我的CSS:-

/*start of ga popup*/
/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
 position: fixed; /* Stay in place */
  z-index: 2; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: hidden; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */

}
i.right{ /*Style for the arrows*/
      border: solid #fc7a22;
  border-width: 0 3px 3px 0;
  display: inline-block;
  padding: 3px;
    transform: translate(0%,-40%) rotate(-45deg);
        margin-right: 10px;



    }
i.arrow-button{ /*Style for the arrows*/
      border: solid #fff;
  border-width: 0 3px 3px 0;
  display: inline-block;
  padding: 3px;
    transform:  rotate(-45deg);
        margin-right: 10px;



    }
/*Making the image responsive*/
.content-img-wrapper .img img{
  width:100%;
  height:auto;
}

/*button inside the modal */
a.btn-ga {
    color: #fff;
    background-color: #fc7a22;
    box-shadow: 0 2px 10px 0 rgba(0,0,0,.1);
    transition: all .4s ease;
    margin-right: auto;
    margin-left: auto;
    position: relative;
    z-index: 2;
    display: inline-block;
    font-weight: 400;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    width: 14.7rem;
    /* height: 4.8rem; */
    border-radius: .5rem;
    font-family: Amsi Pro Cond Bold;
    font-size: 1rem;
    /*letter-spacing: .07rem;*/
    line-height: 2rem;
    text-decoration:none;
    transform: translate(0%,140%);
    /* padding-top: 1.3rem; */
    /* border: 0; */
}

/*styling the content */
.content-img-wrapper{
   display: flex;
  flex-flow:row wrap;
}
.content-img-wrapper .content p {
    /* justify-content: space-around; */
    font-size: 45px;
    font-family:'Atlas Grotesk Bold';
    font-weight:bold;
    color: #351f65;
    /*transform: translateY(-120%);*/

}
.content-img-wrapper .content ul {
  list-style-type: none;
    border: unset;

}
.content-img-wrapper .content ul li {
    /* justify-content: space-around; */
    font-size: 33.5px;
    color: #351f65;
    font-family:'Atlas Grotesk Regular';
    /*transform: translate(-10%,-80%);*/
    margin-bottom: 10px;
    border-bottom: unset;
}
.content-img-wrapper .content ul li:before {
   /* content: "• ";
    color: #53c5e9; */

}
/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  border-radius: 6px;
  border: 1px solid #888;
  width:  70%;
  height: 70%;

 transform: translate(0%, 8%);
}


.content-img-wrapper{


    /*padding-top: 80px;*/


}


.content-img-wrapper .img {
    width: unset;
    height: unset;
    padding: 20px
}
.content-img-wrapper.content{
  padding: 20px

}
a.btn-ga:hover{
    color:#fff !important;
    }
/* The Close Button */
.close {
  /*color: #aaaaaa;*/
  color:#c2c2c2;
  float: right;
  font-size: 28px;
  font-weight: bold;
        transform: translate(-40%,40%);
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
/*unicode icons*/
#ga-icons{
  font-size:10px;
  display:inline-block;
}
/*For phones till ipad pro*/
@media screen and (max-width: 1024px) {
/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  border-radius: 5px;
  border: 1px solid #888;
  width:  100%;
  height: 80%;


}
.content-img-wrapper .img img{
    /*width:90%;*/
        margin-left: 8px;
    }
}
/* For just phones*/
@media screen and (max-width: 767px) {
.content-img-wrapper{
 flex-direction: column;
}
  .content-img-wrapper .content p {
    /* justify-content: space-around; */
    font-size: 25px;
    transform:unset;

}
.content-img-wrapper .content ul li {
   font-size: 15px;

    transform: translate(-10%,100%);
}
.content {
    transform: translate(15%);
}
.modal-content {
    width:90%;
    min-height: 90%;

transform:unset;
}
i.right{
transform: scale(0.7)translate(0%,-20%) rotate(-45deg);
}

}
@media screen and  (min-width: 320px) and (max-width: 360px) {
    .modal{
        padding-top:unset;
        }
.modal-content {

    height: 82%;
}
.content-img-wrapper .content p {

    font-size: 22px;
}

}
@media  screen 
    and (device-width : 375px) 
    and (device-height : 812px) 
    and (-webkit-device-pixel-ratio : 3) { 
.modal-content {
    width: 90%;
    height: 64%;

}

}
@media screen 
  and (device-width: 411px) 
  and (device-height: 823px) 

   {
.modal-content {
    width: 90%;
    height: 66%;

}

}

@media screen 
  and (device-width: 320px) 
  and (device-height: 568px) 

   {
.content {
    transform: translate(11%);
}

}
/*Ipad and Ipad pro specific styles*/
@media  screen 
  and (min-width: 768px) 
  and (max-width: 1279px) 
  {
    .content {

    transform: translate(30%);
    }
    .content-img-wrapper .content ul li {

    transform: translate(-2%,132%);
   margin-bottom: 20px;
}
.content-img-wrapper {
    padding-top: 20px;
    flex-direction: column;
flex-wrap:unset;
}
.content-img-wrapper .img img {
    width: 90%;
    height: auto;
      margin-left: 60px;
}

a.btn-ga {
        transform: translate(0%,80%);
    font-size: 2rem;
        line-height: 3rem;
        width: 29rem;
    height: 3rem;
    }
i.arrow-button {

    transform: scale(1.5)translateY(-25%) rotate(-45deg);
    margin-right: 10px;
}

}
/*For laptops and bigger*/
@media screen and (min-width: 1280px) {
    .content-img-wrapper{

    justify-content: space-around;
    transform: translateY(30%);

}
.content-img-wrapper .content {
    padding-top: 30px;
}
.modal-content {

  width: 1250px; 

}
.content-img-wrapper .content ul li{

        transform: translate(-4%,200%);
    padding-bottom: 10px;
    }
a.btn-ga{
    transform: translate(0%,200%);
    width:483px;
    font-size: 2rem;
        line-height: 4rem;
    height:58px;
    }
i.arrow-button {
    border: solid #fff;
    border-width: 0 3px 3px 0;
    display: inline-block;
    padding: 3px;
    transform: scale(1.5) translateY(-33%) rotate(-45deg);
    margin-right: 10px;
}
#ga-icons {
    font-size: 20px;

}
}

@media screen and (min-width: 1280px) and (max-height: 800px){
.content-img-wrapper {
    transform: translateY(20%);
}


}

/*end of ga popup*/

这是我的js:-

<script>
// Get the modal
var modal = document.getElementById('myModal');



// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
jQuery(document).ready( function($) {
    if(window.location.href !='https://www.labtag.ca/'){
        return;
        }
  modal.style.display = "block";
  $('#Header,#TopMenu').addClass('blur-in');
});

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
      $('#Header,#TopMenu').removeClass('blur-in');
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
   $('#Header,#TopMenu').removeClass('blur-in');
  }
}
</script>

1 个答案:

答案 0 :(得分:0)

很抱歉,这是一个很长的CSS,在上面的CSS里面,是媒体查询:-

private DataTable tblFiltered = 
  ds.Tables("GRAPHICS").AsEnumerable().Where(row => 
  row.Field<int>("GRAPHIC_ID") == graphId && row.Field<int> 
 ("GRAPHIC_ID")).CopyToDataTable;