Make popup div responsive on mobile devices

时间:2017-07-17 15:29:07

标签: jquery css mobile responsive-design media-queries

I am trying to make my pop up div to be responsive on a mobile device. It works perfectly fine on the website but on my mobile device you can't exit the popup and it is too large. Im assuming that I have to use a media query but I've tried a few and I am not too experienced with media queries. I've provided a screenshot of my problem and my code for the popup window.

CSS:

    <style>
    #close{
    width: 20px;
    height: 20px;
    background: #000;
    border-radius: 50%;
    border: 3px solid #fff;
    display: block;
    text-align: center;
    color: #fff;
    text-decoration: none;
    position: absolute;
    top: -15px;
    right: -15px;
    cursor: pointer;
    }

    </style>

  <!--Shop Now Button-->
  <style>

    #btn1{
    position:absolute;
    float: center;
    width: 300px;
    height: 50px;
    font-size: 20px;
    font-weight: bold;
   /* box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19); */
    margin-top:320px; /*brings buttons down*/
      margin-left:60px;
    }


    #emailf{
      position:absolute;
      float: center;
    width: 300px;
    height: 40px;
    font-size: 20px;
    color:black;
    font-weight: bold;
   /* box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19); */
    margin-top:200px; /*brings buttons down*/
      margin-left:60px;
    }

    #password1 {
      position:absolute;
    float: center;
    width: 300px;
    height: 40px;
    font-size: 20px;
    color:black;
    font-weight: bold;
   /* box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19); */
    margin-top:260px; /*brings buttons down*/
      margin-left:60px;
    }


  </style>

  <!-- CSS for the Popup Box -->
  <style>




     #hider
    {
        position:fixed;
        top: 0%;
        left: 0%;
        width:9000px;
        height:9000px;
        margin-top: -100px; /*set to a negative number 1/2 of your height*/
        margin-left: -200px; /*set to a negative number 1/2 of your width*/
        opacity:0.8;
        background-color:#666;
        z-index:99999;

    }

    #popup_box  
    {
        background-image: url('https://cdn.shopify.com/s/files/1/0569/4201/files/popupbanner_3.jpg?11297628032998908977');
        position:fixed;
        top: 50%;
        left: 50%;
        width:450px;
        height:570px;
        margin-top: -315px; /*set to a negative number 1/2 of your height*/
        margin-left: -225px; /*set to a negative number 1/2 of your width*/

       z-index:999999; 

        border: none;
        border:  none;
        padding: 40px;


    }    


  </style>

JAVASCRIPT/JQUERY:

  <script>

     $(document).ready(function () {
        //hide hider and popup_box
        $("#hider").hide
        $('#popup_box').fadeIn("slow");

        //on click show the hider div and the message
        $("#showpopup").click(function () {
            $("#hider").fadeIn("slow");

        });


        //on click hide the message
        $("#close").click(function () {

            $("#hider").fadeOut("slow");
            $('#popup_box').fadeOut("slow");
            $('#popup_box').close;

        });

       $("#shop").click(function () {

            $("#hider").fadeOut("slow");
            $('#popup_box').fadeOut("slow");
        });

       $(document).keyup(function(e) {
     if (e.keyCode == 27) { 
       $("#hider").fadeOut("slow");
       $('#popup_box').fadeOut("slow");
            $('#popup_box').close;
    }
});

        });


 function PopUp(hideOrshow) {
    if (hideOrshow == 'hide') {
        document.getElementById('ac-wrapper').style.display = "none";
    }
    else  if(localStorage.getItem("popupWasShown") == null) {
        localStorage.setItem("popupWasShown",1);
        document.getElementById('ac-wrapper').removeAttribute('style');
    }
}
window.onload = function () {
    setTimeout(function () {
        PopUp('show');
    }, 0);
}


function hideNow(e) {
    if (e.target.id == 'ac-wrapper') document.getElementById('ac-wrapper').style.display = 'none';
}

</script>

HTML:

<div id="ac-wrapper" style='display:none' onClick="hideNow(event)"> 
    <div id="hider"></div>
    <div id="popup_box" >




      <br>
       {% form 'create_customer' %}


    <center>
       <div id="emailf" class="clearfix large_form">
              <label for="email" class="label"></label>
              <input type="email" value="" name="customer[email]"placeholder="Email" id="email" class="text" style="text-align:center; margin: 0 auto; width:300px; height:30px;" />
            </div>
       <div id="password1" class="clearfix large_form">
              <label for="password" class="label"></label>
              <input type="password" value="" name="customer[password]"placeholder="Password" id="password" class="password text" style="text-align:center; margin: 0 auto; width:300px; height:30px;" />
            </div>



      <div id="btn1" class="clearfix large_form">
              <label for="Create" class="btn1"></label>
              <input type="submit" value="SIGN UP!" style="text-align:center; font-weight:bold;margin: 0 auto; width:310px; height:40px;background-color:#852B8A;color:white;" />
            </div>
      <div id="close">X</div>
     <!--  <input class="btn1" type="submit" value="Create" />-->
     <!-- <button id="shop"><a href="https://www.alzerina.com/collections/ready-to-wear">Sign Up Now!</a></button> -->

    </center>
    </div>   {% endform %}
</div>

You may look at the web version of the popup at alzerina.com

This is the current problem on the mobile version

2 个答案:

答案 0 :(得分:0)

你可以使用这样的媒体查询:

<style>
  @media (max-width: 600px) {
   #popup_box{
    top: 0;
    left: 0;
    width:100%;
    max-width: 100%;
    height:100%;
   }
 }
</style>

答案 1 :(得分:0)

尝试一下。 仅纯CSS和Div:

<style>
     *, *:after, *:before {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}
.confirm {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  min-width: 280px;
  max-width: 500px;
  height: auto;
  background: #E2E2E2;
  border-radius: 10px;
  padding: 0;
  margin: 0;
  border-top: 1px solid white;
  animation: fade 1s ease 1 forwards;
}
.confirm h1 {
  text-align: center;
  font-size: 1.2rem;
  margin: 1.5rem 1rem 0.5rem;
}
.confirm p {
  text-align: center;
  font-size: 1rem;
  margin: 0 2rem 4.5rem;
}
.confirm button {
  background: transparent;
  border: none;
  color: #1678E5;
  height: 3rem;
  font-size: 1rem;
  width: 50%;
  position: absolute;
  bottom: 0;
  cursor: pointer;
}
.confirm button:nth-of-type(1) {
  border-top: 1px solid #B4B4B4;
  border-right: 1px solid #B4B4B4;
  left: 0;
  border-radius: 0 0 0 10px;
}
.confirm button:nth-of-type(2) {
  border-top: 1px solid #B4B4B4;
  right: 0;
  border-radius: 0 0 10px 0;
}
.confirm button:focus,
.confirm button:hover {
  font-weight: bold;
  background: #EFEFEF;
}
.confirm button:active {
  background: #D6D6D6;
}

 </style>


<div class="confirm">
  <h1>Text Head</h1>
   <h1></h1>
  <p><strong>Text Deatils </strong></p>
    <form action="">
   <button>OK</button>
  <button>Cancel</button>