0

I want to create a simple two-column layout using four divs. I am restricted and cannot modify the HTML structure. I only can modify the CSS.

I want the second div in the right column to fall directly below the previous right column div. Right now, it pushes to the top of the second left div.

Right now this is what I have in HTML:

<div id="parent">
    <div class="left">
        Left 1
    </div>
    <div class="right">
        Right 1
    </div>
    <div class="left">
        Left 2
    </div>
    <div class="right">
        Right 2
    </div>
</div>

CSS:

.left {
  height: 400px;
  width: 60%;
  float: left;
  background-color: red;
  display: block;
}
.right {

  width: 30%;
  float: right;
  background-color: green;
   display: block;
}

See my fiddle: http://jsfiddle.net/Lun61g7a/2/

2
  • I looked closer and can actually modify the parent's CSS, but i can't create separate divs for each column unfortunately. Ill modify my question to reflect this. Commented Oct 18, 2018 at 12:55
  • So I am stuck with a single parent encapsulating this all and can really only modify the CSS, not the HTML Commented Oct 18, 2018 at 12:57

1 Answer 1

1

Use a flexbox and allow the elements to move to the next "row" when needed

#parent {
  display: flex;
  flex-wrap: wrap;
}

.left {
  height: 400px;
  width: 60%;
  background-color: red;
  display: block;
}

.right {
  width: 30%;
  background-color: green;
  display: block;
}
<div id="parent">
  <div class="left">
    Left 1
  </div>
  <div class="right">
    Right 1
  </div>
  <div class="left">
    Left 2
  </div>
  <div class="right">
    Right 2
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

This looks closer, but I actually want the first right div to end at the end of the content and the 2nd right div to begin right below it. It is still pushing the 2nd right div all the way down

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.