0

I want to split container into three sections and it's already done but I can't figure out how to align all these sections vertically.

HTML:

<table width="100%">
<tbody>
    <tr>
        <td class="description">
            <div>
                <section class="col">
                    <h4>Description1</h4>
                    <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
                </section>
                <section class="col">
                    <h4>Description2</h4>
                    <div>blablalblablablalbla</div>
                </section>
                <section class="col">
                    <h4>Description3</h4>
                    <div>bl
                </section>
            </div>
        </td>
     </tr>
</tbody>

CSS:

.description {
    background: lightgrey;
}

.description .col {
    display: inline-block;
    width: 30%;
}

https://jsfiddle.net/kg4xao6m/

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Suprido
  • 525
  • 7
  • 17

2 Answers2

4

Use vertical-align: top in your CSS for the inline-block elements.

.description .col {
    display: inline-block;
    width: 30%;
    vertical-align: top;
}

JSFiddle

Liftoff
  • 24,717
  • 13
  • 66
  • 119
1

I agree with @David answer that is the way to align the sections vertically but you are also using a table that clearly has two <tr> with three <td> rather than one of each.

Semantically this is more appropriate:

table {
    background: lightgrey;
}

td {
    width: 30%;
    vertical-align: top;
}
<table width="100%">
  <tbody>
    <tr>
      <td>
        <h4>Description1</h4>
      </td>
      <td>
        <h4>Description2</h4>
      </td>
      <td>
        <h4>Description3</h4>
      </td>
    </tr>
    <tr>
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
      <td>blablalblablablalbla</td>
      <td>bl</td>
    </tr>
  </tbody>
</table>
smoggers
  • 3,154
  • 6
  • 26
  • 38
  • You are right but I didnt show the rest of implementation. I use a table with let's say 5 columns and 3 rows, the last row is supposed to be like in an example so the way to do it without creating another table in table is to do it with divs. – Suprido Sep 16 '15 at 13:42