2

I want to create an html table in the format below.

enter image description here

I am not able to find a way to do it. Can anyone help me?

Simon Scarfe
  • 9,378
  • 4
  • 28
  • 32
vaibhav shah
  • 4,939
  • 19
  • 58
  • 96

2 Answers2

5

I don't think you could have a fully cross-browser solution, anyway try this:

.verticalText {
  -webkit-transform: rotate(-90deg);
  -moz-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  -o-transform: rotate(-90deg);
  transform: rotate(-90deg);
  filter: progid: DXImageTransform.Microsoft.BasicImage(rotation=3);
}
<table border="1">
  <tbody>
    <tr>
      <td rowspan="4">
        <div class="verticalText">one</div>
      </td>
      <td>One</td>
      <td>Other</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Other</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Other</td>
    </tr>
    <tr>
      <td>One</td>
      <td>Other</td>
    </tr>
  </tbody>
</table>

In the HTML part, you use the attribute "rowspan" to tell the cell (td) to span over n rows; you have to remove the relative cell declaration in the subsequent "spanned" cell. The same works horizontally with the attribute "colspan". Default value of such attributes is 1, and it's implicit.

The CSS part try to render the text vertically as seen in your image, but it's not a CSS standard yet, so you have to try it in various browser. If you can't achieve fully compatibility, you might be forced to render that text by image, if text is not dynamic.

Edited HTML to include a container to text as indicated in comment.

Ruslan López
  • 4,433
  • 2
  • 26
  • 37
LittleSweetSeas
  • 6,786
  • 2
  • 21
  • 26
  • 1
    The text in the verticalText should be wrapped in a span, and define the CSS for the span inside (with `display:block`). Otherwise, with the current code, there might be weird effect since the whole cell is rotated (not just the text). – nhahtdh Dec 03 '12 at 09:55
  • I have tried this one but vertical column never fits the size of other columns – vaibhav shah Dec 03 '12 at 09:57
  • What do you mean by size? The height of the first td should be fine, maybe you have to adjust the text-align and vertical-align properties – LittleSweetSeas Dec 03 '12 at 10:19
  • In image you can see that height of first column is equal to sum of heights of four column of 2nd column. But if i do using above code then height of 1st column is much bigger than other column – vaibhav shah Dec 03 '12 at 10:33
2

Use rowspan check the DEMO HERE

You need to change the rowspan number when you add the new row.

Sowmya
  • 26,684
  • 21
  • 96
  • 136