I have created these CSS classes:
.table-c {
border: 1px solid black;
width:100%;
height: 30px;
table-layout: fixed;
}
.table-c td {
border: 1px solid black;
padding: 10px;
}
And this table:
<table class="table-c">
<tr>
<td>REFERENCE NO.</td>
<td>DESCRIPTION</td>
<td>Invoice DATE</td>
<td>INVOICE AMOUNT</td>
<td>DISCOUNT TAKEN</td>
<td>AMOUNT PAID</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>CHECK DATA</td>
<td>CHECK NO.</td>
<td>PAYEE</td>
<td>DISCOUNT TAKEN</td>
<td>CHECK AMOUNT</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Table is fixed size as I wanted, but I also need to have different columns have different width. Those columns should not change with and always have it fixed. And also rows height should be fixed.
As in this example:
Here is my try:
http://jsfiddle.net/cbafseq6/
As you can see all columns have same width and all rows same height. If I would try for example set height on specific tr element (like style="height: 20px") all rows would still have same height.
If you want every row to have specific height and every column to have specific width, you can do something like the code below. I used your own code. You can tell me if that helps.
.table-c {
border: 1px solid black;
width:100%;
height: 30px;
table-layout: fixed;
}
.table-c td {
border: 1px solid black;
padding: 10px;
}
<table class="table-c">
<tr>
<td style="width: 10%">REFERENCE NO.</td>
<td style="width: 30%">DESCRIPTION</td>
<td style="width: 10%">Invoice DATE</td>
<td style="width: 10%">INVOICE AMOUNT</td>
<td style="width: 20%">DISCOUNT TAKEN</td>
<td style="width: 20%">AMOUNT PAID</td>
</tr>
<tr style="height: 200px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table class="table-c">
<tr>
<td style="width: 20%">CHECK DATA</td>
<td style="width: 10%">CHECK NO.</td>
<td style="width: 40%">PAYEE</td>
<td style="width: 10%">DISCOUNT TAKEN</td>
<td style="width: 20%">CHECK AMOUNT</td>
</tr>
<tr style="height: 200px">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Not sure the table element is what you want to go with.
Custom width of cells within columns would be available by using multiple tables (one for each row), perhaps, but a single table cannot have columns change width every row.
Maybe try a div layout.
Regarding the height set on tr - you chose a height too small, so there is no effect, a larger value would make the row larger. Again, because of table display settings this works differently and you should probably look for a different layout option.
Just use 2 tables:
table {
border: solid black;
border-width: 0 1px;
width: 100%;
height: 30px;
table-layout: fixed;
border-spacing: 2px;
margin-top: -2px; /* same value as border-spacing */
}
td {
border: 1px solid black;
padding: 10px;
}
table:first-child {
border-top-width: 1px;
margin-top: 0;
}
table:last-child {
border-bottom-width: 1px;
}
<div>
<table>
<tr>
<td>REFERENCE NO.</td>
<td>DESCRIPTION</td>
<td>Invoice DATE</td>
<td>INVOICE AMOUNT</td>
<td>DISCOUNT TAKEN</td>
<td>AMOUNT PAID</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table>
<tr>
<td>CHECK DATA</td>
<td>CHECK NO.</td>
<td>PAYEE</td>
<td>DISCOUNT TAKEN</td>
<td>CHECK AMOUNT</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
Honestly, even though tables are meant to display tabular data, I would go with a div layout here.
You can easily do this with a wrapper and some floated div and then you can do any and all customization you like to any of the "cells". Just my .02
Related
I want to make a table with 2 column at first and 3 column in the second row. The problem is, I cannot adjust them to my desired layout. I'm sorry if my question is hard to understand. I've attached a picture link for your reference.
table, td { border: 1px solid; }
<table>
<tr>
<td colspan="2"></td>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2"></td>
</tr>
</table>
the above picture is what I want.
That configuration is impossible using colspan unless there was a value of 1.5 for the top and bottom rows. But there is a way by nesting a <table> within a <td colspan='2'> in the middle row. Also, it's valid HTML.
* {
margin: 0;
padding: 0;
}
table {
table-layout: fixed;
width: 50%;
margin: 20px auto;
}
table,
td {
border: 1px solid;
border-spacing: 0.5px;
text-align: center;
}
td {
width: 50%;
}
table table {
table-layout: fixed;
width: 100%;
margin: 0;
border: 0;
}
table table td {
width: 33%;
}
<table>
<tbody>
<tr>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td colspan='2' style='border: 0'>
<table>
<tr>
<td>X</td>
<td>X</td>
<td>X</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>X</td>
<td>X</td>
</tr>
</tbody>
</table>
How can I best highlight a cell in a table, without taking up additional space. Just setting the background color is not good enough. (as it has to be a light color for the number/text to be readable).
CSS Outline would be OK if it could have rounded corners, but without them it doesn't have the same look/style as the rest of the document.
The best I have so far is putting a border around an absolute element positioned over the cell. But this requires the extra element, AND it's positioned OVER, not UNDER, so the color needs to have opacity, in case it is over text in adjacent cells.
<style>
td {
vertical-align:top; position:relative; text-align:right;
}
.bordered {
position: absolute;width:calc(100% + 20px)!important;left:-10px;top:-5px;border:6px rgba(255,0,0,0.7)solid;border-radius:8px;width:200%;
}
</style>
<body>
<table style="width: 100%">
<tr>
<td><span class="bordered"> </span>1 </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>12</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><span class="bordered"> </span>123</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>1234</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><span class="bordered"> </span>123456789</td>
</tr>
</table>
a) Can Outline have rounded corners?
b) Can above be done without the extra element?
c) Can above be positioned Under, rather than Over the cell?
Background:
I have an html app. that produces a 'Picking List' (for operatives to pick the right products for an Order. It has a 'Quantity' field which css highlights yellow when it's greater than ONE (but operatives don't notice it - and just despatch one (which is the usual qty).
css highlights with a background Yellow - if we use Red - it's difficult to read the number (which is in black).
No cross-browser issues as operatives just use Chrome internally.
Just make ALL of the TDs have a 1px transparent border, then on the selected ones set the color.
td {
border: 1px solid transparent;
vertical-align:top;
text-align:right;
}
.bordered {
border-color: red;
border-radius: 4px;
}
<table style="width: 100%">
<tr>
<td class="bordered"> 1 </td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>12</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="bordered"> 123</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>1234</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="bordered">  123456789</td>
</tr>
</table>
In relation to Julie's answer, you can actually have the best of both worlds if you also apply a border-radius. For instance:
td {
border: 0px solid transparent;
box-shadow: 0 0 5px red;
border-radius: 10px;
}
The border itself is invisible and takes no space, but the box-shadow will now follow the curve of the would-be border. You can adjust the box shadow params to make the outline hard or fuzzy.
If you can not take up ANY space then try this:
var btn = document.querySelector('#toggle');
btn.addEventListener('click', () => {
document.querySelectorAll('[a]').forEach(
el => {
el.classList.toggle('bordered');
}
);
});
td {
vertical-align:top;
text-align:right;
}
.bordered {
position: relative;
z-index: 1;
}
.bordered::before {
border: 4px solid rgba(255,0,0,.5);
border-radius: 4px;
bottom: -2px;
content: '';
left: -4px;
position: absolute;
right: -4px;
top: -2px;
z-index: -1;
}
<table style="width: 100%">
<tr>
<td a class="bordered"> 1 </td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>12</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td a class="bordered"> 123</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>1234</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td a class="bordered">  123456789</td>
</tr>
</table>
<button id="toggle">Toggle</button>
I an using the pseudo-element ::before to show the border. Like your example it is position: absolute and then I tie the top, left, right and bottom to the cell.
Click on the toggle button to see the adding and removal of the borders.
UPDATED
Based on your question I changed top, left, right and bottom to negative numbers to avoid overlap
You could use a box shadow as a border.
.bordered {
box-shadow: 0 0 5px red;
}
It's not rounded, but it doesn't look quite as boxy either.
This question already has answers here:
Splitting a table cell into two columns in HTML
(9 answers)
How to make one <td> span both columns in a two column table?
(3 answers)
Content of cell should take all row without changing columns width
(4 answers)
Closed 4 years ago.
I'm trying to create two columns in one <td> cell while leaving the rest of the table intact.
Here is a sample of what I'm trying to do
Here is a codepen with my table:
https://codepen.io/akamali/pen/XBVxxZ
I have tried to get it with colspan and add two columns <tr> inside but the result is always uneven. I also tried to add a table but did not look good at all. Any ideas?
Use colspan as follows:
.table {
width: 100%;
background-color: #ffffff;
border: 4px solid #979797;
}
.table td {
border-right: 2px solid #979797;
border-bottom: 4px solid #979797;
padding: 50px;
height: 10px;
}
.table td:nth-child(3n+0) {
border-right: 4px solid #979797;
}
.table td:last-child {
border-right: none;
}
.table tr:last-child td {
border-bottom: none;
}
<div>
<table class="table">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td colspan="3"></td>
<td colspan="3"></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
I tried using boxed elements but it is not coming in a proper way!
Any kind of help is highly appreciated
https://codepen.io/saisree/pen/EXXQGO - link to codepen
<table>
<tr>
<td class="text-center" colspan="4">Aircraft Status Display</td>
</tr>
<tr>
<td> spare</br>STBY</td><td><div class="vr"></div>
</td>
</tr>
<tr>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
<td style="width:80px;" ><p style="padding-top:20px;padding-bottom:20px;" class="boxed4 text-center"
><span class="br"></span></p>
</td>
</table>
Using colspan=n to make a column the width of n columns:
<table>
<tr>
<td></td><td colspan="6">this is wide column</td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td colspan="6">another wide column</td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
</table>
It's not completely clear from your image what you are trying to achieve, but if you mean the "half-open" cells, here is an example.
It uses col-spans to merge several cells into one, and different border settings: First a default setting for all cells (for borders on each side), the therse are overwritten by additional CSS rules that have special CSS selectors (with pseudo classes) to only affect certain cells:
table {
border-collapse: collapse;
width: 60%;
margin: 0 auto;
}
td {
border: 1px solid #333;
height: 40px;
}
tr:first-of-type > td {
border-bottom: none;
height: 20px;
}
tr:nth-of-type(2) > td {
border-top: none;
height: 40px;
}
tr:nth-of-type(4) > td:not(:first-child) {
border-bottom: none;
}
tr:nth-of-type(5) > td:not(:first-child) {
border-top: none;
}
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4" ;></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="4" ;></td>
</tr> <tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
I have a table with four columns and three rows. I want to add horizontal scroll on the table, but the first column should remain fixed.
My HTML is structured like this:
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
What CSS can I use to achieve this effect?
You could do two tables in separate divs. Check out this DEMO for an example.
CSS
#col-one {
float: left;
background-color: red;
}
#col-two {
float: left;
background-color: green;
}
HTML
<div id="col-one">
<table width="200px" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>abc</td>
</tr>
<tr>
<td>123</td>
</tr>
<tr>
<td>abc</td>
</tr>
</table>
</div>
<div id="col-two">
<table width="600px" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>123</td>
<td>abc</td>
<td>123</td>
</tr>
<tr>
<td>abc</td>
<td>123</td>
<td>abc</td>
</tr>
<tr>
<td>123</td>
<td>abc</td>
<td>123</td>
</tr>
</table>
</div>
Use display:table option to get it done with pure css and div.
HTML
<div class="table">
<div class="table_row">
<div >xzv</div>
<div>fjgj</div>
<div>gj g</div>
<div>gdj hk</div>
</div>
<div class="table_row">
<div >8080</div>
<div>7808</div>
<div>870g</div>
<div>80hk</div>
</div>
</div>
CSS
body{margin:20px}
.table{
display:table;
border-top:solid 1px red;
border-left:solid 1px red;
width:100%
}
.table_row{
display:table-row
}
.table_row div{
display:table-cell;
border-right:solid 1px red;
border-bottom:solid 1px red
}
DEMO