这可能吗?
基本上我有以下内容: -
HTML
<div id="wrapper">
<a href="https://bookings.planetbouncetrampolinepark.com/JumpBookings/BookSession.aspx?site=1&group=1">
<div class="btn-book book-now-merge" style="color: rgb(0, 0, 0); z-index: 6;">
<span class="txt-plan" style="display: none;">plan your jump</span>
<br>
<span class="txt-book" style="top: -25px; background: url("/wp-content/themes/planetbounce/assets/img/txt-book-now.png");"></span>
<span id="glim-block" style="height: 0px;">
<span class="book-now-glimmer" style="left: 310px; display: block;">
</span>
</span>
</div>
<span class="book-now-shadow-default" style="display: none;"></span>
<span class="book-now-shadow" style="display: none; opacity: 0;"></span>
</a>
</div>
CSS
#wrapper {
width: 600px;
height: 1000px;
background: #ececec;
}
.book-now-merge {
background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/book-now-merge.png);
height: 54px;
width: 278px;
background-size: 278px 54px;
position: fixed;
top: 73px;
right: 0;
z-index: 5;
}
这是JSFIDDLE。
我基本上总是希望.book-now-merge
始终与#wrapper
div对齐,但作为一个固定的位置,以便在向下滚动页面时它与您保持一致,任何想法如何实现这一点?< / p>
答案 0 :(得分:1)
由于#wrapper
和.book-now-merge
都有固定宽度,因此您可以采用#wrapper
(600px)的宽度,从.book-now-merge
的宽度中减去(278px)并使用生成的322px
作为固定定位left
元素的.book-now-merge
参数:
答案 1 :(得分:0)
你可以尝试这个:
#wrapper {
width: 600px;
height: 1000px;
background: #ececec;
}
.book-now-merge {
background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/book-now-merge.png);
height: 54px;
width: 278px;
background-size: 278px 54px;
position: absolute;
top: 73px;
right: 0;
z-index: 5;
}
答案 2 :(得分:0)
尝试将float:right
添加到<a>
元素,然后从.book-now-merge中删除right: 0
。
编辑:如果您需要在包装内部使用.book-now-merge,只需添加margin-left: -278px