html - 在图像 slider 上定位导航按钮

标签 html css css-position

我想在图像 slider 上放置导航按钮并且我想要响应。我尝试这样做,但只有当我以像素而不是百分比设置最高位置时它才有效。以像素为单位设置它没有响应。

<div id="container">
<header>
    header is here
</header>
<div id="carousel">
<div class="sliderbuttons">
    <input type="button" name="next" id="next" value=" > ">
    <input type="button" name="next" id="prev" value=" < ">
    </div>
    <div class="slides">
        <img src="http://www.planwallpaper.com/static/images/4-Nature-Wallpapers-2014-1_ukaavUI.jpg" alt="image1" class="slide active">
        <img src="http://www.mrwallpaper.com/wallpapers/green-Rice-1600x900.jpg" alt="image2" class="slide">
        <img src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/nature-wallpapers-10.jpg" alt="image3" class="slide">
    </div>


</div>

</div>

CSS

*{
    box-sizing: border-box;
}

#container {
    width: 90%;
    margin: 0 auto;
}

header {
    background: black;
    height: 20px;
    padding: 1.5em;
    color: white;
}

#carousel {
    position: relative;
    margin: 0 auto;
    width: 45%;
    background-color: #f4f4f4;
    margin-top: 15px;
    min-height: 100%;

}

.slide {
    position: absolute;
    max-width: 100%;

}
.sliderbuttons {
    }

#prev,#next {
    position: absolute;
    background-color: rgba(255, 148, 41, 0.68);
    box-shadow: 2px white;
    border:none;
    font-size: 2em;
    color: white;
    font-weight: bold;
/*  font-family: 'Baloo Tamma', cursive;
*/  padding:10px;
    top:45%;
    width: 10%;
    /*making the prev,next on top of content*/
    z-index: 20;
}
#prev {
    left:0;
}
#next {
    right:0;
        }

.active {
    z-index: 10;
}

这是我到目前为止尝试过的。 https://jsfiddle.net/w5xm37y4/1/

最佳答案

如果要以百分比设置位置,则必须为父元素定义百分比。所以尝试添加

html,正文{ 高度:100%; position:relative;

和 height: 100% on #container 也是。我认为(并希望!)它可以帮助你。

(对不起我糟糕的英语)

关于html - 在图像 slider 上定位导航按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39500844/

相关文章:

javascript - 如何在 ng-repeat 过滤器中使用范围变量?

javascript - 为什么我的提交按钮不起作用?

jquery - 为什么 Negator 伪类在 jQuery 中不起作用?

css - GWT 错误!?添加 CSS "position: absolute"时 ClickHandler 未触发

css - 如何在 div 中将绝对定位的元素居中?

html - 如何让背景图片保持纵横比?

HTML SimpleViwer(画廊查看器)在 Firefox 中不对齐 - 在所有其他经过测试的浏览器中工作

css - 响应式布局,将没有内容的 div 拉伸(stretch)到最大宽度

javascript - D3 如何从不透明刻度中去除刻度点

css - 将小 div 精确定位在大 div 的中心。 CSS中获取div的大小