【发布时间】:2017-08-17 10:58:54
【问题描述】:
我有一个图像横幅,我正在尝试在其顶部添加一个按钮。该按钮是 HTML 格式,而不是图像。但是,问题是我无法移动图像顶部的按钮。我相信这与按钮的边距有关。我已经在我的 Weebly 网站中实现了以下代码,虽然该按钮似乎非常适合编辑器,但在发布后,该按钮显示在横幅底部。这是我的 HTML 代码:
“margin:-70px”似乎是正确的,尽管它在发布后并不适用。那么有什么问题呢?有什么遗漏吗?
.btn_action_1 {
border: 5px solid #000 !important;
/* Change button border color */
color: #000 !important;
/* Change button text color */
font-size: 22px;
font-family: 'Ubuntu';
line-height: 0;
display: inline-block;
padding: 10px 15px 10px;
position: relative;
text-decoration: none;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.btn_action_1 span {
left: 10px;
position: relative;
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1 .ico_arrow {
background: url(ico_arrow_w.png) 0 center no-repeat;
display: inline-block;
height: 17px;
width: 17px;
position: relative;
left: -12px;
top: 0px;
opacity: 0;
filter: alpha(opacity=0);
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1:hover {
background: #000 !important;
/* Change button background color when mouse over */
color: #fff !important;
/* Change button text color when mouse over */
}
.btn_action_1:hover span {
left: -5px;
}
.btn_action_1:hover .ico_arrow {
opacity: 1;
filter: alpha(opacity=100);
left: 5px;
}
@media (max-width: 479px) {
.btn_action_1 {
padding: 18px 30px;
}
}
.btn_action_1:not(:hover)>.hover,
.btn_action_1:hover>.default {
display: none
}
<img src="http://unlckpaypal.weebly.com/uploads/6/3/8/8/63884033/left_banner.png" style="margin: 10px 0px 0px 0px;width:440px;height:210px;">
<a href="http://unlckpaypal.weebly.com/trending-127809.html" style="margin:-70px 0px 0px 200px;width:180px;height:45px;" class="btn_action_1">
<span>SHOP NOW</span>
<i class="ico_arrow"></i>
</a>
【问题讨论】:
-
我建议你放弃这种方法,将图像用作(比如说)一个 div 的背景,然后简单地将按钮放在顶部。
-
我认为填充工作正常,请参阅我在答案中添加了 js fiddle
-
您能展示一下您希望输出的图像吗?
-
使用 important 指定填充解决了在我的情况下让按钮填充起作用,例如:
40px!important。感谢:stackoverflow.com/a/6790573/2162226