1

Basically I have to code this layout and not sure how to tackle it.

Here's the layout.

enter image description here

This won't work.

    <div class="container">
      <div class="row">
        <div class="col-md-4">
         text
        </div>
        <div class="col-md-8">
         image
        </div>
      </div>
   </div>

And this won't either.

    <div class="container-fluid">
      <div class="row">
        <div class="col-md-4">
         text
        </div>
        <div class="col-md-8">
         image
        </div>
      </div>
   </div>

There has to be a better way of handling this layout than typing many media queries for different breakpoint.

I'm using Bootstrap 4. CSS grid solution works too.

Thanks

shutupchigo
  • 703
  • 1
  • 7
  • 19

2 Answers2

0

This example isn't using Bootstrap 4 or CSS Grid, but hopefully you can use this as a proof of concept. I tried to make it as simple as possible.

Basically you just swap between a full-width grid and a regular grid, which I defined with .container and .container-full-width. You can change the values so they suit your needs.

JSFiddle Demo here

html,
body {
  margin: 0;
  padding: 0;
}

.section {
  width: 100%;
  height: auto;
}

.section:nth-child(even) {
  background: #9a9a9a;
}

.container {
  display: flex;
  max-width: 700px;
  margin: 0 auto;
}

.container--full-width {
  max-width: 2600px;
}

img {
  width: 100%;
  height: auto;
}

.half {
  width: 50%;
}
<div class="section">
  <div class="container">
      <div class="half">
         <img src="https://placekitten.com/1000/600" alt="">
      </div>
      <div class="half">
        <p>text</p>
      </div>
  </div>
</div>

<div class="section">
  <div class="container container--full-width">
      <div class="half">
         <img src="https://placekitten.com/1000/600" alt="">
      </div>
      <div class="half">
        <p>text</p>
      </div>
   
  </div>
</div>
Marc Hjorth
  • 1,797
  • 2
  • 18
  • 24
0

Is it what you are trying to achieve ?

.col-8{
  background:red;
}
.col-4{
  background:green;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">


  <div class="container">
      <div class="row">
        <div class="col-4">
           1/3
        </div>
        <div class="col-8">
           2/3
        </div>   
      </div>
   </div>

For more informations see Bootstrap - Grid system

Ced
  • 1,293
  • 5
  • 23
  • 34