Remove border-spacing when there is no data in a table - html

I have an issue related to vertical whitespace in a table. I'm using the border-spacing CSS property to add some space between the table rows (to make them appear less-crammed).
Data is added dynamically in the table, so there can be the situation in which I have no data in the table (no trs) but there is some vertical whitespace due to the border-spacing property (which is currently border-spacing: 0px 10px).
Is there a possibility to fix this through CSS?
Fiddle example with data: http://jsfiddle.net/lav911/QLsah/
Fiddle example without data: http://jsfiddle.net/lav911/yWRS7/
I mention that the intended functionality would be not to display the table at all when there is no data in it.
Edit: Testing on Chrome.

You can use CSS :empty pseudo, and than use display: none;
table tbody:empty {
display: none; /* Than get rid of it */
}
Demo (No display: block; required there)
Still a small black dot remains, it is because of the border of your table element, since there's no way as of now to select the parent element using CSS, you cannot eliminate that without using jQuery, by selecting the parent element and applying border: 0;

like this
DEMO
table {
border-collapse:collapse;
}

CSS is not capable of knowing if selectors have content. Since you're adding it dynamically though, if there is no data present add a class to the table. something like:
<table class="empty"></table>
then, in your CSS, add:
table.empty {
display:none;
}
since you're using a framework that may or may not be editable, you can add this JS (using jQuery):
$(document).ready(function() {
if ($('table tr').length == 0) {
$('table').addClass('empty');
}
});

Related

Manipulating the css itself, for performance

My idea is to use JavaScript to change the HTML content of <style> tag, in order to manipulate elements.
Assuming a table with 20,000 cells, i want to hide those who has the hide and hide-me-too class, instead of getting all the elements - i'll add/remove the HTML content
.hide-me-too, .hide{display:table-cell/none;}
of a style element in the page.
what i ask is: should i expect problems with different brwosers? performance? any-other-issue?
If you will try to manipulate the CSSOM to control 20,000 cells you have a problem.
Better if you manipulate the DOM and change classnames.
The any-other-issue, and the most important, is if you have a table structure (<table><tr><td>) and you show cells with display:block you will crash all your layout. The correct display value for cells is display: table-cell. So don't make a single show() or hide() with jQuery, change the classnames so look like this:
.showme {
display: table-cell;
}
.hide,
.hide-me-too {
display: none;
}
And it's another any-other-issue, that you hide some cells, the columns will not match, so you need to play with colspan. Will be hard. Good luck.

Applying CSS Styles to an existing table that is constructed as a tree

Is it possible to apply a CSS style to an existing HTML table that is constructed as a tree?
For example, in Firefox, the Bookmarks Library table is constructed as a tree. Is it possible to apply a CSS style to one of the columns (but not the others)?
Using treechildren it is trivial to apply a style to an entire row. But how about applying a style to just one column?
CSS nth child should help you solve your problem.
https://developer.mozilla.org/en-US/docs/Web/CSS/%3Anth-child
Here's a quick example fiddle: https://jsfiddle.net/0gztemg6/
And the CSS from the above example:
td:nth-child(2) {
background-color: red;
}
Use treechildren:-moz-tree-cell-text(*property*), replacing property with the appropriate property name.
For example:
#placeContent > treechildren:-moz-tree-cell-text(placesContentTags) {
color: blue !important;
}
Will color the tags column blue.
Works perfectly.

No more tables and white-space issue

