如何制作响应式弹出div?

问题描述 投票:0回答:3

基本上我的网站是响应式的,但下面是我的弹出 div div 的代码,它在桌面上运行良好,但在移动纵向上它只是从屏幕上消失,我也需要使该 div 响应式。另外,我希望这个 div 出现在屏幕上并带有淡入淡出或其他动画,但我现在不知道如何使用。请帮忙

HTML 在这里:

    <section id="html" class="content-section text-center">
      <div class="download-section">
        <div class="container">
            <div class="col-lg-8 col-lg-offset-2">
                <h2>HTML Tutorials</h2>
                <p></p>
                <a href="javascript:void(0)" class="btn btn-default btn-lg"       onclick="toggle_visibility('popupBoxHTML');">More HTML Tutorials</a>
                <div id="popupBoxHTML">
                <div class="popupBoxWrapper">
                    <div class="popupBoxContent">
                        <h3>HTML</h3>
                        <p>You are currently viewing HTML Box.</p>
                        <p>Click <a href="javascript:void(0)"    onclick="toggle_visibility('popupBoxHTML');">here</a> to close popup box one.  </p>
                    </div>
                </div>
            </div>
        </div>
     </div>
   </section>

CSS 在这里:

#popupBoxOnePosition, #popupBoxHTML{
 margin:10px 0 0 0;
 top: 0; 
 left: 0; 
 position: fixed; 
 width: 100%; 
 height: 100%;
 background:#333; 
 display: none; 
 opacity:.95; 
 z-index:100;
 widows:50%;

 }

 .popupBoxWrapper{
 width: 550px;
 margin: 
 50px auto; 
 text-align: left;

 }
 .popupBoxContent{
   background-color:
  #000; 
 padding: 
  15px; 
 opacity:1;
 border-radius:15px;
 -o-box-shadow:0 0 50px ##219ab3;
 -moz-box-shadow:0 0 50px ##219ab3;
 -webkit-box-shadow:0 0 50px ##219ab3;
 -ms-box-shadow:0 0 50px ##219ab3;
 transition:ease-in;
 transition-delay:1s;
 -webkit-transition:ease-in;
}

javascript在这里:

    function toggle_visibility(id) {
               var e = document.getElementById(id);
               if(e.style.display == 'block')
                  e.style.display = 'none';
               else
                  e.style.display = 'block';

            }
javascript css popup
3个回答
2
投票

您需要添加媒体查询以使其具有响应能力。

@media only screen and (max-width: 600px) {
  .popupBoxWrapper{
     width:100%;
  }
}

当屏幕宽度低于 600px 时,此 CSS 将使弹出窗口的宽度为 100%,而不是固定的 550px。所以这将使 div 适合屏幕。


1
投票

无需CSS媒体查询。

只需将 CSS 更改为以下内容即可。 将 width:550px 更新为 max-width:550px 并添加 width:95%; 当屏幕小于 550 像素时,剩余 5% 的宽度为您提供弹出窗口的外观和感觉。

.popupBoxWrapper {
   max-width: 550px;
   width: 95%;
   margin: 50px auto; 
   text-align: left;
}

0
投票

引导模态框

改造

扁平、响应式、轻量级、易于定制的模式窗口插件 具有声明性状态符号和哈希跟踪。

© www.soinside.com 2019 - 2024. All rights reserved.