我正在尝试将小的“ x”关闭按钮添加到uk-modal弹出窗口的右上角。我如何正确添加其php代码和CSS以及可能的JavaScript?
我尝试将以下1、2个代码添加到3个代码块中:
1)我添加的第一个代码:
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
2)添加了第二个代码:
<div id="my-id">
<div class="uk-modal-dialog">
<button class="uk-modal-close-default" type="button" uk-close></button>
</div>
</div>
<div id="my-id">
<div class="uk-modal-dialog">
<button class="uk-modal-close-outside" type="button" uk-close></button>
</div>
</div>
3)到弹出的此代码块:
<div class="uk-modal-dialog">
<div class="uk-modal-header">
<h2><?php echo esc_attr_e( $options['popuptitle'] ); ?></h2>
</div>
<div class="uk-modal-content"><?php echo stripslashes( $options['popuptext'] ); ?></div>
<div class="uk-modal-footer">
<button id="button1" type="button" class="uk-button uk-button-large uk-button-<?php echo esc_attr_e( $options['popupbutton1style'] ); ?><?php if( $options['popupbuttonoptions'] != 'button-1-redirect' ) echo ' uk-modal-close'; ?>"><?php echo esc_attr_e( $options['popupbutton1text'] ); ?></button>
</div>
</div>
</div>
我希望在弹出窗口上获得“ x”关闭按钮的真实位置,但是它不在适当的位置,因此也无法关闭模式弹出窗口。
我希望像下面的图片那样得到它:
如何解决?
答案 0 :(得分:0)
看看是否对您有帮助:
.close-button {
border: none;
display: inline-block;
padding: 8px 16px;
vertical-align: middle;
overflow: hidden;
text-decoration: none;
color: inherit;
background-color: inherit;
text-align: center;
cursor: pointer;
white-space: nowrap
}
.topright {
position: absolute;
right: 0;
top: 0
}
<header style="background-color:#000;color:#fff;">
<span onclick="document.getElementById('YourModalBox').style.display='none'" class="close-button topright">×</span>
</header>
别忘了为模态YourModalBox
设置“ id
”,并将其应用于模态框的标题,这样它就进入<div>
内并停留在右上角。
我仍在开发中的Web应用程序中的一个实时示例(请注意,由于我没有发布完整的body
HTML,因此该示例无法正确显示,因为它太长且与值无关的答案:
// When the user clicks anywhere outside of the modal, close it
window.addEventListener('click', function(event) {
if (event.target == document.getElementById('mod_mec')) {
document.getElementById('mod_mec').style.display = "none";
}
if (event.target == document.getElementById('mod_therm')) {
document.getElementById('mod_therm').style.display = "none";
}
});
#btn_menu {
background-color: #000;
}
#btn_menu:hover {
animation-name: change;
animation-duration: 0.6s;
}
@keyframes change {
from {
background-color: #000
}
top {
background-color: #777
}
}
#subs {
opacity: 0.7;
}
#subs:hover {
cursor: pointer;
opacity: 1;
animation-name: hovering;
animation-duration: 0.6s;
}
@keyframes hovering {
from {
opacity: 0.7;
}
top {
opacity: 1;
}
}
<link rel="stylesheet" href="https://www.w3schools.com/w3css/3/w3.css">
<div class="w3-row-padding">
<div class="w3-col l3 m6 w3-margin-bottom">
<div id="subs" class="w3-display-container" onclick="document.getElementById('mod_mec').style.display='block'">
<div class="w3-display-topleft w3-black w3-padding">Mechanics</div>
<img src="_img/sub_bg.jpg" style="width:100%">
<div class="w3-display-middle w3-light-grey w3-padding">
V<sub>avg</sub> = Δs ÷ Δt
</div>
</div>
</div>
<div id="mod_mec" class="w3-modal">
<div class="w3-modal-content w3-animate-top w3-card-4">
<header class="w3-container w3-black">
<span onclick="document.getElementById('mod_mec').style.display='none'" class="w3-button w3-display-topright">×</span>
<h2>Choose a topic</h2>
</header>
<!-- VELOCITY -->
<div class="w3-col l3 m6 w3-margin-bottom">
<a href="velocity.html">
<div id="subs" class="w3-display-container">
<div class="w3-display-topleft w3-black w3-padding">Velocity</div>
<img src="_img/sub_bg.jpg" alt="House" style="width:100%">
<div class="w3-display-middle w3-light-grey w3-padding">
V<sub>avg</sub> = Δs ÷ Δt
</div>
</div>
</a>
</div>
</div>