Skip to content Skip to sidebar Skip to footer

Change Orientation To Vertical, Table Rows Html + Css

I have this table:
row1aaaa
row2

Solution 1:

If you are forced only to use CSS you can play with rotate :)

#table {
    transform:rotate(90deg);  
}
#tableth, #tabletd{
    transform:rotate(-90deg);
}
td {
  height: 50px;
}
<tableid="table"><tbody><tr><th>row1</th><td>aaaa</td></tr><tr><th>row2</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr><tr><th>row3</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr></tbody></table>

Solution 2:

This probably isn't the solution you're expecting, I would really encourage you to look at the new CSS Flexible Box Model instead of using HTML tables as it'll make your life much easier in these sort of scenarios.

If you're interested, take a look at my answer for a very similar question at Vertical Menu (+ Sub-Menu) stacks unnaturally.

Solution 3:

Use display: flex on your tbody and set an evenly divided flex-basis on your table rows.

body {
  font-size: 20px;
  font-family: monospace;
}
table {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
tbody {
  display: flex;
  width: 800px;
  position: relative;
  align-items: stretch;
  border: 1px solid black;
  
}
tr {
  flex-basis: 33.33333333%;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  padding: 5px10px;
 
  
}
tr + tr {
border-left: 1px solid black;
}

th, td {
  flex-basis: 100%;
  text-align: left;
  display: flex;
  padding: 2px;
  
}
th {
  font-weight: bold;
}
<tableid="tabla"><tbody><tr><th>row1</th><td>aaaa</td></tr><tr><th>row2</th><td>bbbb</td></tr><tr><th>row3</th><td>cccc</td><td><figure><imgsrc="https://via.placeholder.com/150"/></figure></td></tr></tbody></table>

CodePen: https://codepen.io/jeffdaley/pen/WmgNRb?editors=1100

Borders might give you some trouble, but this should put you on the right track.

Solution 4:

<tableid="tabla"><tbody><tr><th>row1</th><th>row2</th><th>row3</th></tr><tr><td>aaaa</td><td>bbbb</td><td>cccc</td></tr></tbody></table>

use this

Solution 5:

I wonder why everybody is complicating this question. The answer is simple and clear, If you follow the right format of html table you probably wouldn`t face that problem.

<tableid="tabla"><thead><thclass="rb">row1</th><thclass="rb">row2</th><th>row3</th></thead><tbody><tr><tdclass="rb">aaaa</td><tdclass="rb">bbbb</td><td>cccc</td></tr><tr><tdcolspan="2"class="rb"></td><td><figure><imgsrc="image.png"/></figure></td></tr></tbody></table>


  .rb{
      border-right: 1px solid #ccc;
   }

Just simple and basic like that...

Post a Comment for "Change Orientation To Vertical, Table Rows Html + Css"