I would like to have the cells of my table left aligned but at the same time autofit.
Example:
thead td {
background-color: yellow;
}
td {
border:1px solid #000;
}
<br/>
<p>
First table
</p>
<br/>
<table style="width: 100%;">
<thead>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column with some additional text (blah blah blah blah blah)</td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
<br/>
<p>
Second table
</p>
<br/>
<table style="width: 100%;">
<thead>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column</td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
on the second table we clearly see that each cells are equal width.
This is not what I wanted.
I want to have each cells side by side without extra space between.
Extra space should be on the right.
Edit: an image of what I want:
Edit: if you don't want multilines in column use
white-space:nowrap; in `td` css
use :nth-last-child in your CSS to make it 100% in width
thead td {
background-color: yellow;
}
td {
border:1px solid #000;
}
thead td:nth-last-child(1){
width:100%;
}
<table style="width: 100%;">
<thead>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column </td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
try it help full
thead td {
background-color: yellow;
}
td {
border:1px solid #000;
}
thead td:last-child{
width:100%;
}
<br/>
<p>
First table
</p>
<br/>
<table style="width: 100%;">
<thead>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column with some additional text (blah blah blah blah blah)</td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
<br/>
<p>
Second table
</p>
<br/>
<table style="width: 100%;">
<thead>
<tr>
<td>Title 1</td>
<td>Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column</td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
i have add some css
thead td:last-child{
width:100%;
}
Do you mean something like that?
<table style="width: 100%;">
<thead>
<tr>
<td style="width: 150px;">Title 1</td>
<td style="width: 150px;">Title 2</td>
<td>Title 3</td>
</tr>
</thead>
<tr>
<td class="block">First column</td>
<td class="block">Second column</td>
<td class="block">Third column</td>
</tr>
</table>
Related
I need to make a table with more tables, but i dont know how to put this tables inside
It should look like this
i need to do this without CSS
I have tried something...well it turns out like this
I don't understand how to make it
This is a HTML lesson for tables as well as colspan and rowspan attributes:
<body>
<table>
<td>spaltenweise</td>
<td>
<table>
<td colspan="4">A04_03a</td>
<tr>
<td>Spale 1</td>
<td>Spalte 2</td>
<td>Spalte 3</td>
<td>Spalte 4</td>
</tr>
<tr>
<td colspan="4">Spalte 1+2+3+4</td>
</tr>
</table>
</td>
<td>
<table>
<td colspan="4">A04_03b</td>
<tr>
<td>Spale 1</td>
<td>Spalte 2</td>
<td>Spalte 3</td>
<td>Spalte 4</td>
</tr>
<tr>
<td colspan="2">Spalte 1+2</td>
<td colspan="2">Spalte 3+4</td>
</tr>
</table>
</td>
<td>
<table>
<td colspan="4">A04_03c</td>
<tr>
<td>Spalte 1</td>
<td>Spalte 2</td>
<td>Spalte 3</td>
<td>Spalte 4</td>
</tr>
<tr>
<td colspan="1">Spalte 1</td>
<td colspan="3">Spalte 2+3+4</td>
</tr>
</table>
</td>
<tr>
<td>zeilenweise</td>
<td>
<table>
<tr colspan="3">A04_03d</tr>
<tr>
<td>Zeile 1</td>
<td rowspan="4">Zeile 1+2+3+4</td>
</tr>
<tr>
<td>Zeile 2</td>
</tr>
<tr>
<td>Zeile 3</td>
</tr>
<tr>
<td>Zeile 4</td>
</tr>
</table>
</td>
<td>
<table>
<tr colspan="3">A04_03e</tr>
<tr>
<td>Zeile 1</td>
<td rowspan="2">Zeile 2+3</td>
</tr>
<tr>
<td>Zeile 2</td>
</tr>
<tr colspan="3"></tr>
<tr>
<td>Zeile 3</td>
<td rowspan="2">Zeile 2+3</td>
</tr>
<tr>
<td>Zeile 4</td>
</tr>
</table>
</td>
<td>
<table>
<tr colspan="3">A04_03f</tr>
<tr>
<td>Zeile 1</td>
<td>1</td>
</tr>
<tr>
<td>Zeile 1</td>
<td rowspan="3">Zeile 2+3+4</td>
</tr>
<tr>
<td>Zeile 3</td>
</tr>
<tr>
<td>Zeile 4</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<table>
<tr>
<td style="border:1px solid black;">
Spaltenweise
</td>
<td style="border:1px solid black;">
<table>
<tr>
<td style="border:1px solid black;">
A04
</td>
</tr>
<tr>
<td style="border:1px solid black;">
100
</td>
<td style="border:1px solid black;">
200
</td>
<td style="border:1px solid black;">
300
</td>
</tr>
<tr >
<td colspan=3 style="border:1px solid black;">
spalte 1 2 3 4
</td>
</tr>
</table>
</td>
</tr>
</table>
I have a table.
<table style="margin-left: 20px" class="tg">
<tbody>
<tr>
<td class="tg- 0lax">Question 1</td>
</tr>
<tr>
<td class="tg-0lax">Answwer 1</td>
</tr>
<tr>
<td class="tg- 0lax">Question 2</td>
</tr>
<tr>
<td class="tg- 0lax">Answer 2</td>
</tr>
I want the margin between the question 1 and the answer 1 2px. And the margin between the answer 1 and question 2 , 10 px. I cant get i done. I did try the following things: style="margin-bottom / margin-top in the and , al well as padding 2px. But both doesnt work
<td></td> and <tr></tr> cant be given a margin. Although you can give them a padding when you set display: block; Then you can go on an set things like every second one should get a bigger padding at the bottom (as you wanted it). Here is a snippet with very basic styles:
tr {
display: block;
}
tr:nth-child(even) {
padding-bottom: 20px;
}
tr:nth-child(odd) {
padding-bottom: 2px;
}
<table>
<tbody>
<tr>
<td>Question 1</td>
</tr>
<tr>
<td>Answer 1</td>
</tr>
<tr>
<td>Question 2</td>
</tr>
<tr>
<td>Answer 2</td>
</tr>
</tbody>
</table>
Set border-spacing property 2px to the table, and then skip 5 rows to get 10px something like this:
<table style="margin-left: 20px;border-spacing: 2px;" class="tg">
<tbody>
<tr>
<td class="tg- 0lax" >Question 1</td>
</tr>
<tr>
<td class="tg-0lax">Answwer 1</td>
</tr>
<tr>
<td class="tg-0lax"></td>
</tr>
<tr>
<td class="tg-0lax"></td>
</tr>
<tr>
<td class="tg-0lax"></td>
</tr>
<tr>
<td class="tg-0lax"></td>
</tr>
<tr>
<td class="tg- 0lax">Question 2</td>
</tr>
<tr>
<td class="tg- 0lax">Answer 2</td>
</tr>
I have 2 tables in same row of the big table, like this:
<table>
<tr>
<td>Type</td>
<td>Storage 1</td>
<td>Storage 2</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>Type A</td>
</tr>
<tr>
<td>Type B</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>10%</td>
</tr>
<tr>
<td>90%</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>40%</td>
</tr>
<tr>
<td>60%</td>
</tr>
</table>
</td>
</tr>
<table>
But when the text in first column (e.g. "Type A") is too long, it makes a new line. Then data in same row is not in same row. ("Type B" is not in same row with "90%" and "60%")
Return data is in xml format, like this:
<DataGroup Storage="Storage 1">
<DataRow Type="Type A" Percentage="10%"/>
<DataRow Type="Type B" Percentage="90%"/>
</DataGroup>
<DataGroup Storage="Storage 2">
<DataRow Type="Type A" Percentage="40%"/>
<DataRow Type="Type B" Percentage="60%"/>
</DataGroup>
I have to draw borders to make it look like one table. Render in cshtml file.
How can I resolve this? Many thanks.
You can add the border: 1px solid black; to CSS to make it like a table. For HTML, you just need one table.
table,
th,
td {
border: 1px solid black;
}
<table>
<tr>
<td>Type</td>
<td>Storage 1</td>
<td>Storage 2</td>
</tr>
<tr>
<td>Type A
<br>new line</td>
<td>10%</td>
<td>40%</td>
</tr>
<tr>
<td>Type B</td>
<td>90%</td>
<td>60%</td>
</tr>
</table>
You can stop word-wrap with white-space: nowrap; although it stops honoring the width element.
tr td:nth-child(1){
width:20px;
color:red;
white-space: nowrap;
}
<table>
<tr>
<td>Type</td>
<td>Storage 1</td>
<td>Storage 2</td>
</tr>
<tr>
<td>Type A</td>
<td>10%</td>
<td>40%</td>
</tr>
<tr>
<td>Type B</td>
<td>90%</td>
<td>60%</td>
</tr>
<table>
I'm assuming, you have a good reason for having tables within table. Then your problem is your semantics. You are not outputting the 'Type B', '90%' and '60%' on the same rows of the big table. Your sub-tables can either be aligned by vertical-align as blocks or you need to rework your big table semantics to something like this.
<table class="big">
<tr>
<td>Type</td>
<td>Storage 1</td>
<td>Storage 2</td>
</tr>
<tr>
<td>
<table class="small">
<tr>
<td>Type A Lorem ipsum</td>
</tr>
</table>
</td>
<td>
<table class="small">
<tr>
<td>10%</td>
</tr>
</table>
</td>
<td>
<table class="small">
<tr>
<td>40%</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="small">
<tr>
<td>Type B</td>
</tr>
</table>
</td>
<td>
<table class="small">
<tr>
<td>90%</td>
</tr>
</table>
</td>
<td>
<table class="small">
<tr>
<td>60%</td>
</tr>
</table>
</td>
</tr>
<table>
I have the code below:
tbody > tr:hover{
background-color: lightgrey;
cursor: pointer;
}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td >$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td >$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>
How can I highlight the whole row when I hover to the row.
For example, when I hover to January, it should highlight the whole January row instead of highlight only the half one because of the rowspan attribute.
Move the styling to the td under the hovered tr. In addition, highlight the sibling row, when the 1st row is hovered. The only caveat is that if the 2nd tr is hovered, it won't highlight the 1st cell.
tr:hover > td {
background-color: lightgrey;
cursor: pointer;
}
tr:nth-child(2n + 1):hover + tr {
background-color: lightgrey;
}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td>$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td>$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>
tr:hover td:not([rowspan]) {background: red;}
tr:hover td[rowspan]:hover ~ td {background: none;}
tr:hover td[rowspan]:hover {background: yellow;}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td >$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td >$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>
I have header line on my page and then I have a table displayed on the page. I want that header line and top row of the table to be freezed and rest the of the table to be scrollable. My table is without <THEAD> element and also I tried using positon:fixed to freeze the header line and top row of table but only top row is fixed. How can I freeze header line as well?
TIA
Code:
<div id="topheader">
<h1> This is header line </h1>
</div>
<table ellspacing="0" cellpadding="10" border="1" width="100%" STYLE="empty-cells:show; position:fixed; top:300px;" id="reporttable" >
<tr class="header">
<td align="left">
Field1
</td>
<td align="left">
Field2
</td>
<td align="left">
Field3
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="10" border="1" width="100%" STYLE="empty-cells:show;" id="reporttables">
<tr class="tbody" >
<td>
Data1
</td>
<td>
Data2
</td>
<td>
Data3
</td>
</tr>
</table>
</div>
CSS:
<style>
div.topheader{
position:fixed;
top:200px;
}
</style>
As far as I know, you cannot do this with just one table element.
A good way to approach this is to create 2 tables and use the table-layout: fixed property on the tables and then set a fixed width on td and th.
Check this Demo or the code snippet below.
div.div-demo {
height: 60px;
overflow-y: scroll;
}
table.demo {
table-layout: fixed;
border: 1px solid black;
}
table.demo td, th {
width: 80px;
text-align: left;
}
<table class="demo">
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</table>
<div class="div-demo">
<table class="demo">
<tr>
<td>Content 1</td>
<td>Content 2</td>
<td>Content 3</td>
</tr>
<tr>
<td>Content 1</td>
<td>Content 2</td>
<td>Content 3</td>
</tr>
<tr>
<td>Content 1</td>
<td>Content 2</td>
<td>Content 3</td>
</tr>
<tr>
<td>Content 1</td>
<td>Content 2</td>
<td>Content 3</td>
</tr>
</table>
</div>