[CSS] Target empty elements using the :empty pseudo-class
CSS The Class Using Target Elements empty
2023-09-14 09:00:53 时间
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; }
相关文章
- CSS水平垂直居中
- 第四界css大会 黑魔法-css网格背景、颜色拾取器、遮罩、文字颜色渐变、标题溢出渐变等
- 第七十一,CSS颜色与度量单位
- [CSS 3] Use Multiple Background Images to Create Single Element CSS Art
- [CSS 3] Use the Border-Radius CSS Property to Define Horizontal and Vertical Radius
- [CSS] Change the Alignment of a Single Flexed Item with 'align-self'
- [CSS] Change the off-axis Alignment of a Flexed Container with `align-items`
- [CSS] The :empty Pseudo Selector Gotchas
- [CSS] Specify grid columns, rows, and areas at once with the grid-template shorthand
- [CSS] Change the auto-placement behaviour of grid items with grid-auto-flow
- [CSS 3] Center an element both horizontally and vertically with place-items CSS property
- [CSS] Change the off-axis Alignment of a Flexed Container with `align-items`
- [CSS] The :empty Pseudo Selector Gotchas
- [React] Using the classnames library for conditional CSS
- vue.js 3.2.22:用useIntersectionObserver实现滑动到div可见时才运行css动画(@vueuse/core@7.0.3)
- css property 和 attribute 的区别
- 制作CSS气泡框
- 〖大前端 - 基础入门三大核心之CSS篇⑧〗- CSS3文本的常用文本样式属性之字体属性详解
- 分享一个纯css制作的动画化,在网页(手机)载入等的时候能够引用!
- CSS简洁导航条