can you please let me know if there is any chance to make that the label wraps itself and do not go like in the picture ("Change Change Change..."):
I use "no more tables" here and always get that issue with longer labels - they just do not wrap. I understand that the white-space in css is "nowrap", but if I change it to "normal", everything goes wrong and displays badly. Maybe someone had an issue with this "no more tables" technique and word-wrapping?
More about this script can be fuonde here http://elvery.net/demo/responsive-tables/
That example uses absolute positioning to move the generated content to the start of the rows and is a flawed approach as that means that the content cannot wrap because it will overlap the content in the next row. That's why the nowrap rule is in place to stop this happening.
Instead of absolute positioning you could use display:inline-block instead and avoid the issue altogether.
In the code from here change these two rules as follows:
td {
border: none;
border-bottom: 1px solid #eee;
position: relative;
}
td:before {
display:inline-block;
vertical-align:top;
width: 45%;
padding:0 3% 0 1%;
}
Rough example here:
Updated code as per comments below:
td:before {
float:left;
width: 95%;
padding:0 0 0 1%;
margin-left:-100%;
}
td {
padding-left:50%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
You need to break the words if they are too long. You can make this in css as:
word-wrap:break-word;
Try it.
The main issue here has to do with sizing one HTML element based on another element. This is something that tables are optimized to do - calculating the height and width of TD elements across the entire table to a uniform size dynamically based on content.
By abandoning tables (via changing the display type of THEAD to "block", effectively making it nothing more than a DIV), you've lost this automatic resizing effect that browsers do for you, as evidenced here:
There's no getting around this. The "No More Tables" approach must make a compromise - use absolute height to mimic the way tables are laid out. You are trying to reintroduce this automatic size calculation, but you can't without restructuring your HTML.
If you want to continue to pursue this path, you'd need to "manually" handle resizing of the TD elements - iterate over the cells of the table and resize them yourself whenever the size of table might have changed. While possible, your Javascript won't be nearly as optimized as the browser and anything you implement yourself will likely be buggy and slow.
I'm afraid the only viable solution is to shorten your label names and accept the need for absolute sizing to get around the lack of dynamic sizing in non-TABLE elements.
One possible solution: show an abbreviated label and then show a longer name in a popup on hover or tap: Tooltips for mobile browsers

Is it possible to remove a table tag on a specific html location using only css

Is it possible to remove a table tag on a specific HTML location using only CSS? I have access only to the CSS file unfortunately.
I want to remove the image (which say "LOUIS INVESTORS RELATIONS") on the blue background here: http://louis.stockwatch.com.cy/nqcontent.cfm?a_name=fstatement&lang=en
It would be great if I could remove the whole table that contains that image.
Is it possible, and how?
Now use to this
table tr:first-child td:nth-child(2) img {
display: none;
}
Removing the whole table that contains that image means removing pretty much everything.
If you mean to remove the <td> that the image is within, that is possible, if you assume that no other <td> has an attribute with the background-color being set to #576f9c:
http://jsfiddle.net/YY98W/
table td[bgcolor="#576f9c"] { display: none; }

Removing styling from a table inside a table

I'm currently trying to use an HTML table with an HTML table, and I'm using the following CSS style for the outside table:
table.jobtable tr:nth-child(4n+1)
{
background-color: #65594D;
}
table.jobtable tr:nth-child(4n+3)
{
background-color: #3E362F;
}
I want to be able to make a table inside one of the rows without adopting it's background color. However, everything I seem to try results in the background color being adopted. Seems like such a trivial thing to be stuck on.
Any help appreciated.
Easy peasey:
table table {
background: none; /* Or whatever background you want */
}
You can use the > selector in css.
table.jobtable > tr:nth-child(4n+1)
{
background-color: #65594D;
}
This will only apply the style to tr elements that are direct children of table.jobtable, so it won't cascade down to the next table. [If you use a tbody tag, you'll need to do table.jobtable > tbody > tr:nth-child(4n+1).]
Assuming you're specifically setting the background color of the inner table (as I don't know of a CSS property value that will cause the selected elements to inherit the property's value from an element that is not the closest element in the chain that has the property set to a specific value) and you've already tried selecting the nested table as a child of the outer table (as per 3rror404's answer), you probably need to increase the specificity of the selector for the inner table.
http://www.w3.org/TR/selectors/#specificity
Here's the specificity calculations for CSS2.1 if you're working with an older browser: http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#specificity