So, I've hidden whole tables like this, which works fine:
<div style="display:none">
<table>
<tr><th>Test Table</th><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
</table>
</div>
But I want to hide just a group of rows like this:
<table>
<tr><th>Test Table</th><tr>
<div style="display:none">
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
</div>
</table>
But that doesn't work. Any hints?
Just apply the style attribute to the tr tag. In the case of multiple tr tags, you will have to apply the style to each element, or wrap them in a tbody tag:
<table>
<tr><th>Test Table</th><tr>
<tbody style="display:none">
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
</tbody>
</table>
Unfortuantely, as div elements can't be direct descendants of table elements, the way I know to do this is to apply the CSS rules you want to each tr element that you want to apply it to.
<table>
<tr><th>Test Table</th><tr>
<tr><td>123456789</td><tr>
<tr style="display: none; other-property: value;"><td>123456789</td><tr>
<tr style="display: none; other-property: value;"><td>123456789</td><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
</table>
If you have more than one CSS rule to apply to the rows in question, give the applicable rows a class instead and offload the rules to external CSS.
<table>
<tr><th>Test Table</th><tr>
<tr><td>123456789</td><tr>
<tr class="something"><td>123456789</td><tr>
<tr class="something"><td>123456789</td><tr>
<tr><td>123456789</td><tr>
<tr><td>123456789</td><tr>
</table>
Just set the display:none on the elements that you want to hide:
<table>
<tr><th>Test Table</th><tr>
<tr style="display:none"><td>1. 123456789</td><tr>
<tr><td>2. 123456789</td><tr>
<tr><td>3. 123456789</td><tr>
</table>
<style type="text/css">
.hidden { display:none; }
</style>
<table>
<tr><th>Test Table</th><tr>
<tr class="hidden"><td>123456789</td></tr>
<tr class="hidden"><td>123456789</td></tr>
<tr class="hidden"><td>123456789</td></tr>
</table>
And instead of:
<div style="display:none;">
<table>...</table>
</div>
you had better use:
...
Give all the rows you want to hide a class name that you can use for hiding. Use javascript to add/remove this class from the different rows.
<table>
<tr><th>Test Table</th><tr>
<tr class="toHide"><td>123456789</td><tr>
<tr class="toHide"><td>123456789</td><tr>
<tr class="toHide"><td>123456789</td><tr>
</table>
CSS:
.toHide
{
display: none;
}
You are not allowed to have div tags between tr tags. You have to look for some other strategies like creating a CSS class with display: none and adding it to concerning rows or adding inline style display: none to concerning rows.
.hidden
{
display:none;
}
<table>
<tr><td>I am visible</td><tr>
<tr class="hidden"><td>I am hidden using CSS class</td><tr>
<tr class="hidden"><td>I am hidden using CSS class</td><tr>
<tr class="hidden"><td>I am hidden using CSS class</td><tr>
<tr class="hidden"><td>I am hidden using CSS class</td><tr>
</table>
or
<table>
<tr><td>I am visible</td><tr>
<tr style="display:none"><td>I am hidden using inline style</td><tr>
<tr style="display:none"><td>I am hidden using inline style</td><tr>
<tr style="display:none"><td>I am hidden using inline style</td><tr>
</table>
Wrap the sections you want to hide in their own tbody and dynamically show/hide that.
Yes, you can hide only the rows that you want to hide. This can be helpful if you want to show rows only when some condition is satisfied in the rows that are currently being shown. The following worked for me.
<table>
<tr><th>Sample Table</th></tr>
<tr id="row1">
<td><input id="data1" type="text" name="data1" /></td>
</tr>
<tr id="row2" style="display: none;">
<td><input id="data2" type="text" name="data2" /></td>
</tr>
<tr id="row3" style="display: none;">
<td><input id="data3" type="text" name="data3" /></td>
</tr>
</table>
In CSS, do the following:
#row2{
display: none;
}
#row3{
display: none;
}
In JQuery, you might have something like the following to show the desired rows.
$(document).ready(function(){
if($("#row1").val() === "sometext"){ //your desired condition
$("#row2").show();
}
if($("#row2").val() !== ""){ //your desired condition
$("#row3").show();
}
});
Instead of using <div>, it would be better to use to provide the <tr> (which you want to hide) an id and then hiding it using javascript.
/* add javascript*/
{
document.getElementById('abc 1').style.display='none';
}
/* after that add html*/
<html>
<head>
<title>...</title>
</head>
<body>
<table border = 2>
<tr id = "abc 1">
<td>abcd</td>
</tr>
<tr id ="abc 2">
<td>efgh</td>
</tr>
</table>
</body>
</html>
you should add style="display:none" in any of <tr> that you want to hide.
Related
I have a table. The row of the table has checkbox and others control. I only want to print the row which the checkbox is check. I have searched the web and didn't find the solution. Hope someone can help me. thanks in advance
There is my css for pint
#pageTest .dgrd td input[type=checkbox]:checked+tr::before{
display: none;
}
There is my html:
<table>
<tr class="dgrdRed">
<td style="width: 140px;">
<span class="checkBoxClass"><input name="dgrd$ctl15$chkCheckBox" id="dgrd_ctl15_chkCheckBox" type="checkbox"></span>
</td>
<td>
<span id="dgrd_ctl15_lbl"><br>BOWEE</span>
</td>
</tr>
<tr class="dgrdRed">
<td style="width: 140px;">
<span class="inputCheckBox"><input name="dgrd$ctl16$chkCheckBox" id="dgrd_ctl16_chkCheckBox" type="checkbox"></span>
</td>
<td>
<span id="dgrd_ctl16_lbl"><br>BOLT</span>
</td>
</tr>
</table>
Use #media print CSS...
#media print {
#pageTest .dgrd td input[type=checkbox]:checked+tr::before{
display: none;
}
}
I’m trying to get my table row to have a different background color when I hover over it. So I included this in my stylesheet
table tbody tr:hover {
background-color: #F6F8F9
}
<table id="subscriptions-table">
<thead>
<tr>
<th>Subscription</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr class="even subscription-row header">
<td class="ig-header-title ellipsis">
<img src="/assets/s-icon-0d60471f901d65172728d3df0e793b2ee4493a529c1a1dca73409fdae56ad362.png" alt="S icon" />
<a class="name ellipsis" href="/scenarios/18">My #1 Scenario</a>
</td>
<td align="center">
<a href="/scenarios/18/download">
<img src="/assets/zip_icon-c2a0694959db12a0939d264d4283478c1f59a4b118df839d7020aca929a1df61.png" alt="Zip icon" />
</a>
</td>
</tr>
</tbody>
</table>
Here is the Fiddle that demonstrates the problem — https://jsfiddle.net/uwddax6j/ .
This works if you change the color to something different than the current background color.
Try this:
table tbody tr:hover {
background-color: green;
}
I'm trying to find a way, using CSS, to change the colspan on the base of a responsive table such as that found on a shopping cart. So what happens is, at lower resolutions, certain columns are trimmed off to preserve horizontal space. This leaves the col spanned rows "hanging" over the end, essentially preserving the original width, causing overflow situations. As we know, horizontal overflows on mobiles is a pain.
So is there a way, using CSS, to change the colspan of table rows? I already know how to do this with JS, using a listener frame, but I'm curious if there was some kinda CSS hack I could do instead. This would help to prevent a bit of FOUC.
Here is a fiddle example: https://jsfiddle.net/Dhaupin/5pv5qmru/3/
Here is the example table structure:
<table>
<thead>
<tr>
<td class="image">Image</td>
<td>Name</td>
<td>Model</td>
<td>Qty</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<tr>
<td class="image">-- img --</td>
<td>This Red Hat</td>
<td>HAT-RED-2384</td>
<td>2</td>
<td>$13.22</td>
</tr>
<tr>
<td class="total right" colspan="4">Subtotal:</td>
<td>$26.44</td>
</tr>
<tr>
<td class="total right" colspan="4">Shipping:</td>
<td>$6.65</td>
</tr>
<tr>
<td class="total right" colspan="4">Total:</td>
<td>$33.10</td>
</tr>
</tbody>
</table>
And some default CSS, hiding the "image" column at 640px or less:
table {
border-collapse: collapse;
}
td {
border: 1px solid grey;
padding: 4px;
width: 18%;
}
.right {
text-align: right;
}
#media (max-width: 640px) {
td.image {
display: none;
/* some kinda css hack here to "hide" without "hiding? */
}
td.total {
/* colspan 3 here? how do we make it span cleanly? */
}
}
Here is what full width looks like:
Here is what it looks like on smaller res, notice the overflow of colspan on bottom:
I know this is not the best solution
but css does not allow to change the native html table attribute value.
More information can be fount here:
HTML colspan in CSS
For better solution you can use js/ jquery
and change attribute colspan for td.total
#media (max-width: 480px) {
td.image {
position: absolute;
left: -99999px;
}
}
This solution doesn't CHANGE the colspans, but corrects colspan issues by adding cells (with different colspans) that show up in place of the hidden ones.
Here's your table with bootstrap styling. Note the opposing use of d-none and d-md-table-cell on the total header columns.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css">
<table class="table table-bordered">
<thead>
<tr>
<td class="image d-none d-md-table-cell">Image</td>
<td>Name</td>
<td>Model</td>
<td>Qty</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<tr>
<td class="image d-none d-md-table-cell">-- img --</td>
<td>This Red Hat</td>
<td>HAT-RED-2384</td>
<td>2</td>
<td>$13.22</td>
</tr>
<tr>
<td class="total text-right d-none d-md-table-cell" colspan="4">Subtotal:</td>
<td class="total text-right d-table-cell d-md-none" colspan="3">Subtotal:</td>
<td>$26.44</td>
</tr>
<tr>
<td class="total text-right d-none d-md-table-cell" colspan="4">Shipping:</td>
<td class="total text-right d-table-cell d-md-none" colspan="3">Shipping:</td>
<td>$6.65</td>
</tr>
<tr>
<td class="total text-right d-none d-md-table-cell" colspan="4">Total:</td>
<td class="total text-right d-table-cell d-md-none" colspan="3">Total:</td>
<td>$33.10</td>
</tr>
</tbody>
</table>
Suppose I have a table like so:
<table>
<tr>
<th>Type</th>
<th colspan="3">Type Info</th>
</tr>
<tr class="typeA">
<td><input name="type[0]" /></td>
<td class="group1"><input name="A[0]" disabled /></td>
<td class="group2"><input name="B[0]" disabled /></td>
<td class="group2"><input name="C[0]" disabled /></td>
</tr>
<tr class="typeB">
<td><input name="type[1]" /></td>
<td class="group1"><input name="A[1]" /></td>
<td class="group2"><input name="B[1]" disabled /></td>
<td class="group2"><input name="C[1]" disabled /></td>
</tr>
<tr class="typeC">
<td><input name="type[2]" /></td>
<td class="group1"><input name="A[2]" disabled /></td>
<td class="group2"><input name="B[2]" /></td>
<td class="group2"><input name="C[2]" /></td>
</tr>
</table>
There are certain data combinations that are not valid, so we disable the inputs. In this case, I believe the data makes semantic sense as a table - I am not just using a table for layout purposes.
What I would like to do is hide the disabled cells, and have the cells with the non-disabled elements fill the space formerly taken by the now hidden cells.
I can accomplish the hiding with the following css:
.typeA .group1, .typeA .group2 {
display:none;
}
.typeB .group2 {
display:none;
}
.typeC .group1 {
display:none;
}
However, this gives me:
|_____Type____|____________,__Type Info__,__________|
|_____________|
|_____________|____________|
|_____________|____________|_____________|
What I want is:
|_____Type____|____________,__Type Info__,__________|
|_____________|
|_____________|____________,_____________,__________|
|_____________|____________,_____________|__________|
(| represent cell boundaries, , represents where a single cell crosses the layout cell boundaries.
What css can I use to get the desired td to expand to fill the horizontal space vacated by the hidden td elements?
There does not appear to be a way to do this using solely CSS. It seems that to accomplish what I want, the html structure has to be modified in one way or another.
I found two options:
Do a row by row modification of the table structure, removing hidden td elements and adding appropriate colspan attributes to the visible td elements
Place all of the "group1" and "group2" inputs in the same cell, with additional div structures that can be styled as table cells.
For the second option, e.g.
<table>
<tr>
<th>Type</th>
<th>Type Info</th>
</tr>
<tr class="typeA">
<td><input name="type[0]" /></td>
<td>
<div class="group1">
<input name="A[0]" />
</div>
<div class="group2">
<div>
<input name="B[0]" />
</div>
<div>
<input name="C[0]" class="staticSize" />
</div>
</div>
</td>
</tr>
<tr class="typeB">
<td><input name="type[1]" /></td>
<td>
<div class="group1">
<input name="A[1]" />
</div>
<div class="group2">
<div>
<input name="B[1]" />
</div>
<div>
<input name="C[1]" class="staticSize" />
</div>
</div>
</td>
</tr>
<tr class="typeC">
<td><input name="type[2]" /></td>
<td>
<div class="group1">
<input name="A[2]" />
</div>
<div class="group2">
<div>
<input name="B[2]" />
</div>
<div>
<input name="C[2]" class="staticSize" />
</div>
</div>
</td>
</tr>
</table>
For the second option css, something like the following:
table {
width:100%;
}
.typeA .group1, .typeA .group2 {
display:none;
}
.typeB .group2 {
display:none;
}
.typeC .group1 {
display:none;
}
.typeC div.group2 {
display:table;
border-collapse:collapse;
}
.typeC div.group2>div {
width:100%;
display:table-cell;
}
input:not(.staticSize) {
width:100%;
box-sizing: border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing: border-box;
}
Try
visibility: hidden;
That should keep it in the layout.
I want the text inside my table to word-wrap. The constraint is that I can't change the HTML since it's generated by the server.
I created a JSFiddle
In case it's not working:
<div style="width: 25%">
<table class="af_selectManyCheckbox" id="pt1:r1:1:smc1" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="af_selectManyCheckbox_label" valign="top"/>
<td valign="top" class="AFContentCell" nowrap="">
<div class="af_selectManyCheckbox_content">
<div>
<span class="af_selectManyCheckbox_content-input">
<input class="af_selectManyCheckbox_native-input" type="checkbox" value="0"/>
</span>
<label class="af_selectManyCheckbox_item-text">It allows a component to partially refresh another component whose partialSubmit property is set to true.</label>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
Here you go.
WORKING DEMO
The CSS Code:
.col-md-3 label {
white-space: normal;
}
Hope this helps.