Bootstrap 3 - Aligning column height

2019-03-03 18:13发布

问题:

create a site for educational purposes but I'm stuck with grid/column height issue.

Here's an image of site I'm trying to replicate: Click me

Here's what I've got so far: Click me

My problem is, on the first row I have two columns (col-sm-6) and on the first column I nested another row and created 2 additional columns within it. However, the second columns seems to be taller than the first one. I tried to adjust the img size but it loses the responsiveness that I need.

Hope someone understood what I'm trying to say, I'm really new to web development. I hope someone can help me out. :(

Please refer to the images attached to verify issue. Thanks.

My code -

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;
  }

回答1:

Here is a snippet, but I can't realize why are so huge gaps between columns.

Although look at https://jsfiddle.net/xeen9s7y/ - it works well.

I've added border: solid 1px red; to images for better visual control.

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 -->