首页 > 代码库 > [CSS] Target empty elements using the :empty pseudo-class
[CSS] Target empty elements using the :empty pseudo-class
You can target an element that has no child elements by using the :empty
pseudo-class. With browser support down to IE9, it‘s solid, easy way to select empty elements without any additional markup.
Be aware that whitespace is considered a "child", so :empty
will not work if the element has no children, but has space between the opening and closing tags.
<!DOCTYPE html><html><head> <link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet"> <link rel="stylesheet" href="style.css"></head><body> <div class="Alert"> <p>Success! Your profile has been updated.</p> </div> <!-- This empty alert box won‘t be show--> <div class="Alert"></div></body></html>
.Alert:not(:empty) { border: 3px solid darkgreen; margin: 1em; padding: 1em; background-color: seagreen; color: white; border-radius: 4px;}.Alert:empty{ display:none;}
<iframe style="width: 100%; height: 300px;" src="https://run.plnkr.co/6hEGs1GyGcDhDHsQ/" width="320" height="240"></iframe>
[CSS] Target empty elements using the :empty pseudo-class
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。