开发者

hide border if there is no content

开发者 https://www.devze.com 2023-03-14 00:25 出处:网络
On a div开发者_如何学编程 I have css set: div.class {border: 1px solid red;} The div is positioned absolutely in the center of the page. The problem is that the border appears even if there is no c

On a div开发者_如何学编程 I have css set:

div.class {border: 1px solid red;}

The div is positioned absolutely in the center of the page. The problem is that the border appears even if there is no content.

Any css methods to get the border to not appear if there is no content?


CSS3 has a selector defined for this case. It does not work in IE8 and lower though.

div.class:empty { 
    border: none;
}

Your best option would be to tweak this on the server side, and simply don't display that div if it would be empty.


If the div can have content related to a server response, you can tell whether it is an empty or a filled response and change to display:none or display:block accordingly

0

精彩评论

暂无评论...
验证码 换一张
取 消