简体   繁体   中英

How to create a vertical column in a table using css

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

在此处输入图片说明

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

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.

Use rowspan check the DEMO HERE

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM