As you can see in this fiddle, http://jsfiddle.net/S8Bne/64/, I am trying to draw a box shadow around the table (just the outside out it). The approach that I've taken is to create a div with slightly larger height than the thead area and give it a box shadow. However, I can't quite get it positioned properly. How can I do so?
Any solutions are welcome.
This is happening because your thead is not inside the div.
I added some height to the div to show...
Problem: http://jsfiddle.net/jasongennaro/S8Bne/54/
Add this
-webkit-box-shadow:#8A0000 2px 2px 10px;
box-shadow:#8A0000 2px 2px 10px;
to
.geniusPicks table tr#picksHeading th
And it works.
Working Example: http://jsfiddle.net/jasongennaro/S8Bne/55/
So no need for the div
If you want to add shadow to thead without using div, try the following code
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
table thead{
display:block;
position:relative;
box-shadow: 0px 1px 3px 0px #cccccc;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
table tr{
display:table;
table-layout:fixed;
width:100%;
}
<table>
<thead>
<tr>
<th>Company</th>
<th>Owner</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alfred Trading</td>
<td>Alfred Thomas</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Australia</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helena Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus</td>
<td>John Cook</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</tbody>
</table>
Related
I'm trying to set up a formatting class for tables on a wiki I'm building, and I've hit a wall on my very rudimentary CSS knowledge. Following online tutorials, I tried to create a .navbox class in the CSS sheet and alter settings for table, th, and td, but I hit an error message.
This is about as far as I got:
.navbox {
border: 2px solid black;
th {
background-color: gray;
}
}
Fandom's built-in compiler gave an error message on the "th" line saying "expected COLON at line 3, col 8", and another on the last line saying "unexpected token '}' at line 6, col 1".
I want to make this table: https://aeon14.fandom.com/wiki/Template:New_Canaan_system
...look something like this: https://memory-beta.fandom.com/wiki/Template:Ships_named_Enterprise
I see your using some SCSS syntax instead of CSS
Try this :
.navbox {
border: 2px solid black;
}
.navbox th {
background-color: gray;
}
Please check this code and implement it in your code and also change color value in CSS which you want.
#customers {
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}
#customers tr:nth-child(even){background-color: #f2f2f2;}
#customers tr:hover {background-color: #ddd;}
#customers thead th{
background-color: gray;
}
#customers tbody th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #d7d7d7;
color: white;
}
<table id="customers">
<thead>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<th>Alfreds Futterkiste</th>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<th>Berglunds snabbköp</th>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<th>Centro comercial Moctezuma</th>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<th>Ernst Handel</th>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<th>Island Trading</th>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<th>Königlich Essen</th>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<th>Laughing Bacchus Winecellars</th>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<th>Magazzini Alimentari Riuniti</th>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<th>North/South</th>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr>
<th>Paris spécialités</th>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</tbody>
</table>
Let's say I've a list of data in table.
Is there any way to achieve the below format using CSS?
I tried the below CSS but not the correct one:
table tr td:nth-child(2){ border-top: solid 1px #ccc; }
Here's my example
https://codepen.io/w3nta1/pen/QrzVgb
You could give a try to extend the border via an absolute pseudo element:
table {
border: none;
border-spacing:0;
width:200px;
overflow:hidden;/* hide pseudo overflowing */
}
table tr td + td {
border-top: solid 1px #ccc;
position:relative;/* make it the coordonates reference for the absolute positionned pseudo */
}
table tr td + td:before {
content:'';
position:absolute;
width:100%;
right:100%;
top:-1px;/* climb up the size of parent's border */
border-top: inherit;/* draw same border */
}
<table>
<tbody>
<tr>
<td>01</td>
<td rowspan="3">ABC</td>
</tr>
<tr>
<td>02</td>
</tr>
<tr>
<td>03</td>
</tr>
<tr>
<td>04</td>
<td>DEF</td>
</tr>
<tr>
<td>05</td>
<td>GHI</td>
</tr>
<tr>
<td>06</td>
<td rowspan="2">JKL</td>
</tr>
<tr>
<td>07</td>
</tr>
<tr>
<td>08</td>
<td>MNO</td>
</tr>
<tr>
<td>09</td>
<td>PQR</td>
</tr>
<tr>
<td>10</td>
<td rowspan="2">STU</td>
</tr>
<tr>
<td>11</td>
</tr>
<tr>
<td>12</td>
<td>VWX</td>
</tr>
<tr>
<td>13</td>
<td>YZ</td>
</tr>
</tbody>
</table>
https://codepen.io/gc-nomade/pen/wjRYqg
you can use only this css for look like you want table
table tr td + td {
border-top: solid 1px #ccc;
position:relative;
}
table tr td + td:before {
content:'';
position:absolute;
width:100%;
right:100%;
top:-1px;
border-top: solid 1px #ccc;
}
I'm trying to fill black color between vertical cell spacing(columns) of a table in html but can't figure it out how to do it. Here is my code
table,
th,
td {
border-collapse: separate;
border-spacing: 2px;
border-style: solid;
border-width: thin;
}
<table>
<tr>
<th>Heading One</th>
<th>Heading Two</th>
<th>Heading Three</th>
</tr>
<tr>
<td>Apple</td>
<td>10</td>
<td>$1.0</td>
</tr>
<tr>
<td>Mango</td>
<td>12</td>
<td>$2.0</td>
</tr>
</table>
Best way to do this would be to add a background color to the table and a foreground color to the fields. See below
table, th, td
{
border-collapse: separate;
border-spacing:2px;
border-style: solid;
border-width:thin;
}
table{background:#000;}
tr{background: #fff;}
<table>
<tr><th>Heading One</th>
<th>Heading Two </th>
<th>Heading Three </th>
</tr>
<tr>
<td>Apple</td>
<td>10</td>
<td>$1.0</td>
</tr>
<tr>
<td>Mango</td>
<td>12</td>
<td>$2.0</td>
</tr>
</table>
The space between the cells is the table. You change the background of the table in the same way as any other element.
Watch out, the default background colour of the table cells is transparent.
table,
th,
td {
border-collapse: separate;
border-spacing: 2px;
border-style: solid;
border-width: thin;
}
table {
background-color: black;
}
td, th {
background-color: white;
}
<table>
<tr>
<th>Heading One</th>
<th>Heading Two</th>
<th>Heading Three</th>
</tr>
<tr>
<td>Apple</td>
<td>10</td>
<td>$1.0</td>
</tr>
<tr>
<td>Mango</td>
<td>12</td>
<td>$2.0</td>
</tr>
</table>
From another approach, the border-collapse doesn't have to be separated, collapse value also works. The size of the border can be changed by changing the value of border-width.
table,
th,
td {
border-collapse: collapse;
border-width: 4px;
border-style: solid;
border-color: #000;
}
tr{background: #eee;}
<table>
<tr>
<th>Heading One</th>
<th>Heading Two</th>
<th>Heading Three</th>
</tr>
<tr>
<td>Apple</td>
<td>10</td>
<td>$1.0</td>
</tr>
<tr>
<td>Mango</td>
<td>12</td>
<td>$2.0</td>
</tr>
</table>
Updated on May 13th, 2021
As I have read through the book CSS Mastery Advanced Web Standards Solution, 3rd 3, the book has mentioned in ch9 that using border-collapse: collapse; can result empty spacing on vertical border using IE/Edge.
Add the below css and try,
table, th, td
{
border-collapse: separate;
border-spacing:2px;
border-style: solid;
border-width:thin;
background-color:White;
}
table
{
background-color:Black;
}
Firefox does not render table cell borders correctly when a table has an empty tbody.
But if you use the pseudo selector tbody:empty {display:none;} to hide the tbody element, everything is rendered as expected.
jsfiddle
table {
border-collapse: collapse;
}
th,
td {
border: 1px solid #000;
}
.fixed tbody:empty {
display: none;
}
<table class="broken">
<thead>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</tfoot>
</table>
<hr />
<table class="fixed">
<thead>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</tfoot>
</table>
It most likely belongs to Bug 409254 and Bug 217769 on Firefox.
Side note: Although an empty tbody is valid in HTML 5, but the number of the cells in each row group should be matched (except using colspan) in one table.
A workaround would be drawing the borders separately on both the table and cell elements.
table {
border-collapse: separate; /*changed from collapse*/
border-spacing: 0;
border: 1px solid;
border-width: 0 0 1px 1px; /*draw bottom and left borders*/
}
th,
td {
border: 1px solid;
border-width: 1px 1px 0 0; /*draw top and right borders*/
}
jsfiddle
Is it possible with css3 to apply borders on table, tr, td so it would look like it is drawn by hand similar to:
Currently, I'm trying like the following but which results in space between tds:
table{
border-collapse: collapse;
}
td{
background: url(http://i.stack.imgur.com/ojaEj.png) no-repeat;
background-size: 100% 100%;
padding: 20px;
}
<table>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
</table>
So, is there a way so I can use different borders on top right bottom and left of the tds?
You could do that by carefully crafting a table with no borders or background (so it's transparent) and using your hand-drawn graphic as a background.
If you design the background to be repeating (seamless) your table could even be dynamic.
table {
background: url(http://i.stack.imgur.com/idN4k.jpg) -10px -15px repeat;
}
table td {
padding: 20px 10px;
}
<table>
<tr>
<td width="37">one</td>
<td width="42">two</td>
<td width="42">three</td>
<td width="42">four</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
<td>four</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
<td>four</td>
</tr>
</table>
http://jsfiddle.net/nhur0uu0/
This could also be achieved with custom svg, but I would want to know more about what you are going for before I recommended it.
You might be able to achieve something like that with border-images and applying different border images to every Nth cell with the :nth-child selectors on both rows and columns, maybe with some prime numbers thrown in to obscure repetition.
This will require border-collapse:separate tables, so you'll also want zero border spacing.
The images will have to line up properly at the corners though, so the lines can't be quite as crooked as in your example
You could try setting negative margins as I did here.
table {
border-collapse: collapse;
}
td {
background: url(http://i.stack.imgur.com/ojaEj.png) no-repeat;
background-size: 100% 100%;
padding: 20px;
margin: -9px -8px;
display: inline-block;
}
tr {
display: block;
}
tr:nth-child(2) {
margin-left:4px;
}
tr:nth-child(3) {
margin-left:8px;
}
<table>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
</table>
Not too pretty, but it works.