【问题标题】:CSS, image slider height with overlaying dots placement issue on responsive designCSS,图像滑块高度与响应式设计上的重叠点放置问题
【发布时间】:2015-01-02 20:52:04
【问题描述】:

可能会忽略一些简单的事情,但问题是浏览器窗口宽度较小时。重叠点放置不正确(图像底部)。

注意:如果从 HTML LI 中删除“HEIGHT”属性,则不会显示图像。 玩高度:自动;在 HTML/CSS 中具有相同的结果。最大高度具有相同的效果。

我想删除硬编码的 HTML 样式高度,并让点始终出现在图像的底部,无论大小。

小提琴:http://jsfiddle.net/s3r8uuzz/

JavaScript 文件:

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//unslider.com/unslider.min.js" type="text/javascript"></script>

CSS:

.banner ul { 
  list-style: none; /* Lose the dot */
  margin:0px;
  padding:0px;
}

.banner li { 
  float: left; 
  background-size: 100% auto;
  background-repeat: no-repeat;
}

.dots {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  bottom: 0px;
  background-color: #353535;
  height: 35px;
  opacity: .7;
}

.dots li {
  position:relative;
  top:11px;
  left:-4px;
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 4px;
  text-indent: -999em;
  border: 2px solid #bc9a6a;
  background-color: white;
  border-radius: 6px;
  cursor: pointer;
  -webkit-transition: background .5s, opacity .5s;
  -moz-transition: background .5s, opacity .5s;
  transition: background .5s, opacity .5s;
}

.dots li.active {
  background: #3e245b;
  opacity: 1;  /* opacity of the inside dot (not the border) */
}


#slider{
  position: relative;
}

HTML:

<div id="slider" style=""> 
    <div class="banner">
        <ul>
            <li style="background-image: url(http://cdn.nliphonedwwwghan.savviihq.com/wp-content/uploads/2013/12/500px1-580x375.jpg); height:350px;"><a href="/testing"></a></li>
            <li style="background-image: url(http://cdn.nliphonedwwwghan.savviihq.com/wp-content/uploads/2013/12/500px1-580x375.jpg); height:350px;"><a href="testing"></a></li>
        </ul>
    </div>
</div> 
<div>
    No matter the window size, this text should be directly under the image.
</div>
<script>
        // main image settings
        $('.banner').unslider({
                arrows: false,
                delay: 2000,
                fluid: true,
                speed: 1000,
                dots: true
        });

</script>

【问题讨论】:

  • 图像容器的高度固定为 350px,图像将在其中响应,但容器将保持相同的高度
  • 是的,高度在 HTML 中是固定的。我想删除它,但无法删除,因为删除后的图像不会显示。
  • 不要使用背景图片,把图片放在li里面,li高度会包裹图片
  • 我编辑了问题以澄清我需要解决的问题。感谢您指出缺乏明确性。

标签: html css unslider


【解决方案1】:

您对点使用 position:absolute,为了让它们正确定位在其父级而不是页面主体中,您需要提供滑块容器,该容器当前的 id 为“slider”,一个相对定位。

#slider { position: relative; }

这将包含点在其父容器中的绝对定位。

【讨论】:

  • 我相信此解决方案适用于大图像,但当您减小图像尺寸时(如问题中所述的较小屏幕分辨率),问题仍未解决。
  • @hungerstar 我喜欢这种思路,它解决了我注意到的另一个问题。但是我仍然无法删除 HTML 中的固定高度,它将始终保持在图像的底部。
  • 我已更新问题和 FIDDLE 以反映您的改进。谢谢。
  • @thefid ru-pearls 发布了答案,我只是对其进行了简单的编辑。我确实快速浏览了一下,包含您的liul 最终成为您的图像幻灯片有一个height: 0px 使用运行它的jQuery 设置。找到一个不同的 jQuery 滑块可能比强迫这个滑块做你想做的更容易。
  • 我同意@hungerstar,我会找到一个符合您要求的。我做了一些调查,我认为某处存在错误。我查看了 unslider 的网站,包含
    • 具有高度,而不是
    • 的高度。我认为解决方案是尝试将高度分配给
        而不是单个
猜你喜欢
相关资源
最近更新 更多
热门标签