Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rotate the text in a td and keep it center? [duplicate]

Tags:

I would like to do something like this but I'm not able to do it.

I know how to rotate the text with :

-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);

But I don't know how to keep it aligned in the center of the cell.

Could you help me?

like image 354
Erylis Avatar asked Dec 14 '16 11:12

Erylis


People also ask

How do you rotate text in selected cells 90 degrees?

Right-click and then select "Format Cells" from the popup menu. When the Format Cells window appears, select the Alignment tab. Then set the number of degrees that you wish to rotate the text. This value ranges from 90 degrees to -90 degrees for Orientation.

How do I rotate text in a table in HTML?

(I simplified the table a bit to allow me to focus on the part that does the vertical text.) The first trick is to use writing-mode: vertical-lr to get the text to run vertically. By itself, the text runs top to bottom, but we want it to run bottom to top, so we spin it around it with the transform: rotate(180deg) .

How do you rotate text in CSS?

If what you are looking for is a way to set type vertically, you're best bet is probably CSS writing-mode . The rotation property of Internet Explorer's BasicImage filter can accept one of four values: 0, 1, 2, or 3 which will rotate the element 0, 90, 180 or 270 degrees respectively.


1 Answers

Taken from: https://stackoverflow.com/a/27258573/6376949

.rotate {
  display: inline-block;
  filter: progid: DXImageTransform.Microsoft.BasicImage(rotation=3);
  -webkit-transform: rotate(270deg);
  -ms-transform: rotate(270deg);
  transform: rotate(270deg);
}
.tblborder,
.tblborder td,
.tblborder th {
  border-collapse: collapse;
  border: 1px solid #000;
}
.tblborder td,
.tblborder th {
  padding: 20px 10px;
}
<table class="tblborder">
  <tr>
    <th>
      <div class="rotate">header</div>
    </th>
    <th>
      <div class="rotate">header</div>
    </th>
    <th>
      <div class="rotate">header</div>
    </th>
  </tr>
  <tr>
    <td>
      <div class="rotate">detail</div>
    </td>
    <td>detail</td>
    <td>detail</td>
  </tr>
  <tr>
    <td>detail</td>
    <td>detail</td>
    <td>detail</td>
  </tr>
</table>
like image 76
T K Avatar answered Sep 24 '22 16:09

T K