August 2018
CSS - PRO TIPS - CSS element() function - [: -moz-element()]Vincent De Oliveira
element() brings CSS design to a new level, in an easily way. Few ideas that comes to my mind (some that I've already used since the last 4 years):
- when you have to deal with duplicated content in advanced effects
- live thumbnails of previous/next slides in a slideshow
- live zoom over an image, for example in an e-commerce product page
- animated background, using CSS Animations or by referencing a video, canvas or SVG
- faking backdrop-filter or filter()
- watermark with multiples backgrounds from Lea Verou idea
- and anything you’re currently thinking of ;)
Few things we can note:
- prefixed for now in Firefox: -moz-element()
- impact on rendering performance when using multiple reference. Not as bad as CSS filters, but still something you have to consider
- there’s a CanIUse support page
- Issue Chromium
- Issue WebKit
- No mention from IE Platform Status
August 2017
CSS - VARIABLE - Autoprefixing, with CSS variables! | Lea Verou
a neat trick one can do with CSS variables, precisely due to their dynamic nature. Let’s say you want to use a property that has multiple versions: an unprefixed one and one or more prefixed ones. In this example we are going to use clip-path, which currently needs both an unprefixed version and a -webkit- prefixed one, however the technique works for any property and any number of prefixes or different property names, as long as the value is the same across all variations of the property name.
The first part is to define a --clip-path property on every element with a value of initial. This prevents the property from being inherited every time it’s used, and since the * has zero specificity, any declaration that uses --clip-path can override it. Then you define all variations of the property name with var(--clip-path) as their value:
* {
--clip-path: initial;
-webkit-clip-path: var(--clip-path);
clip-path: var(--clip-path);
}
1
(2 marks)