带有关闭按钮的 CSS 弹出窗口

标签 css popup

我正在使用 CSS 在我的页面上控制和显示 POPUP,一切正常,但我想要“确定”按钮关闭弹出窗口,而不是通过单击右上角的十字按钮来关闭它。有什么办法可以在 css 中执行此操作。或者我可以为此做些什么。

    .box {
      width: 40%;
      margin: 0 auto;
      background: rgba(255,255,255,0.2);
      padding: 35px;
      border: 2px solid #fff;
      border-radius: 20px/50px;
      background-clip: padding-box;
      text-align: center;
    }
    
    .button {
      font-size: 1em;
      padding: 10px;
      color: #fff;
      border: 2px solid #06D85F;
      border-radius: 20px/50px;
      text-decoration: none;
      cursor: pointer;
      transition: all 0.3s ease-out;
    }
    .button:hover {
      background: #06D85F;
    }
    
    .popup h2 {
      margin-top: 0;
      color: #333;
      font-family: Tahoma, Arial, sans-serif;
    }
    .popup .close {
      position: absolute;
      top: 20px;
      right: 30px;
      transition: all 0.2s;
      font-size: 30px;
      font-weight: bold;
      text-decoration: none;
      color: #333;
    }
    .popup .close:hover {
      color: #06D85F;
    }
    .popup .content {
      max-height: 30%;
      overflow: auto;
    }
    
    /*Let's make it appear when the page loads*/
    .overlay:target:before {
        display: none;
    }
    .overlay:before {
      content:"";
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      display: block;
      background: rgba(0, 0, 0, 0.6);
      position: fixed;
      z-index: 9;
    }
    .overlay .popup {
      background: #fff;
      border-radius: 5px;
      width: 64%;
      position: fixed;
      top: 25%;
      left: 18%;
      padding: 25px;
      margin: 70px auto;
      z-index: 10;
      -webkit-transition: all 0.6s ease-in-out;
      -moz-transition: all 0.6s ease-in-out;
      transition: all 0.6s ease-in-out;
    }
    .overlay:target .popup {
        top: -100%;
        left: -100%;
    }
    
    @media screen and (max-width: 768px){
      .box{
        width: 70%;
      }
      .overlay .popup{
        width: 70%;
        left: 15%;
      }
    }
<!--popup starts-->	
    <div id="popup1" class="overlay">
    	<div class="popup">
    		<h3 style="margin-bottom: 13px; text-align:center; color:red;">Your Application Id : <?php echo $appid;?></h3>
    		<a class="close" href="#popup1">&times;</a>
    		<div class="content">
    			Thank you <span style="text-transform:uppercase; font-weight:600;"><?php echo $firstname;?>&nbsp;<?php echo $middlename;?>&nbsp;<?php echo $surname;?></span> for registring for e-visa service.there is more text. 
    		</div>
    	</div>
    </div>
    <!--popup end-->

最佳答案

....或者您可以只使用样式为按钮的 anchor

    .popup h2 {
      margin-top: 0;
      color: #333;
      font-family: Tahoma, Arial, sans-serif;
    }
    .popup .close {
      display:block;
      border:1px solid darkblue;
      text-align:center;
      background: steelblue;
      color:white;
      border-radius:5px;
      padding:5px;
    }
    .popup .close:hover {
      color: #06D85F;
    }
    .popup .content {
      max-height: 30%;
      overflow: auto;
    }
    
    /*Let's make it appear when the page loads*/
    .overlay:target:before {
        display: none;
    }
    .overlay:before {
      content:"";
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      display: block;
      background: rgba(0, 0, 0, 0.6);
      position: fixed;
      z-index: 9;
    }
    .overlay .popup {
      background: #fff;
      border-radius: 5px;
      width: 64%;
      position: fixed;
      top: 0;
      left: 18%;
      padding: 25px;
      margin: 70px auto;
      z-index: 10;
      -webkit-transition: all 0.6s ease-in-out;
      -moz-transition: all 0.6s ease-in-out;
      transition: all 0.6s ease-in-out;
    }
    .overlay:target .popup {
        top: -100%;
        left: -100%;
    }
    
    @media screen and (max-width: 768px){
      .box{
        width: 70%;
      }
      .overlay .popup{
        width: 70%;
        left: 15%;
      }
    }
<!--popup starts-->	
    <div id="popup1" class="overlay">
    	<div class="popup">
    		<h3 style="margin-bottom: 13px; text-align:center; color:red;">Your Application Id : <?php echo $appid;?></h3>
    		<div class="content">
    			Thank you <span style="text-transform:uppercase; font-weight:600;"><?php echo $firstname;?>&nbsp;<?php echo $middlename;?>&nbsp;<?php echo $surname;?></span> for registring for e-visa service.there is more text. 
    		</div>

        <a class="close" href="#popup1">OK</a>

    	</div>
    </div>
    <!--popup end-->

关于带有关闭按钮的 CSS 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48873173/

相关文章:

javascript - 输入类型隐藏值加载时调用函数

javascript - 在javascript中将带引号的var从父级传递给子级

javascript - 使用引导下拉子菜单

iphone - 响应式设计高达 320 像素?

jquery - 检查cookie是否存在并隐藏内容

javascript - 使用 JQuery 单击时打开延迟窗口

css - 如何 CSS 选择除 IE7/8 上的最后一个单元格之外的所有单元格?

javascript - 有什么方法可以将部分使用 Javascript 设计的网页转换为纯 HTML 和 CSS?

javascript - 如何在Leaflet中标记类似于Google map 的标记

wpf - 为什么我的 Popup 在某些机器上显示在 Placement 属性的对面?