Reputation: 15104
I have a div which in which errors will be represented. My problem is that because it has a red border, it will be displayed as an empty line even when the div is empty (there are no errors). I don't like this behavior; I'd prefer the div to be completely invisible when it is empty.
Also, I don't want to do that with javascript—is it possible to hide the border when the div is empty only with CSS?
Upvotes: 1
Views: 10271
Reputation: 17434
Yes. Here is one possible solution using empty-cells:
CSS
.error {
display:table-cell;
empty-cells:hide;
padding: 10px;
border: 1px solid red;
}
HTML
<div class="error"><!-- I am empty --></div>
<div class="error">Error'd!</div>
Upvotes: 10
Reputation: 3969
BEST way is to control it from server side and DON'T display if its empty. Otherwise you can use :empty selector but its support in IE is not solid.
And yes, if you use jquery then you'll be fine.
$(document).ready(function() { $('div:empty').remove(); });
Upvotes: 3
Reputation: 119867
check out this CSS3 pseudoclass :empty
div{
border:1px solid red
}
div:empty{
display:none
}
Upvotes: 11