我的网站上有一个ResponsiveSlides滑块,我试图让上一个/下一个导航箭头在滑块的左右边缘垂直居中。
当我调整浏览器大小时,它们当前移动,右/下箭头似乎在滑块外悬挂了几个像素,并且在480px断点附近发生了一些奇怪的事情(一旦你的距离小于480px,滑块比下面的列略宽;同样,箭头最终向下进入屏幕。
你可以看到它here
JS
<script src="js/responsiveslides.min.js"></script>
<script>
$(function() {
$("#slider").responsiveSlides({
auto: true,
pager: false,
nav: true,
});
});
</script>
HTML
<div class="section group">
<div class="col span_3_of_3">
<ul id="slider">
<li id="1"><img src="assets/slider/buzz-covers.jpg" alt="buzz covers"></li>
<li id="2"><img src="assets/slider/slab-happy.png" alt="slab happy"></li>
<li id="3"><img src="assets/slider/gridbook.jpg" alt="gridbook"></li>
<li id="4"><img src="assets/slider/ninth-spread.jpg" alt="ninth letter"></li>
<li id="5"><img src="assets/slider/slinkster.jpg" alt="slinkster"></li>
<li id="6"><img src="assets/slider/buzz-spread.jpg" alt="buzz spread"></li>
</ul>
</div>
</div>
css(不确定哪些位与我正在做的事情有关,所以这里的所有滑块都与我的样式表有关)
.rslides {
position: relative;
list-style: none;
overflow: hidden;
width: 100%;
padding: 0;
margin: 1.5em 0 0 0;
background-color: #f7f7f7;
}
.rslides li {
-webkit-backface-visibility: hidden;
position: absolute;
display: none;
width: 100%;
left: 0;
top: 0;
}
.rslides li:first-child {
position: relative;
display: block;
float: left;
}
.rslides img {
display: block;
height: auto;
float: left;
width: 100%;
border: 0;
}
.rslides1_nav {
position: absolute;
-webkit-tap-highlight-color: rgba(0,0,0,0);
top: 50%;
left: 0;
z-index: 99;
opacity: 0.7;
text-indent: -9999px;
overflow: hidden;
text-decoration: none;
height: 61px;
width: 38px;
background: transparent url("themes.gif") no-repeat left top;
margin-top: -45px;
}
.rslides1_nav:active {
opacity: 1.0;
}
.rslides1_nav.next {
left: auto;
background-position: right top;
right: 0;
}
.rslides1_nav:focus {
outline: none;
}
.rslides_tabs {
margin-top: 10px;
text-align: center;
}
.rslides_tabs li {
display: inline;
float: none;
_float: left;
*float: left;
margin-right: 5px;
}
.rslides_tabs a {
text-indent: -9999px;
overflow: hidden;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
background: #ccc;
background: rgba(0,0,0, .2);
display: inline-block;
_display: block;
*display: block;
-webkit-box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
-moz-box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
box-shadow: inset 0 0 2px 0 rgba(0,0,0,.3);
width: 9px;
height: 9px;
}
.rslides_tabs .rslides_here a {
background: #222;
background: rgba(0,0,0, .8);
}
答案 0 :(得分:4)
如Varinder所述,将#slider和上一个/下一个链接的父级(.col.span_3_of_3)的位置设置为相对只能解决部分问题。
<div class="col span_3_of_3" style="position: relative;">
<ul id="slider" class="rslides rslides1">
<li id="rslides1_s0" class="" style="display: block; float: none; position: absolute; opacity: 0; z-index: 1; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;">
<img src="assets/slider/buzz-covers.jpg" alt="buzz covers">
</li>
<li id="rslides1_s1" style="float: left; position: relative; opacity: 1; z-index: 2; display: list-item; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;" class="rslides1_on">
<img src="assets/slider/slab-happy.png" alt="slab happy">
</li>
<li id="rslides1_s2" style="float: none; position: absolute; opacity: 0; z-index: 1; display: list-item; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;" class="">
<img src="assets/slider/gridbook.jpg" alt="gridbook">
</li>
<li id="rslides1_s3" style="float: none; position: absolute; opacity: 0; z-index: 1; display: list-item; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;" class="">
<img src="assets/slider/ninth-spread.jpg" alt="ninth letter">
</li>
<li id="rslides1_s4" style="float: none; position: absolute; opacity: 0; z-index: 1; display: list-item; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;" class="">
<img src="assets/slider/slinkster.jpg" alt="slinkster">
</li>
<li id="rslides1_s5" style="float: none; position: absolute; opacity: 0; z-index: 1; display: list-item; -webkit-transition: opacity 500ms ease-in-out; transition: opacity 500ms ease-in-out;" class="">
<img src="assets/slider/buzz-spread.jpg" alt="buzz spread">
</li>
</ul>
<a href="#" class="rslides_nav rslides1_nav prev">Previous</a><a href="#" class="rslides_nav rslides1_nav next">Next</a>
</div>
下一部分是将margin-top
设置为&{34; .rslides_nav&#34;使垂直滑动导航按钮完全居中。
这个解决方案源于这样一个事实:当浏览器宽度小于420px时,这些链接已经预先设置了margin-top,使按钮仍然略微不对齐。
因此,您的问题的解决方案是使用以下CSS
-19.5px
答案 1 :(得分:3)
快速解决方案:
您需要在包含滑块和控件导航的父级上设置position:relative;
,如下所示:
<div class="col span_3_of_3" style="position: relative;">
<ul id="slider" class="rslides rslides1">
...content...
</ul>
<a class="rslides_nav rslides1_nav prev" href="#">Previous</a>
<a class="rslides_nav rslides1_nav next" href="#">Next</a>
</div>
答案 2 :(得分:2)
绝对定位元素相对于第一个具有静态位置的父元素定位。
您的导航元素具有绝对定位,为了使其正常工作,您需要将其容器位置属性设置为除静态之外的任何内容,正如其他答案所示。