2014-10-31 27 views
0

我試圖改變彈出的位置,如果屏幕寬度小於568px通過媒體的質疑,但不知何故,它不工作.. 這裏; S代碼: CSS:彈出位置更新寬度

<style type="text/css"> 
      #wrapper 
      { 
       left: 300px; 
       position: relative; 
       width:500px; 
      } 

      .popup 
      { 
       display:none; 
       width:300px; 
       border:1px solid red; 
       padding: 10px;  
       position: absolute; 
       margin: 10px 0 0 0px; 
      } 
      @media only screen and (max-device-width : 568px) { 
      .popup 
       { 
        margin: 10px 0 0 -180px; 
       } 
      } 
     </style> 

HTML:

<div id="wrapper"> 
     <a href="#" class="def">What is Lorum Ipsum?</a> 
     <div class="popup"> 
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
     </div> 
    </div> 
    </body> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  
    <script> 
    $(".def").click(function(){ 
     $(".popup").toggle(); 
    }); 
    </script> 

這裏的的jsfiddle鏈接: http://jsfiddle.net/0sfve6t3/2/

欣賞您的意見/輸入

回答

2

嘗試的jQuery:

if($(window).width() < 568){ 
    $('.popup').css('margin','10px 0 0 -180px'); 
} 

嘗試CSS:

@media only screen and (max-width: 567px){ 
.popup{margin: 10px 0 0 -180px;} 
} 
+0

完美。這樣一個愚蠢的錯誤..用 「最大設備寬度」 來代替「最大「寬度」..謝謝 – SatAj 2014-10-31 20:56:15