Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tr / td height refuses to be 0

Tags:

html

css

I'm trying to do something very simple: get the height of a tr to 0px, but it won't work.

See the code or this JSFiddle for what I've tried.

HTML:

<table>
  <tbody>
    <tr>
      <td>
        Title 1
      </td>
      <td>
        Title 2
      </td>
    </tr>
    <tr class="model">
      <td>
        <input placeholder="Name">
      </td>
      <td>
        <input class="delete" type="checkbox">
      </td>
    </tr>
</table>

CSS:

.model, .model * {
  max-height: 0 !important;
  min-height: 0 !important;
  height: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-top: 0 !important;
  border-bottom: 0 !important;
  outline: 0 !important;
}

.model {
  background-color: red;
}

RESULT:

Result

There is red in the result, so the tr height is still not 0.

How can I get it to be 0, while maintaining the width?

EDIT: The issue seems to be the checkbox nested into the td. How can I get its height down to 0?

like image 363
Quelklef Avatar asked Jan 23 '16 05:01

Quelklef


People also ask

How do you fix tr height?

The height of rows 'tr' in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.

How do I fix td height in HTML?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.

How do you decrease the height of a table row?

Change row height To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.


3 Answers

I would add visibility: collapse; to tr to fix that

like image 178
Mohammad H Avatar answered Oct 29 '22 04:10

Mohammad H


Wrap it in a DIV, set it to not be tall enough, hide the overflow:

div {
 height: 1.2em;
 overflow: hidden;
}
like image 40
Nate Avatar answered Oct 29 '22 05:10

Nate


I know I'm late to the party, but I had the same problem with a Bootstrap 3 table. Looking in Chrome inspector, it looks like the bootstrap css selectors are very specific, so they seem to take precedence over my css unless I am even more specific. So while the following did not work:

tr.my-class td {
    height: 0;
    padding: 0;
    border-top: 0;
    overflow: hidden;
    line-height: 0;
    transition: all ease 0.5s;
}

tr.my-class.expanded td  {
    height: 20px;
    padding: 5px;
    border-top: 1px solid #ddd;
    line-height: 20px;
}

Changing it to this to mirror the Bootstrap selectors worked:

table>tbody>tr.my-class>td {
    height: 0;
    padding: 0;
    border-top: 0;
    overflow: hidden;
    line-height: 0;
    transition: all ease 0.5s;
}

table>tbody>tr.my-class.expanded>td  {
    height: 20px;
    padding: 5px;
    border-top: 1px solid #ddd;
    line-height: 20px;
}
like image 26
Dave Smash Avatar answered Oct 29 '22 03:10

Dave Smash