CSS content-visibility

The CSS language is full of small gaps which are frustrating to navigate. Between CSS properties to hide a container and its contents, there is still room for improvement. visibility: hidden keeps height and width integrity while display: none on a container hides everything. You can use .container > * to hide all contents of a […]

The post CSS content-visibility appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

The CSS language is full of small gaps which are frustrating to navigate. Between CSS properties to hide a container and its contents, there is still room for improvement. visibility: hidden keeps height and width integrity while display: none on a container hides everything. You can use .container > * to hide all contents of a container, but what if there was a better way?

There is a better way to hide the contents of an element while respecting the container’s border and dimensions. That better way is using the content-visibility property:

.my-container.contents-loading {
  content-visibility: hidden;
}

A demo of such functionality:

See the Pen Untitled by David Walsh (@darkwing) on CodePen.

Avoiding a .container > * selector by using content-visibility: hidden is so much nicer from a maintenance perspective!

The post CSS content-visibility appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2023-04-28T00:13:28+00:00) CSS content-visibility. Retrieved from https://www.scien.cx/2023/04/28/css-content-visibility/

MLA
" » CSS content-visibility." David Walsh | Sciencx - Friday April 28, 2023, https://www.scien.cx/2023/04/28/css-content-visibility/
HARVARD
David Walsh | Sciencx Friday April 28, 2023 » CSS content-visibility., viewed ,<https://www.scien.cx/2023/04/28/css-content-visibility/>
VANCOUVER
David Walsh | Sciencx - » CSS content-visibility. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/04/28/css-content-visibility/
CHICAGO
" » CSS content-visibility." David Walsh | Sciencx - Accessed . https://www.scien.cx/2023/04/28/css-content-visibility/
IEEE
" » CSS content-visibility." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2023/04/28/css-content-visibility/. [Accessed: ]
rf:citation
» CSS content-visibility | David Walsh | Sciencx | https://www.scien.cx/2023/04/28/css-content-visibility/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.