Skip to content

Commit 8e75637

Browse files
authored
AG-50265 add documentation for new pseudo-class :empty-trimmed
2 parents b495a9d + 0292bff commit 8e75637

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

docs/general/ad-filtering/create-own-filters.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,6 +3603,7 @@ example.org#@#body{remove:true;}
36033603
- [Pseudo-class `:remove()` and pseudo-property `remove`](#remove-pseudos)
36043604
- [Pseudo-class `:is()`](#extended-css-is)
36053605
- [Pseudo-class `:not()`](#extended-css-not)
3606+
- [Pseudo-class `:empty-trimmed`](#extended-css-empty-trimmed)
36063607
- [Pseudo-class `:if-not()` (removed)](#extended-css-if-not)
36073608
36083609
CSS 3.0 is not always enough to block ads. To solve this problem AdGuard extends CSS capabilities by adding support for the new pseudo-elements. We have developed a separate [open-source library](https://github.com/AdguardTeam/ExtendedCss) for non-standard element selecting and applying CSS styles with extended properties.
@@ -4296,6 +4297,62 @@ The `:not()` is considered as a standard CSS pseudo-class inside the argument of
42964297
</div>
42974298
```
42984299
4300+
#### Pseudo-class `:empty-trimmed` {#extended-css-empty-trimmed}
4301+
4302+
The `:empty-trimmed` pseudo-class allows selecting elements without text content. Unlike the native CSS [`:empty`](https://developer.mozilla.org/en-US/docs/Web/CSS/:empty) pseudo-class, which matches elements that have no child nodes at all (no elements, no text nodes), `:empty-trimmed` checks `textContent` of the element **and its descendants**. It also matches elements whose text content consists only of whitespace, including non-breaking spaces such as `&nbsp;`.
4303+
4304+
**Syntax**
4305+
4306+
```text
4307+
[target]:empty-trimmed
4308+
```
4309+
4310+
- `target` — optional, standard or extended CSS selector, can be skipped for checking *any* element
4311+
4312+
:::note
4313+
4314+
This pseudo-class has no arguments.
4315+
4316+
:::
4317+
4318+
:::info Compatibility
4319+
4320+
Added in ExtendedCSS v2.0.0.
4321+
4322+
Rules with the `:empty-trimmed` pseudo-class are supported by AdGuard Browser Extension v5.5 or later. Such rules do not work in AdGuard Content Blocker.
4323+
4324+
:::
4325+
4326+
**Examples**
4327+
4328+
`div > p:empty-trimmed` selects `p#empty`, `p#spaces`, `p#nbsp`, `p#child-empty`, and `p#comment`:
4329+
4330+
```html
4331+
<!-- HTML code -->
4332+
<div>
4333+
<p id="empty"></p>
4334+
<p id="spaces"> </p>
4335+
<p id="nbsp">&nbsp;</p>
4336+
<p id="text">hello</p>
4337+
<p id="child-empty"><span></span></p>
4338+
<p id="child-text"><span>world</span></p>
4339+
<p id="comment"><!-- hidden --></p>
4340+
<p id="zwsp">&#x200B;</p>
4341+
</div>
4342+
```
4343+
4344+
`div > p:not(:empty-trimmed)` selects `p#text`, `p#child-text`, and `p#zwsp`.
4345+
4346+
:::note
4347+
4348+
An element like `<p><span></span></p>` matches `:empty-trimmed` (its text content is empty) but does **not** match native `:empty` (it has a child `<span>` node).
4349+
4350+
Elements containing only HTML comments (e.g. `<!-- hidden -->`) also match `:empty-trimmed`, because comment nodes are not reflected in `textContent`.
4351+
4352+
Zero-width characters such as zero-width space (`\u200B`) are **not** treated as whitespace. An element containing only zero-width characters does **not** match `:empty-trimmed`.
4353+
4354+
:::
4355+
42994356
#### Pseudo-class `:if-not()` (removed) {#extended-css-if-not}
43004357
43014358
:::danger Removal notice

0 commit comments

Comments
 (0)