【问题标题】:Bootstrap 3 - Aligning column heightBootstrap 3 - 对齐列高
【发布时间】:2017-05-11 00:14:48
【问题描述】:

为教育目的创建一个网站,但我遇到了网格/列高问题。

这是我要复制的网站图片: Click me

这是我目前得到的:Click me

我的问题是,在第一行我有两列 (col-sm-6),在第一列我嵌套了另一行并在其中创建了 2 个额外的列。但是,第二列似乎比第一列高。我尝试调整 img 大小,但它失去了我需要的响应能力。

希望有人理解我想说的话,我对 Web 开发真的很陌生。我希望有人可以帮助我。 :(

请参考随附的图片来验证问题。谢谢。

我的代码 -

HTML:

    <!-- start portfolio-content -->
        <section class="portfolio-content">
            <div class="row" id="port-first-row">
                <div class="col-sm-6" id="port-first-col">
                    <div class="row">
                        <div class="col-12">
                            <img src="images/others/large/BridalPlannerHeader.jpg" alt="image"/>
                        </div> <!-- end col-12 -->
                        <div class="col-12">
                            <img src="images/others/large/video-home.jpg" alt="video" />
                        </div> <!-- end col-12 -->
                    </div> <!-- end row -->
                </div> <!-- end port-first-col -->

                <div class="col-sm-6" id="port-second-col">
                    <img src="images/home/medium/KC_phuket-thailand-wedding-photographer_0061.jpg" alt="image" />
                </div> <!--end port-second-col -->
            </div> <!-- end port-first-row -->

            <div class="row" id="port2-second-row">
                <div class="col-sm-6" id="port2-first-col">
                    <img src="images/others/large/Phuket_view.jpg" alt="phuket" />
                </div> <!-- end col-sm-6 -->
                <div class="col-sm-6" id="port2-second-col">
                    <img src="images/others/large/Julie+Andrew_darinimages-409.jpg" alt="julie" />
                </div> <!-- end col-sm-6 -->

            </div> <!-- end port-second-row -->
        </section> <!-- end portfolio-content -->

CSS/SASS:

 .portfolio-content {
    max-width: 100%;
  }
  img {
    width: 100%;
  }
  .col-sm-6 {
    padding: 0;
  } 
  #port-first-row {
    max-width: 100%;
    margin: 0;
  }
  #port2-second-row {
    max-width: 100%;
    margin: 0;
  }

【问题讨论】:

  • 引导程序中没有 col-12
  • 尝试使用 bootstrap 预定义的class="img-responsive" 图像。
  • 我认为 col-12 让你使用 div 的整个长度还是占据所有 12 个空间?唔。回家后让我试试 img-responsive 。我会回复你的,谢谢你回答顺便说一句。 :)
  • 填充整个行的宽度,你可以使用任何视口宽度col-xs-12
  • 我明白了.. img-responsive 类怎么样?即使包含它的 div 具有未定义的宽度/高度,它会起作用吗?我很想尝试一下,但我还没回家。 :(

标签: twitter-bootstrap css grid alignment


【解决方案1】:

这是一个sn-p,但我不明白为什么列之间的差距如此之大。

虽然看https://jsfiddle.net/xeen9s7y/ - 它运作良好。

我已在图像中添加了border: solid 1px red; 以获得更好的视觉控制。

img {
    width: 100%;
    height: 100%;
    border: solid 1px red;
}
.imgcont {
    height: 25vw;
    padding: 1px;
}
.imgcont2 {
    height: 50vw;
    padding: 1px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
      <section class="portfolio-content">
            <div class="row" id="port-first-row">
                <div class="col-xs-6" id="port-first-col">
                    <div class="row">
                        <div class="col-xs-12 imgcont">
                            <img src="//placehold.it/200x150/2255EE" alt="image"/>
                        </div> <!-- end col-12 -->
                        <div class="col-xs-12 imgcont">
                            <img src="//placehold.it/200x150/2255EE" alt="video" />
                        </div> <!-- end col-12 -->
                    </div> <!-- end row -->
                </div> <!-- end port-first-col -->

                <div class="col-xs-6 imgcont2" id="port-second-col">
                    <img src="//placehold.it/200x150/2255EE" alt="image" />
                </div> <!--end port-second-col -->
            </div> <!-- end port-first-row -->

            <div class="row" id="port2-second-row">
                <div class="col-xs-6 imgcont" id="port2-first-col">
                    <img src="//placehold.it/200x150/2255EE" alt="phuket" />
                </div> <!-- end col-sm-6 -->
                <div class="col-xs-6 imgcont" id="port2-second-col">
                    <img src="//placehold.it/200x150/2255EE" alt="julie" />
                </div> <!-- end col-sm-6 -->

            </div> <!-- end port-second-row -->
        </section> <!-- end portfolio-content -->

【讨论】:

  • 你是上帝吗?!哈哈。谢啦!你是救生员!现在我要做的就是了解你是如何做到的。或者,也许您可​​以快速解释一下它是如何做到的?它可能会解决我仍然与网格有关的另一个问题,如果不是太多,也许你可以研究一下。第一行和第二行的中间填充/边距不对齐。现在正在尝试解决它..但是说真的,谢谢伙计!你真棒! :) 这里:photobucket.com/user/Young_Do_Choi/media/…
  • 我现在对齐了!谢啦!输出如下:photobucket.com/user/Young_Do_Choi/media/… 我得知道你是怎么做到的,伙计!你是天才!我爱你!哈哈!如果你能解释给我听,那就太棒了!但无论哪种方式,我真的不能感谢你,bud.BIG THANKS!!!!!!
  • padding: 1px; 覆盖 BS 的默认填充设置。如果您从样式中删除 padding: 1px; ,您将看到默认值,即 padding-right: 15px; padding-left: 15px; ,默认情况下 padding-top 和 padding-bottom 为零。
  • 对对对,但我认为对我帮助最大的是'vw'属性,我相信那是视口宽度,对吗?我得更深入地研究它,因为我有点困惑如何有效地使用它。我的意思是,您使用 'vw' 来定义高度,而不是 'vh',这产生了奇迹但令人困惑,至少对于我的水平而言。
  • 我经常使用vw 来定义高度。当您的外部容器(对于您的情况是section)填充整个屏幕宽度时,它会起作用。如果没有,那么您需要使用 javascript 计算单元格高度
猜你喜欢
  • 2018-01-31
  • 2018-10-13
  • 2019-05-01
  • 2014-03-22
  • 1970-01-01
  • 2018-04-14
  • 2016-06-13
  • 1970-01-01
  • 2013-09-11
相关资源
最近更新 更多