Cell border expanding total table's width - html

I need a table which spans the full width of the parent container.
The table's header cell cannot have any border while the data cell should.
The cell borders should be uniformly 1px wide on all 4 sides, which means that the border needs to collapse. When I have styled my table like this in CSS I notce that the total table width is 100% + 1px.
Could anyone help me and tell me what am I doing wrong?
* {
box-sizing: border-box;
}
div {
width: 200px;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
td,
th {
border: 1px solid #d3e0ee;
padding: 5px;
}
th {
border: 0px solid white;
padding: 6px;
}
<div>
<table>
<tr>
<th>Col 1</th>
<th>Col2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
</div>
Demo also at https://jsfiddle.net/fbwyx66o/4/ (try in Chrome)
Edit 1:
When the border is set to transparent (i.e. border: 1px solid transparent;) the overflow issue is gone but the browser still renders only half of the right hand side border. Please compare the th and td right border on the screenshot below:

It seems a Chrome bug when the render calculates the table size, it works in Firefox. Instead of removing border, make it transparent or use the same color as background.
th {
border-color: rgba(0, 0, 0, 0);
border-bottom-color: #d3e0ee;
padding: 6px;
}
I tried the style above and it works fine in Chrome.

To achieve expected result with border-collpase:collapse use below border for div
div {
width: 200px;
overflow-x: auto;
border:1px solid white;
}
code sample - https://jsfiddle.net/Nagasai_Aytha/fbwyx66o/41/
It seems to be Chrome bug ,as in other browsers it looks fine
Check this for more details - Table width 100% is off by a single pixel (depending on actual width)

Related

Does a table cell border count as part of its content?

The following document renders differently on Firefox and Chrome:
<!DOCTYPE html>
<html>
<head>
<title>Table rendering test</title>
<style>
table {
border-collapse: collapse;
border-spacing: 0;
padding: 0;
background-color: #ffffff;
border: 2px solid black;
}
table td {
border: 1px solid black;
padding: 5px;
}
tr.testRow > td {
border-left-width: 0;
border-right-width: 0;
padding: 0;
}
tr.testRow table {
border-color: #ff0000;
}
</style>
</head>
<body>
<table>
<tr>
<td>cell1.1</td>
<td>cell1.2</td>
<td>cell1.3</td>
</tr>
<tr class="testRow">
<td>cell2.1</td>
<td colspan="2">
<table>
<tr>
<td>internal table cell</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Firefox:
Chrome:
Note how Firefox does not count the bottom-right cell's border as part of its content, so the "internal table" renders 1 pixel to the right of the border of the above cell. Chrome, however, renders the "internal table" at the same horizontal location as the above cell's border.
Both of these browsers are operating in standards mode. Which browser is exhibiting the correct behaviour? And how can I modify the code so that they both exhibit the behaviour Chrome is giving (which is what I want)?
Which browser is exhibiting the correct behaviour?
Technically, both are behaving correctly.
They're each interpreting the specification in their own way and also have different ways of compiling and rendering a page to your screen.
How can I modify the code so that they both exhibit the behaviour Chrome is giving?
Using the CSS property box-sizing.
If you set this too border-box, it will always include padding and the border into the width of an element.
.box {
width: 200px;
height: 75px;
border: 5px solid black;
padding: 10px;
margin-bottom: 10px;
}
.with_sizing {
box-sizing: border-box;
}
<div class="box">This is a box with no box sizing</div>
<div class="box with_sizing">This is a box with box sizing</div>
Have a look at both of the above boxes and you will see that the top element only has the content at 200px and then adds the border and padding on top whereas the element below, which has box-sizing: border-box set will have the entire area set to 200px.

Chrome bug with colspan and border?

In the example below, there is a border on top of the right cell. It only appears in Chrome, is it a Chrome bug?
HTML / CSS
html,
body {
height: 100%;
}
table {
border-collapse: collapse;
width: 100%;
height: 100%;
}
.left {
border-right: 1px #aaaaaa solid;
border-top: 1px #aaaaaa solid;
}
<table>
<tr>
<td colspan=2>top</td>
</tr>
<tr>
<td class="left">left</td>
<td>right</td>
</tr>
</table>
Here is the example as a fiddle.
Chrome Screenshot
This appears to be the same bug listed here (or similar)
An easy workaround is at the bottom of this answer.
This is a relevant comment under that bug report:
It's a known (old) issue in our table code. Collapsing borders are
determined based on adjacent cells and our code doesn't deal correctly
with spanning cells (we only consider the cell adjoining the first row
/ column in a row / column span). On top of that, our border
granularity is determined by the cell's span.
To fix this bug, we would need to overhaul our collapsing border code,
which is a big undertaking.
Here is an example that highlights the same problem:
html,
body {
height: 100%;
}
table {
border-collapse: collapse;
width: 100%;
height: 100%;
}
.left {
border-right: 1px #aaaaaa solid;
border-top: 1px #aaaaaa solid;
}
.right {
border-top: double 20px #F00;
}
<table>
<tr>
<td colspan=2>top</td>
</tr>
<tr>
<td class="left">left</td>
<td class="right">right</td>
</tr>
</table>
I added this:
.right { border-top: double 20px #F00; }
Which results in this in Chrome:
That grey border would not be between the double red border if it was not a bug.
For comparison, this is how it should look (taken in Firefox):
Here are the rules of border conflicts:
Rule 1: You do not talk about border conflicts
The following rules determine which border style "wins" in case of a conflict:
Borders with the 'border-style' of 'hidden' take precedence over all other conflicting borders. Any border with this value suppresses all borders at this location.
Borders with a style of 'none' have the lowest priority. Only if the border properties of all the elements meeting at this edge are 'none' will the border be omitted (but note that 'none' is the default value for the border style.)
If none of the styles are 'hidden' and at least one of them is not 'none', then narrow borders are discarded in favor of wider ones. If several have the same 'border-width' then styles are preferred in this order: 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and the lowest: 'inset'.
If border styles differ only in color, then a style set on a cell wins over one on a row, which wins over a row group, column, column group and, lastly, table. When two elements of the same type conflict, then the one further to the left (if the table's 'direction' is 'ltr'; right, if it is 'rtl') and further to the top wins.
Workaround
Here is a workaround, just don't use border-collapse: collapse:
table {
border-collapse: separate; /* the default option */
border-spacing: 0; /* remove border gaps */
}
td {
padding: 20px;
border-right: solid 1px #CCC;
border-bottom: solid 1px #CCC;
}
td:first-child {
border-left: solid 1px #CCC;
}
table {
border-top: solid 1px #CCC
}
<table>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
table {
border-collapse: separate; /* the default option */
border-spacing: 0; /* remove border gaps */
}
td {
padding: 20px;
border-right: solid 1px #CCC;
border-bottom: solid 1px #CCC;
}
td:first-child {
border-left: solid 1px #CCC;
}
table {
border-top: solid 1px #CCC
}
Since its a Chrome-Bug let's think up a workaround. So far I only came up with one that involves changing the html:
http://jsfiddle.net/5366whmf/24/
It adds another row:
<table style="border-collapse: collapse">
<tr><td colspan=2>top</td></tr>
<tr><td style="height: 0"></td></tr> <!-- fix for chrome -->
<tr><td style="border-top: 1px solid red">left</td><td>right</td></tr>
</table>

Fancy border in a HTML table

So I am styling a table, and I'd like to make quite a fancy underline for the table headings.
I've though hard and had a look on the internet but couldn't find anything.
This is the table structure:
<table>
<thead>
<tr>
<td>Number</td>
<td>Name</td>
<td>Address</td>
</tr>
</thead>
<tbody></tbody>
</table>
And my current styling:
table {
width: 100%;
}
table thead {
font-weight: bold;
}
table thead td {
margin-right: 5px;
border-collapse: separate;
border-spacing: 10px 5px;
border-bottom: 2px solid #427AA8;
}
table tbody {
font-size: 90%;
}
table tbody tr {
line-height: 2em;
border-bottom: 1px solid #CCC;
}
table tbody td {
padding: 0 5px;
}
Here is a jsfiddle of the code: http://jsfiddle.net/tYA4e/1/
What I am looking for is a break in the border between the columns, but only in the thead.
And an example of what I am trying to achieve: http://i.imgur.com/OHrhJ.jpg
Is there a way to achieve this with some simple CSS?
A border will, necessarily, extend the full width of its element; therefore to extend a border only partially across the width of an element that border must be applied to a child element, sized accordingly.
That said, the only way this is achievable would seem to be with nesting an element within the td (in this case a span), and using the following CSS:
table thead td span {
display: inline-block;
width: 80%;
border-bottom: 2px solid #427AA8;
}
JS Fiddle demo.
As an aside, though, it's worth noting that, for table-headings, the th (table-heading) element might be more appropriate for your use in this case.
On further thought it is, of course, also possible to use styled hr elements, which allows you to give pixel-level control over the hr's width in that it can extend up to, in this example, 10px from the right edge of the parent td):
table thead td hr {
width: 80%;
margin: 0 10px 0 0;
border-bottom: 2px solid #427AA8;
}
JS Fiddle demo.
You could also use th for heading cells -> no more need for seperating the rows into groups with thead and tbody - less markup and less css.
<table>
<tr>
<th>headlinecell</th>
</tr>
<tr>
<td>contentcell</td>
</tr>
</table>
now just style the th and td.

Border messes up when using border-radius

Here is HTML:
<table>
<tr>
<td>Smth:</td>
<td>Lalala</td>
</tr>
</table>
Here is CSS:
table
{
border: 1px dotted black;
border-radius: 25px;
}
table td
{
padding: 15px;
}
When I use border-radius and border together, it messes up.
Is it possible to correct that? (I can't show it in jsFiddle, because border-radius doesn't work there)
table {border-collapse:separate;}
http://jsfiddle.net/seler/28p9W/

Space between two rows in a table?

Is this possible via CSS?
I'm trying
tr.classname {
border-spacing: 5em;
}
to no avail. Maybe I'm doing something wrong?
You need to use padding on your td elements. Something like this should do the trick. You can, of course, get the same result using a top padding instead of a bottom padding.
In the CSS code below, the greater-than sign means that the padding is only applied to td elements that are direct children to tr elements with the class spaceUnder. This will make it possible to use nested tables. (Cell C and D in the example code.) I'm not too sure about browser support for the direct child selector (think IE 6), but it shouldn't break the code in any modern browsers.
/* Apply padding to td elements that are direct children of the tr elements with class spaceUnder. */
tr.spaceUnder>td {
padding-bottom: 1em;
}
<table>
<tbody>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr class="spaceUnder">
<td>C</td>
<td>D</td>
</tr>
<tr>
<td>E</td>
<td>F</td>
</tr>
</tbody>
</table>
This should render somewhat like this:
+---+---+
| A | B |
+---+---+
| C | D |
| | |
+---+---+
| E | F |
+---+---+
In the parent table, try setting
border-collapse: separate;
border-spacing: 5em;
Plus a border declaration, and see if this achieves your desired effect.
Beware, though, that IE doesn't support the "separated borders" model.
You have table with id albums with any data... I have omitted the trs and tds
<table id="albums" cellspacing="0">
</table>
In the css:
table#albums
{
border-collapse:separate;
border-spacing:0 5px;
}
since I have a background image behind the table, faking it with white padding wouldn't work. I opted to put an empty row in-between each row of content:
<tr class="spacer"><td></td></tr>
then use css to give the spacer rows a certain height and transparent background.
From Mozilla Developer Network:
The border-spacing CSS property specifies the distance between the borders of adjacent cells (only for the separated borders model). This is equivalent to the cellspacing attribute in presentational HTML, but an optional second value can be used to set different horizontal and vertical spacing.
That last part is often overseen. Example:
.your-table {
border-collapse: separate; /* allow spacing between cell borders */
border-spacing: 0 5px; /* NOTE: syntax is <horizontal value> <vertical value> */
UPDATE
I now understand that the OP wants specific, seperate rows to have increased spacing. I've added a setup with tbody elements that accomplishes that without ruining the semantics. However, I'm not sure if it is supported on all browsers. I made it in Chrome.
The example below is for showing how you can make it look like the table exists of seperate rows, full blown css sweetness. Also gave the first row more spacing with the tbody setup. Feel free to use!
Support notice: IE8+, Chrome, Firefox, Safari, Opera 4+
.spacing-table {
font-family: 'Helvetica', 'Arial', sans-serif;
font-size: 15px;
border-collapse: separate;
table-layout: fixed;
width: 80%;
border-spacing: 0 5px; /* this is the ultimate fix */
}
.spacing-table th {
text-align: left;
padding: 5px 15px;
}
.spacing-table td {
border-width: 3px 0;
width: 50%;
border-color: darkred;
border-style: solid;
background-color: red;
color: white;
padding: 5px 15px;
}
.spacing-table td:first-child {
border-left-width: 3px;
border-radius: 5px 0 0 5px;
}
.spacing-table td:last-child {
border-right-width: 3px;
border-radius: 0 5px 5px 0;
}
.spacing-table thead {
display: table;
table-layout: fixed;
width: 100%;
}
.spacing-table tbody {
display: table;
table-layout: fixed;
width: 100%;
border-spacing: 0 10px;
}
<table class="spacing-table">
<thead>
<tr>
<th>Lead singer</th>
<th>Band</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bono</td>
<td>U2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Chris Martin</td>
<td>Coldplay</td>
</tr>
<tr>
<td>Mick Jagger</td>
<td>Rolling Stones</td>
</tr>
<tr>
<td>John Lennon</td>
<td>The Beatles</td>
</tr>
</tbody>
</table>
You may try to add separator row:
html:
<tr class="separator" />
css:
table tr.separator { height: 10px; }
You can't change the margin of a table cell. But you CAN change the padding. Change the padding of the TD, which will make the cell larger and push the text away from the side with the increased padding. If you have border lines, however, it still won't be exactly what you want.
Take a look at the border-collapse: separate attribute (default) and the border-spacing property.
First, you have to seperate them with border-collapse, then you can define the space between columns and rows with border-spacing .
Both of these CSS properties are actually well-supported on every browser, see here.
table {border-collapse: separate; border-spacing: 10px 20px;}
table,
table td,
table th {border: 1px solid black;}
<table>
<tr>
<td>Some text - 1</td>
<td>Some text - 1</td>
</tr>
<tr>
<td>Some text - 2</td>
<td>Some text - 2</td>
</tr>
<tr>
<td>Some text - 3</td>
<td>Some text - 3</td>
</tr>
</table>
Ok, you can do
tr.classname td {background-color:red; border-bottom: 5em solid white}
Make sure the background color is set on the td rather than the row. This should work across most browsers... (Chrome, ie & ff tested)
You need to set border-collapse: separate; on the table; most browser default stylesheets start at border-collapse: collapse;, which ditches border spacing.
Also, border-spacing: goes on the TD, not the TR.
Try:
<html><head><style type="text/css">
#ex { border-collapse: separate; }
#ex td { border-spacing: 1em; }
</style></head><body>
<table id="ex"><tr><td>A</td><td>B</td></tr><tr><td>C</td><td>D</td></tr></table>
</body>
You can use line-height in the table:
<table style="width: 400px; line-height:50px;">
tr {
display: block;
margin-bottom: 5px;
}
A too late answer :)
If you apply float to tr elements, you can space between two rows with margin attribute.
table tr{
float: left
width: 100%;
}
tr.classname {
margin-bottom:5px;
}
For creating an illusion of spacing between rows, apply background color to row and then create a thick border with white color so that a "space" is created :)
tr
{
background-color: #FFD700;
border: 10px solid white;
}
I stumbled upon this while struggling with a similar issue. I've found Varun Natraaj's answer to be quite helpful, but I would use a transparent border instead.
td { border: 1em solid transparent; }
Transparent borders still have width.
The correct way to give spacing for tables is to use cellpadding and cellspacing e.g.
<table cellpadding="4">
Works for most latest browsers in 2015. Simple solution. It doesn't work for transparent, but unlike Thoronwen's answer, I can't get transparent to render with any size.
tr {
border-bottom:5em solid white;
}
table { border-collapse: separate; border-spacing: 0 1em; }
Best way is to add <td> with a height attribute:
<td height="50" colspan="2"></td>
You can read more about colspan here.
In the following example, our table is green and our td with the height attribute is yellow:
<table style="background-color: green">
<tr>
<td>
<span>Lorem</span>
</td>
<td>
<span>Ipsum</span>
</td>
</tr>
<tr>
<td height="50" colspan="2" style="background-color: yellow"></td>
</tr>
<tr>
<td>
<span>Sit</span>
</td>
<td>
<span>Amet</span>
</td>
</tr>
</table>
Simply put div inside the td and set the following styles of div:
margin-bottom: 20px;
height: 40px;
float: left;
width: 100%;
you can do something like on your table :
table {
border-collapse: separate;
border-spacing: 0 15px;
}
table selective: as it will select all tables, so if you want to select single table you can do likewise
<table class="res">
</table>
For the above html you can do like this, note that for specific table if you want then you can use the below approach.
.res {
border-collapse: separate;
border-spacing: 0 15px;
}
Reference:https://www.w3docs.com/snippets/css/how-to-create-space-between-rows-in-the-table.html
You can fill the <td/> elements with <div/> elements, and apply any margin to those divs that you like. For a visual space between the rows, you can use a repeating background image on the <tr/> element. (This was the solution I just used today, and it appears to work in both IE6 and FireFox 3, though I didn't test it any further.)
Also, if you're averse to modifying your server code to put <div/>s inside the <td/>s, you can use jQuery (or something similar) to dynamically wrap the <td/> contents in a <div/>, enabling you to apply the CSS as desired.
I realize this is an answer to an old thread and may not be the solution requested, but while all the suggested solutions did not do what I needed, this solution worked for me.
I had 2 table cells, one with background color, the other with a border color. The above solutions remove the border, so the cell on the right would appear to be floating in mid-air.
The solution that did the trick was to replace the table, tr and td with divs and corresponding classes: table would be div id="table_replacer", tr would be div class="tr_replacer" and td would be div class="td_replacer" (change closing tags to divs as well obviously)
To get the solution for my problem the css is:
#table_replacer{display:table;}
.tr_replacer {border: 1px solid #123456;margin-bottom: 5px;}/*DO NOT USE display:table-row! It will destroy the border and the margin*/
.td_replacer{display:table-cell;}
Hope this helps someone.
The appearance of a row gap can be achieved by using a bottom border on the cells where there should be the next gap, i.e. border-bottom:solid white 5px;
Here is the code to create the screenshot:
<style>
table.class1 {
text-align:center;
border-spacing:0 0px;
font-family:Calibri, sans-serif;
}
table.class1 tr:first-child {
background-color:#F8F8F8; /* header row color */
}
table.class1 tr > td {
/* firefox has a problem rounding the bottom corners if the entire row is colored */
/* hence the color is applied to each cell */
background-color:#BDE5F8;
}
table.class1 th {
border:solid #A6A6A6 1px;
border-bottom-width:0px; /* otherwise borders are doubled-up */
border-right-width:0px;
padding:5px;
}
table.class1 th:first-child {
border-radius: 5px 0 0 0;
}
table.class1 th.last {
border-right-width:1px;
border-radius: 0 5px 0 0;
}
/* round the bottom corners */
table.class1 tr:last-child > td:first-child {
border-radius: 0 0 0 5px;
}
table.class1 tr:last-child > td:last-child {
border-radius: 0 0 5px 0;
}
/* put a line at the start of each new group */
td.newgroup {
border-top:solid #AAA 1px;
}
/* this has to match the parent element background-color */
/* increase or decrease the amount of space by changing 5px */
td.endgroup {
border-bottom:solid white 5px;
}
</style>
<table class="class1">
<tr><th>Group</th><th>Item</th><th class="last">Row</th></tr>
<tr><td class="newgroup endgroup">G-1</td><td class="newgroup endgroup">a1</td><td class="newgroup endgroup">1</td></tr>
<tr><td class="newgroup">G-2</td><td class="newgroup">b1</td><td class="newgroup">2</td></tr>
<tr><td>G-2</td><td>b2</td><td>3</td></tr>
<tr><td class="endgroup">G-2</td><td class="endgroup">b3</td><td class="endgroup">4</td></tr>
<tr><td class="newgroup">G-3</td><td class="newgroup">c1</td><td class="newgroup">5</td></tr>
<tr><td>G-3</td><td>c2</td><td>6</td></tr>
</table>
.table {
border-collapse: separate;
border-spacing: 0 1rem;
}
This works well for me to give a vertical margin/spacing between tables.
Reference: https://www.w3docs.com/snippets/css/how-to-create-space-between-rows-in-the-table.html
Modern solution involving display:grid with grid-gap.
A modern solution to create a table would be using CSS grid or flexbox.
To add space between rows and columns, one can use grid-gap: [vertical] [horizontal].
To prevent "too thick / double border" with zero grid-gap, one can add margin: -1px to the cell styling. Worth noticing: you will need this hack only if you have both borders and grid-gap of zero.
my-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px 0px;
}
my-item {
border: 2px solid #c60965;
background: #ffc000;
color: #c60965;
margin: -1px;
font-size: 20px;
display: flex;
justify-content: center;
align-items: center;
}
<my-grid>
<my-item>1</my-item>
<my-item>2</my-item>
<my-item>3</my-item>
<my-item>4</my-item>
<my-item>5</my-item>
</my-grid>
Space between columns is achieved in the same way. For example, 20px space between columns and 10px space between rows is done with this syntax: grid-gap: 10px 20px;.
Space inside rows / columns is achieved with paddings.
Tweakable demo
Below is an interactive demo, where you can tweak grid-gap, padding and turn on/off margin hack to see what changes.
Bonus: at the bottom you can find what code to insert for such behavior (regarding grid-gap, padding and margin hack)
<style>my-grid{display: grid; grid-template-columns: 1fr 1fr;}my-item{border: 2px solid #c60965; background: #ffc000; color: #c60965; margin: -1px; font-size: 20px; display: flex;}cus{font-family:Menlo; display:block; padding:7px; margin-top: 20px; border:3px dotted grey; border-radius:20px; font-size:14px;}set{display:flex; align-items:center;}dev-grid{display:grid; grid-template-columns: 1fr 1fr; margin:5px;}.hack{transform: scale(1.3); margin-top:13px; margin-left:5px;}txt:last-of-type{display:inline-block; margin-top:10px;}d{display:block; margin-top:10px; font-family: Menlo;}pre{padding:10px; background:rgb(246,246,246);}</style><my-grid> <my-item>Cell number one</my-item> <my-item>Cell number two</my-item> <my-item>Cell number three</my-item> <my-item>Cell number four</my-item> <my-item>Cell number five</my-item></my-grid><cus><dev-grid><txt>Space between rows:</txt><input type="range" min="0" max="20" value="0"><txt>Space between cols:</txt><input type="range" min="0" max="20" value="0"><txt>Padding (rows)</txt><input type="range" min="0" max="20" value="0"><txt>Padding (cols):</txt><input type="range" min="0" max="20" value="0"><txt>Margin hack:</txt><label> <input class="hack" type="checkbox" checked> <tt>on</tt></label></dev-grid></cus><d>Code to implement this:</d><pre></pre><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script>var values=[0,0,0,0],hack=0,props={grid:{dis:"display:grid;",cols:"grid-template-columns: 1fr 1fr;"},item:{}};function drawProps(){grid_props=Object.values(props.grid).map(p=>` ${p}`).join("\n"),item_props=Object.values(props.item).map(p=>` ${p}`).join("\n"),all_code=`my-grid{\n${grid_props}\n}`,""!=item_props&&(all_code+=`\nmy-item{\n${item_props}\n}`),$("pre").text(all_code)}props.item.hack="margin: -1px;",drawProps(),$("input[type=range]").on("input",function(){ind=($(this).index()-1)/2,values[ind]=$(this).val(),$("my-grid").css("grid-gap",`${values[0]}px ${values[1]}px`),$("my-item").css("padding",`${values[2]}px ${values[3]}px ${values[2]}px ${values[3]}px`),code_grid=`grid-gap: ${values[0]}px ${values[1]}px;`,values[0]==values[1]&&(code_grid=`grid-gap: ${values[0]}px;`,0==values[0]&&(code_grid="")),code_padding=`padding: ${values[2]}px ${values[3]}px ${values[2]}px ${values[3]}px;`,values[2]==values[3]&&(code_padding=`padding: ${values[2]}px;`,0==values[2]&&(code_padding="")),props.grid.gap=code_grid,props.item.padding=code_padding,""==props.grid.gap&&delete props.grid.gap,""==props.item.padding&&delete props.item.padding,drawProps()}),$(".hack").change(function(){hack=$(this).is(":checked"),st=hack?"on":"off",$("tt").text(st),hack?(props.item.hack="margin: -1px;",$("my-item").css("margin","-1px")):(props.item.hack&&delete props.item.hack,$("my-item").css("margin","0px")),drawProps()});</script>
Here's a simple and elegant solution, with a few caveats:
You can't actually make the gaps transparent, you need to give them a specific color.
You can't round the corners of the borders above & below the gaps
You need to know the padding and borders of your table cells
With that in mind, try this:
td {padding:5px 8px;border:2px solid blue;background:#E0E0E0} /* lets say the cells all have this padding and border, and the gaps should be white */
tr.gapbefore td {overflow:visible}
tr.gapbefore td::before,
tr.gapbefore th::before
{
content:"";
display:block;
position:relative;
z-index:1;
width:auto;
height:0;
padding:0;
margin:-5px -10px 5px; /* 5px = cell top padding, 10px = (cell side padding)+(cell side border width)+(table side border width) */
border-top:16px solid white; /* the size & color of the gap you want */
border-bottom:2px solid blue; /* this replaces the cell's top border, so should be the same as that. DOUBLE IT if using border-collapse:separate */
}
What you're actually doing is sticking a rectangular ::before block into the top of all the cells in the row you want preceded by a gap. These blocks stick out of the cells a bit to overlap the existing borders, hiding them. These blocks are just a top and bottom border sandwiched together: The top border forms the gap, and the bottom border re-creates the appearance of the cells' original top border.
Note that if you have a border around the table itself as well as the cells, you'll need to further increase the horizontal -ve margin of of your 'blocks'. So for a 4px table border, you'd instead use:
margin:-5px -12px 5px; /* 14px = original 10px + 2px for 'uncollapsed' part of table border */
And if your table uses border-collapse:separate instead of border-collapse:collapse, then you'll need to (a) use the full table border width:
margin:-5px -14px 5px; /* 14px = original 10px + 4px full width of table border */
... and also (b) replace the double-width of border that now needs to appear below the gap:
border-bottom:4px solid blue; /* i.e. 4px = cell top border + previous row's bottom border */
The technique is easily adapted to a .gapafter version, if you prefer, or to creating vertical (column) gaps instead of row gaps.
Here's a codepen where you can see it in action: https://codepen.io/anon/pen/agqPpW
Here this works smoothly:
#myOwnTable td { padding: 6px 0 6px 0;}
I suppose you could work out a more finely-grained layout by specifying which td if need be.
doing this shown above...
table tr{ float: left width: 100%; } tr.classname { margin-bottom:5px; }
removes vertical column alignment so be careful how you use it
Have you tried:
tr.classname { margin-bottom:5em; }
Alternatively, each td can be adjusted as well:
td.classname { margin-bottom:5em; }
or
td.classname { padding-bottom:5em; }