图像在移动设备上偏离正位

时间:2017-02-10 15:05:38

标签: html image css3 responsive-design

我正在尝试构建一个滑块。我在图像上定位了方向导航按钮,但是当我进入移动视图时,按钮一直关闭,这是一段代码,

<div class="design container">
    <section class="subcontainer">
        <h2>
            I love to <span id="purple">design</span> beautiful websites and making<br> my code as good as it can 
        </h2>

        <div class="slider">

            <div class="slide"> 
               <img src="images/charity.jpg" width="100%">
            </div>
            <div class="slide">
                <img src="images/doveyjean.jpg" width="100%">
            </div>
            <div class="slide">
                <img src="images/1.jpg" width="100%">
            </div>

        </div>
        <div class="slider-nav">
          <div class="directional-buttons"> 
            <img class="backward" src="images/backward.png" width="8%">
            <img class="forward" src="images/forward.png" width="8%">
          </div>


            <!-- dots -->
            <ul>
                <li class="active"></li>
                <li></li>
                <li></li>
            </ul>

        </div>

        <div class="button">
            <a href="#"><img src="images/more.png"></a>
        </div>

    </section>
</div>

这里是css,我用过css reset:

body{
    margin: 0 auto;
    height: 100vh;
    font-family: 'Open Sans', sans-serif;
    background-image: url(../images/background.jpg);
    background-size: cover;
    background-position: center;
} 

header,section {
    height: 100%;
}

.container{
    width: 80%;
    margin: 0 auto;
    }  

.subcontainer {
    width: 93.75%;
    margin: 0 auto;
}     

.design{
    background-color: #fff;
    margin-top: 3%;
    height: 140vh;
}

.design h2{
    font-size: 1.75em;
    text-align: center;
    padding-top: 4%; 
    line-height: 1.3;
}

#purple {
    color: #6600ff;
}

.slider{
  padding-top: 3%;
}

.slide{
    display: none;
}

.slide:first-child {
    display: block;
}

.button {
    text-align: center;
    padding-bottom: 3%;
}

.slider-nav{
    height: 10%;
}

.slider-nav ul{
    text-align: center;
    position: relative;
    top: -55px;
}

.slider-nav li{
    list-style: none;
    background-color: black;
    width: 10px;
    height: 10px;
    margin: 3px;
    border-radius: 100%;
}

.slider-nav li.active{
    background-color: #0060ff;
}

.directional-buttons{
    position: relative;
    top: -350%;
    cursor: pointer;

}

.forward{
    float: right;
}

我发布了设计截图

desktop view

mobile view

如何始终将方向按钮保持在滑块的垂直中心和滑块下方的点?任何类型的建议都表示赞赏,如果建议的措施百分比很高。谢谢!

1 个答案:

答案 0 :(得分:0)

将div .directional-buttons放入div滑块以查看如下:

<div class="slider">

            <div class="slide">
                <img src="../a.jpg" style="height: 50vw;width: 100%;" width="">
            </div>
            <div class="slide">
                <img src="images/doveyjean.jpg" width="100%">
            </div>
            <div class="slide">
                <img src="images/1.jpg" width="100%">
            </div>
            <div class="directional-buttons">
                <img class="backward" src="images/backward.png" width="8%">
                <img class="forward" src="images/forward.png" width="8%">
            </div>
        </div>

并添加以下样式:

.slider {
   position: relative;
}

.directional-buttons {
    position: absolute;
    top: 50%;
    width: 100%;
}