Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from abbas-roholamin/css-empty-pseudo-class
Browse files Browse the repository at this point in the history
Create css-empty-pseudo-class.mdx
  • Loading branch information
alisamadiii authored Mar 9, 2023
2 parents fbfc8e0 + 0417fd7 commit bc1703b
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions blog/css/css-empty-pseudo-class.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: CSS Empty Pseudo-class
author: Abbas Roholamin
date: 2023/03/09
category: [css]
description: Now we can target empty element without using JS.
order: 5
---

# CSS Empty Pseudo-class

The CSS pseudo-class __:empty__ represents each element with no children. Children can be either element nodes or text (including spaces). Comments, processing instructions, and CSS content do not affect whether an element is considered empty..

## Empty Elements

These types of elements are assumed to be empty elements and have this style applied.

```css:style.css
div:empty {
outline: 2px solid deeppink;
height: 1em;
}
```

```html:index.html
<div></div>
```

```html:index.html
<div><!-- Simple Comment --></div>
```

## Non-empty Elements

These types of elements are not considered empty elements and this style is not applied.


```css:style.css
div:empty {
outline: 2px solid deeppink;
height: 1em;
}
```


```html:index.html
<div> </div>
```

```html:index.html
<div><p></p></div>
```

```html:index.html
<div>
<!-- Simple Comment -->
</div>
```

```html:index.html
<div>Some text</div>
```

> Example [codepen.io](https://codepen.io/abbas-roholamin/pen/LYJObpx)
<Tips>
The inputs are considered empty elements even though content can be typed into them.
</Tips>

<Author
name="Abbas Roholamin"
headline="Web Designer & Developer"
image="https://i.ibb.co/h1ppgNp/photo-2023-02-28-14-46-31.jpg"
link="https://twitter.com/abbas_roholamin"
/>

1 comment on commit bc1703b

@vercel
Copy link

@vercel vercel bot commented on bc1703b Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.