Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Keep divs in columns aligned

I tried searching for what I was looking for, but I kept on finding things for css on internal divs.

Anyway, what I am trying to do is have two columns of divs be aligned with oneanother, with the right column always being aligned to the top of the left column. This is where I am drawing a blank, I can't seem to figure out how to do that.

The size of the left column is dynamic, so I can't use the :height property to keep things in order.

Here is what I am trying to do:

enter image description here

like image 220
sl133 Avatar asked Jan 07 '13 07:01

sl133


People also ask

How do I keep two side by side div elements the same height?

The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.

How do I align columns in CSS?

For aligning columns to the left, the align-content property will set to 'flex-start'. For aligning columns to the right, the align-content property will set to 'flex-end'. For aligning columns to the extreme ends, the align-content property will set to 'space-between'.

How do I make a div align?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.


2 Answers

What you could do is, wrap the inline div within a transparent div. For Example:

<div class="transparent-container">
    <div class="inline-div">
    </div>
    <div class="inline-div">
    </div>
    <div class="clearfix"></div>
</div>

Here is a working JSFiddle

like image 92
Amyth Avatar answered Sep 18 '22 03:09

Amyth


You can do this by three ways:

  1. Using a table:
<table>
    <tr>
        <td><div>div</div></td>
        <td><div>div</div></td>
    </tr>
    <tr>
       <td><div>div</div></td>
       <td><div>div</div></td>
    </tr>
</table>
  1. Using the container div like below:
<div class="outer-container">
    <div class="box-container">
        <div class="left-box">
            Left Box content
        </div>
        <div class="right-box">
            Right Box Content
        </div>
    </div>
</div>
  1. Using JS:

Calcuate the height by Js of left-box and and then pass that to right-box to maintain the gap.

like image 37
Rajnish Bakaria Avatar answered Sep 18 '22 03:09

Rajnish Bakaria