I'm trying to compose a table in HTML; I found code to make the first line of the table in vertical text, but I have problems with the padding, or width, of columns.
I want them to be as wide as necessary for the second line (there will be more lines, but just for example), but it seems to have unnecessary padding. I tried with the column-width property in CSS, and with col width in my tpl (after I define table), but nothing works.
I want the column to be as wide as its longest input (in first and last column there will be words, in others will be numbers from 1 to 5). How can I do that?
And another thing: why does not first line align left, if I change text-align attribute in style to left?
This is what I have now and what I want to achieve:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<style>
.verticalTableHeader {
text-align:center;
white-space:nowrap;
transform-origin:50% 50%;
transform: rotate(-90deg);
}
.verticalTableHeader:before {
content:'';
padding-top:110%;/* takes width as reference, + 10% for faking some extra padding */
display:inline-block;
vertical-align:middle;
}
</style>
</head>
<body>
<br>
<center>
<table border="1">
<tr>
<th class="verticalTableHeader">Breed</th>
<th class="verticalTableHeader">Option 1</th>
<th class="verticalTableHeader">Option 2</th>
<th class="verticalTableHeader">Option 3</th>
<th class="verticalTableHeader">Option 4</th>
<th class="verticalTableHeader">Option 5</th>
<th class="verticalTableHeader">Option 6</th>
<th class="verticalTableHeader">Option 7</th>
<th class="verticalTableHeader">Option 8</th>
<th class="verticalTableHeader">Option 9</th>
<th class="verticalTableHeader">Option 10</th>
<th class="verticalTableHeader">Option 11</th>
<th class="verticalTableHeader">Option 12</th>
<th class="verticalTableHeader">Option 13</th>
<th class="verticalTableHeader">Option 14</th>
<th class="verticalTableHeader">Option 15</th>
<th class="verticalTableHeader">Option 16</th>
<th class="verticalTableHeader">Option 17</th>
<th class="verticalTableHeader">Option 18</th>
<th class="verticalTableHeader">Option 19</th>
<th class="verticalTableHeader">Option 20</th>
<th class="verticalTableHeader">Option 21</th>
<th class="verticalTableHeader">Option 22</th>
</tr>
<tr>
<td>American pitbull</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>26</td>
<td>Hunting dogs</td>
</tr>
</table>
</center>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
</body>
</html>