【问题标题】:How to eliminate whitespace between two divs in different class=row's (Bootstrap)?如何消除不同类 = 行(引导程序)中两个 div 之间的空格?
【发布时间】:2015-08-19 04:48:37
【问题描述】:

看起来不错,除了在垂直平板电脑浏览器上。由黑色 div 的高度强制显示红色和蓝色 div 之间的空白。

在解决方案中,平板电脑/手机屏幕上 div 的堆叠顺序为蓝色 > 黑色 > 红色也很重要。

            <html>
            <div class="container">
            <div class="row">
            <div class="col-sm-7"><div class="blue"><img src="jpg"> Lots of whitespace appears below between 768 to aprx 900 px browser width (tablet dimenions)</div></div>
            <div class="col-sm-5"><div class="black">Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text<br>Line of text</div>
            </div>   
            </div>
            </div>     
            <div class="container">
            <div class="row">
            <div class="col-sm-7"><div class="red">Red</div></div>
            <div class="col-sm-5"><div>
            </div>   
            </div>
            </html> 

https://jsfiddle.net/g7xg0uc7/1/

【问题讨论】:

  • 您期待什么?每行都以
    结尾,因此 div 会随着每行添加而向下移动。

标签: html css twitter-bootstrap height


【解决方案1】:

尽我所能:https://jsfiddle.net/g7xg0uc7/12/

HTML:

<div class="container">
    <div class="row">
        <div class="col-sm-7">
            <div class="blue">
                <img src="https://wiki.creativecommons.org/images/9/97/8256206923_c77e85319e_n.jpg" /> Lots of whitespace appears below between 768 to aprx 900 px browser width (tablet dimenions)
            </div>
        </div>
        <div class="col-xs-12 col-sm-5" style="float: right;">
            <div class="black">
                Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text<br/>Line of text
           </div>     
        </div>   
        <div class="col-sm-7">
            <div class="red">Red</div>
        </div>
     </div>   
  </div>

CSS:

.black {width:100%; color: #fff;background-color: black ; padding:10px; float: right;}
.red {width:100%; background-color:red;  color: #fff; padding:10px; float: left;}
.blue {width:100%; background-color:blue; color: #fff; padding:10px}
img {width:100%}

抱歉,如果我删除了您需要的容器,请尝试清理代码以使答案清晰。如果您不喜欢内联样式,可以将该内联浮点数整理到一个类中。

【讨论】:

    【解决方案2】:

    如果您将所有col-sm-# 更改为col-md-#,则它会将空白区域从图像底部和红色 div 中移开,但在这 2 和充满文本的黑色 div 之间仍然存在空白。

    试着和他们一起玩,看看你能不能得到你想要的!

    【讨论】:

      【解决方案3】:

      带有红色divrow 将被黑色div 的高度向下推。

      在同一 col-sm-7 div 中的蓝色 div 下方添加红色 div

      【讨论】:

      • 不能。平板电脑/手机屏幕上 div 的堆叠顺序为蓝色 > 黑色 > 红色,这一点至关重要。你的方式会导致蓝色>红色>黑色。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 2020-10-24
      • 2020-04-11
      • 1970-01-01
      相关资源
      最近更新 更多