简体   繁体   English

如何在响应图像和下面的元素之间创建固定数量的空间?

[英]How do I create a fixed amount of space between a responsive image and an element below?

I have a responsive slider with elements below. 我有一个响应滑块,下面有元素。 I've tried using margin-top on the element below and margin-bottom on the image. 我尝试在下面的元素上使用margin-top,在图像上使用margin-bottom。 In both cases, when the view-port reduces, the image and the other elements part company...ie the gap widens. 在这两种情况下,当视口减少时,图像和其他元素分开公司......即间隙变宽。 I've tried px, vw and vh as the unit for the margin. 我试过px,vw和vh作为保证金的单位。 Is there a technique to resolve this? 有解决方法吗? The code is: 代码是:

    <div id="slider">

    <div class="container">
        <div>
            <img class="slider_img" src="images/hands-coffee-cup-apple_1920x965.jpg"/>
        </div>
        <div>
            <img class="slider_img" src="images/macbook-apple-imac-computer-39284_1920x965.jpg"/>
        </div>
        <div>
            <img class="slider_img" src="images/ipad-tablet-technology-touch_1920x965.jpg"/>
        </div>

    </div>

</div>

<div class="promises_hdr">Our promise to you</div>
<div class="promises">
    <div class="promise">
        <img class="promise_img" src="images/iconfinder_ecommerce.png"/>
        <div class="promise_hdr">Get Noticed, Get Customers</div>
        <div class="promise_txt">
            <p>The progression from the Get Noticed Online step to the Create Customer step goes through 2 other stages. These are Convert and Close. Inward Marketing: webThemes understands.</p>
        </div>
    </div>

#slider{
    width:100%;
    height: 100vh;
    position: relative;

}
.container {
    max-width: 100%;
    height: 100%;
    margin: auto;
    position: absolute;
}
.container div {
    display: inline-block;
    width: 100%;
    height: 940px;
    display: none;
}
.slider_img {
    width: 100%;
    height: auto;
    z-index: -1;
}
.promises_hdr {
    font-family: "Century Gothic", Sans-serif;
    font-size: 2.3em;
    color: #0150E2;
    position: relative;
    text-align: center;
    margin-top: 4vw;
}

$( document ).ready(function() {

     var currentIndex = 0,
      items = $('.container div'),
      itemAmt = items.length;

    function cycleItems() {
      var item = $('.container div').eq(currentIndex);
      items.hide();
      item.css('display','inline-block');
    }

    var autoSlide = setInterval(function() {
      currentIndex += 1;
      if (currentIndex > itemAmt - 1) {
        currentIndex = 0;
      }
      cycleItems();
    }, 4000);

});

Try to use % value for the margin as well. 尝试使用%值作为保证金。 It's the most confident way to resolve many problems in CSS, especially in tweaking site's responsiveness. 这是解决CSS中许多问题的最有信心的方法,特别是在调整网站的响应能力方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM