admin管理员组文章数量:1333430
I have a HTML structure like this:
li{
list-style: none;
border-bottom: 1px solid;
padding:4px;
}
div{
background-color: #eee;
padding: 6px 0;
}
<ul>
<li>
<span>something</span>
<div></div>
</li>
<li>
<span>something</span>
<div>something else</div>
</li>
</ul>
I have a HTML structure like this:
li{
list-style: none;
border-bottom: 1px solid;
padding:4px;
}
div{
background-color: #eee;
padding: 6px 0;
}
<ul>
<li>
<span>something</span>
<div></div>
</li>
<li>
<span>something</span>
<div>something else</div>
</li>
</ul>
And this is expected result:
I guess I can do that by JS, something like this:
if ( $('div').val() == '' ) {
$('div').hide();
}
But I want to know can I do that by pure HTML and CSS ?
Share Improve this question asked Aug 20, 2016 at 0:07 stackstack 10.2k22 gold badges70 silver badges130 bronze badges 2- Well why my question has earned one vote to be close as unclear ? Really is it unclear? I've provided a screenshot of the expected result... still it is unclear ?! – stack Commented Aug 20, 2016 at 0:11
- 1 Possible duplicate of How to hide/remove a DIV when empty – Calum Commented Aug 20, 2016 at 0:13
4 Answers
Reset to default 10You can use the :empty pseudo selector:
div:empty {
display: none;
}
li{
list-style: none;
border-bottom: 1px solid;
padding:4px;
}
div{
background-color: #eee;
padding: 6px 0;
}
div:empty {
display: none;
}
<ul>
<li>
<span>something</span>
<div></div>
</li>
<li>
<span>something</span>
<div>something else</div>
</li>
</ul>
If you need old browser support, you could just use line height for spacing instead.
li{
list-style: none;
border-bottom: 1px solid;
padding:4px;
}
div{
background-color: #eee;
// padding: 6px 0;
line-height: 2;
}
<ul>
<li>
<span>something</span>
<div></div>
</li>
<li>
<span>something</span>
<div>something else</div>
</li>
</ul>
use :empty | CSS-Trick
div:empty{
display:none;
}
reference from :empty | css-Trick
You can use Jquery like
$('div:empty').hide();
本文标签: javascriptHow can I remove element39s height when its value is emptyStack Overflow
版权声明:本文标题:javascript - How can I remove element's height when its value is empty? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742311790a2451015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论