[英]tr / td height refuses to be 0
I'm trying to do something very simple: get the height of a tr
to 0px
, but it won't work.我正在尝试做一些非常简单的事情:将
tr
的高度设置为0px
,但它不起作用。
See the code or this JSFiddle for what I've tried.有关我尝试过的内容,请参阅代码或此 JSFiddle 。
HTML: 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: 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:结果:
There is red in the result, so the tr
height is still not 0.结果里面有红色,所以
tr
高度还是不为0。
How can I get it to be 0, while maintaining the width ?如何在保持宽度的同时使其为 0?
EDIT : The issue seems to be the checkbox
nested into the td
.编辑:问题似乎是嵌套到
td
中的checkbox
。 How can I get its height down to 0?我怎样才能把它的高度降到0?
I would add visibility: collapse;
我会增加
visibility: collapse;
to tr
to fix that tr
解决这个问题
Add font-size:0; margin:0;
添加
font-size:0; margin:0;
font-size:0; margin:0;
to the class上课
I know I'm late to the party, but I had the same problem with a Bootstrap 3 table.我知道我迟到了,但我在使用 Bootstrap 3 表时遇到了同样的问题。 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.
查看 Chrome 检查器,看起来引导 css 选择器非常具体,所以它们似乎优先于我的 css,除非我更具体。 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:将其更改为此以反映 Bootstrap 选择器的工作:
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;
}
Wrap it in a DIV
, set it to not be tall enough, hide the overflow
:将其包裹在
DIV
中,将其设置为不够高,隐藏overflow
:
div {
height: 1.2em;
overflow: hidden;
}
I just had a very similar problem - my solution was to set both height and max-height to s.th.我只是有一个非常相似的问题 - 我的解决方案是将高度和最大高度都设置为 s.th。 slightly above 0, like so
略高于0,像这样
height:0.01px; max-height:0.01px;
perhaps combined with也许结合
visibility:hidden;
No idea, why setting it to 0 does not work.不知道,为什么将它设置为 0 不起作用。 But, perhaps, using 0.01px instead of 0px ist still sufficient for you
但是,也许,使用 0.01px 而不是 0px ist 对你来说仍然足够
You need to set these as well if you'd like to keep the width.如果你想保持宽度,你也需要设置这些。
line-height: 0 !important;
visibility: hidden;
Combination of few other solutions:其他几种解决方案的组合:
td {
overflow: hidden;
line-height: 0;
}
if this don't have whole text and you have part if it showing up you can use:如果这没有完整的文本并且你有部分显示你可以使用:
<td><div>text</div></td>
and additionally:另外:
td div {
overflow: hidden;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.