我试图在WordPress的网页右下角实现一个弹出窗口。
弹出窗口工作正常,但我有2行文本,一条消息和一个按钮。一切都很好,因为我想在按钮上放置一个margin-top,因为按钮覆盖了文本。
在这里,您可以看到HTML代码和CSS。
#corner-slider {
position: fixed;
z-index: 10000;
overflow: hidden;
border-radius: 15px;
color: white;
padding: 10px;
margin-bottom: 60px;
height: 120px;
width: 369px;
border: 1px solid #2d93f1;
background: #2d93f1;
}
#corner-slider.hidden {
display: none;
}
#corner-slider .close {
position: absolute;
cursor: pointer;
font-size: 16px;
display: inline-block;
z-index: 1002;
right: 24px;
top: 10px;
}
.popup-button {
padding: 8px 30px;
background-color: #ffffff;
border-color: #ffffff;
border-radius: 45px;
margin-top: 240px;
}

<div id="corner-slider">
Do you want to stay here?
<br />
<a target="_blank" href="#" class="popup-button">Click me!</a>
</div>
&#13;
那么,为什么margin-top不起作用?我该怎么办?
感谢。
答案 0 :(得分:1)
锚元素<a>
是内联元素。将其display
类型更改为inline-block
或block
:
#corner-slider {
position: fixed;
z-index: 10000;
overflow: hidden;
border-radius: 15px;
color: white;
padding: 10px;
margin-bottom: 60px;
height: 120px;
width: 369px;
border: 1px solid #2d93f1;
background: #2d93f1;
}
#corner-slider.hidden {
display: none;
}
#corner-slider .close {
position: absolute;
cursor: pointer;
font-size: 16px;
display: inline-block;
z-index: 1002;
right: 24px;
top: 10px;
}
.popup-button {
padding: 8px 30px;
background-color: #ffffff;
border-color: #ffffff;
border-radius: 45px;
display: inline-block;
margin-top: 1em;
}
<div id="corner-slider">
Do you want to stay here?
<br />
<a target="_blank" href="#" class="popup-button">Click me!</a>
</div>
答案 1 :(得分:0)
按钮不稳定,只需添加disply:inline-block
或float:left
#corner-slider {
position: fixed;
z-index: 10000;
overflow: hidden;
border-radius: 15px;
color: white;
padding: 10px;
margin-bottom: 60px;
height: 120px;
width: 369px;
border: 1px solid #2d93f1;
background: #2d93f1;
}
#corner-slider.hidden {
display: none;
}
#corner-slider .close {
position: absolute;
cursor: pointer;
font-size: 16px;
display: inline-block;
z-index: 1002;
right: 24px;
top: 10px;
}
.popup-button {
padding: 8px 30px;
background-color: #ffffff;
border-color: #ffffff;
border-radius: 45px;
margin-top: 10px;
display: inline-block; /* newly added */
}
<div id="corner-slider">
Do you want to stay here?
<br />
<a target="_blank" href="#" class="popup-button">Click me!</a>
</div>
答案 2 :(得分:0)
我在代码中做了一些更改,只需查看下面的代码,只需将文本放在div中并添加一个margin-bottom的CSS:15px;
<style>
#corner-slider {
position:fixed;
z-index:10000;
overflow:hidden;
border-radius: 15px;
color: white;
padding: 10px;
margin-bottom: 60px;
height: 120px;
width:369px;
border:1px solid #2d93f1;
background:#2d93f1;
}
#corner-slider.hidden{
display:none;
}
#corner-slider .close{
position:absolute;
cursor:pointer;
font-size:16px;
display:inline-block;
z-index:1002;
right:24px;
top:10px;
}
.popup-button {
padding: 8px 30px;
background-color: #ffffff;
border-color: #ffffff;
border-radius: 45px;
margin-top: 240px;
}
/*--------------- new css ----------*/
.small-area
{
margin-bottom: 15px;
}
</style>
<div id="corner-slider">
<div class="small-area">Do you want to stay here?</div>
<a target="_blank" href="#" class="popup-button">Click me!</a>
</div>