Hidden cells in html table causing larger row height - html

So I have an HTML Table that is acting as a summary table for a list of things I need to display. I have only 4 columns showing but there are approx. 20 and they're currently set to display: none;. The problem is those hidden cells are causing rows to be larger than the visible ones need. (I Would just delete the hidden ones but later functionality dictates that user's will need to be able to make those cells/columns visible)
Question: Is there a way to make the row's height as tall as the visible ones need (and nothing more) and adjust as cells/columns visibility change?
Current CSS:
table.grid {
border-collapse: collapse;
}
table.grid tr td {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
white-space: nowrap;
vertical-align: top;
}
table.grid tr td input {
display: block;
}
With this I've successfully eliminated the horizontal white-space between cells but I need to eliminate the vertical space now and I'm not sure how to overcome this little hiccup.

Try this on your hidden cells.
.class{
display:none;
line-height:0;
}

Related

why is my table row 0.4px wider then i set it to be?

I have looked around alot but i cant figure out what is going on here.
So i have a table with 2 td's on the first row.
left td has a image and should be h:200px and w:200px.
right td has some text and should be h:200px and w:430px.
So the total should be w:630px and h:200px but somehow if i inspect the tr its h:200px and w:630.4px so 0.4 too many which i cant figure out where its from.
i have the margin and padding set to 0px.
#logo {
height: 200px;
width: 200px;
display: inline-block;
}
#headerText {
height: 200px;
width: 430px;
background-color: #660066;
display: inline-block;
}
picture with inspecter: https://imgur.com/d4nVbq9
You need to add both your HTML and CSS codes so that we can see the result and inspect it. But from your explanation, I would say there are two things to consider:
If you want to control the size of a cell, you need to wrap the content in a div or other block elements.
Try adding overflow: hidden; and white-space: nowrap;to your table cell. Use either one that works for you.

Table Row Bottom Border "buckling" at certain window sizes

I am making a simple table to display information and wanted a border at the bottom of each row. I collapsed the borders to remove the space between the rows as to avoid the doubling of borders. And it works fine but when I adjust the screen size sometimes the border seems to break or buckle where it gets displaced slightly. I'm attaching an image of the phenomenon.
Here is the whole table as well:
And here is my CSS:
table{
border-collapse: collapse;
}
tbody{
width: 100% !important;
}
th{
width: 8%;
padding-left: 4%;
font-size: 1.5vw;
padding-top: 2%;
}
td{
width: 20%;
font-size: 1.5vw;
padding-top: 2%;
}
td ul {
width: 90%;
}
td ul li {
padding-top: 10%;
text-align: center;
padding-bottom: 10%;
}
tr{
border-bottom: solid 1px black !important;
}
Is there any way around this? Or is it more a matter of my content?
Your table row borders work only as a side-effect of conflict-resolution in the border-collapse algorithm. A table row is not meant to have borders, but since the style is applied, and borders are collapsed, the browser attempts to resolve any potentially conflicting styles by applying border styles of the parent to the respective cells it houses.
What's actually being rendered is a series of cells of slightly varying height, each with its own bottom border resolved from the value taken from the parent tr element.
One alternative might be to wrap the first row with a thead element and each successive row with a tbody element, and then set them to display: block with border-bottom.
You can work out some different solutions, but the main issue here is just a misunderstanding of how borders work on table elements, and the W3C link should help to sort that out.
At small sizes this table becomes impossible to read, so I'd also recommend that you read Richard Rutter on designing tables to be read, and also avoid using percentage and viewport-based units for font-size and padding.

border-spacing for inside borders only

I want my table cells to have a margin between them within same row, so I tried setting border-spacing: smth, but it also forces the left-most and right-most to have that same margin from table's outside border. Is it possible to avoid such scenario and apply spacing only between cells?
You can select the first and last td and reset their margins to 0.
td {
margin: 0 5px;
}
td:first-of-type, td:last-of-type {
margin: 0;
}

HTML table icons not sitting in a line

I have a tick based pricing table. Two of the ticks are not in vertical alignment with the other ticks.
For your convinence I've taken a print screen and highlited them:
The page itself is found here.
You could do this to avoid changing the style sheets. Although please do keep in mind that stylesheets are a better method to achieve this.
<td style="text-align: center !important; width: 145px !important;">
The 'width' property in table elements is not always respected by browsers and can lead to inconsistent behavior. Instead, use properties like 'min-width' and 'max-width' when trying to set table widths.
Ex.
table.header-features tr td {
text-align: center !important;
min-width: 33% !important;
max-width: 33% !important;
}
The problem is wheb you include a text "Restricted" inside td rather than the image with the green tick. You should set the width of td lower so that the green ticks are aligned
Just change this css
table.header-features tr td {
text-align: center !important;
width: 212px !important;
}
to this:
table.header-features tr td {
text-align: center !important;
width: 145px !important;
}

Text overflow in table with variable size

I was looking to implement the following design to the HTML/CSS.
I have got problems with the text overflow in the column. Currently the table column width is given in the percentage format so that the column width will change depending on the screen size, but there is a minimum width too. In the first text column, you can see that the content is extending and produced a second line due to the long size. How to avoid this problem using the text overflow? Or any other solution? Also, you can see that a set of icons are appearing in the same row when the mouse hover takes place. At this time, the text below the icons should hide and it should be shortened as shown in the design. Can you advise me to get a solution to this problem? I have tried text-overflow: ellipsis. But I'm getting problem when the screen width changes. Since I don't have a minimum width due to the variable column width, how to cut short the text in this field? Also in the hover case ??
Please let me know if you want to know anything else.
If you don't want the text to split in multiple rows, add white-space:nowrap rule.
Then, set a max-width for the cell.
For the icons, position them in absolute to the right, with a z-index higher then the text. You'll have to add a relative position to the containing cell also.
To keep them visible over text, i've added a background color (and some left padding).
EDIT: Fix for Mozilla
Mozilla seems to ignore position:relative; for td elements.
To fix it, you've to wrap the td contents inside another div, and apply this style
.tables td {
font-weight: 400;
font-size: 13px;
border-bottom: 1px solid #E1E1E1;
line-height: 38px;
text-align: right;
white-space: nowrap;
max-width: 200px; /* just an example */
}
.tables td > div {
overflow: hidden;
width:100%;
position: relative;
}
.linkFunctions {
display: none;
padding-top: 14px;
position: absolute;
right: 0;
z-index: 999;
background-color: #FFF9DC;
padding-left: 3px;
width: 100%;
max-width: 120px; /* just an example */
text-overflow: ellipsis;
overflow: hidden;
}
It's not exactly what you want (regarding the elipsis) but comes very close.
For the <a> inside the <td> add
td a{
display:block;
overflow:hidden;
width:100%;
white-space:nowrap;
}
(You might need to add a class to them to more easily target them and not ALL <a> inside <td>s).
And regarding the hover. Float the div.linkFunctions right, add the yellow background to it and it will look like it cuts the text accordingly.
All of those require a width to be set, which doesn't make tables fluid as they are intended to be. Use this: http://jsfiddle.net/maruxa1j/
That allows you to automatically set widths on <td> as percentages and the :after automatically sizes the overflowed <span>