228 private links
👍
- Think about the
:empty
selector, especially for message errors :) :target
to select the node targeted by an achor.:only-child
and:only-of-type
selectors
Another minimalistic CSS framework that makes a webpage pretty
A pure CSS form plugin
TL;DR Nearly 50% of HWB possible values tends to grey shades.
In both HWB & HSL colors, we can describe white and black and a full scale of grays using any hue we want. It doesn’t matter what hue we provide in either table
Lucky for us, browsers don’t generally render gradients using naive HSL math: currently browsers convert everything to sRGB before mixing. Gradients in RGB can still get muddy at times
Without auto, the
remains 4 / 3, and the image appears stretched. You can avoid the stretching with object-fit:
img {
aspect-ratio: 4 / 3;
width: 100%;
object-fit: cover;
}
Although, if the image isn't actually that aspect ratio, it'll either end up stretched (object-fit: fill), letter-boxed (object-fit: contain), or cropped (object-fit: cover). None of which are ideal.
Using clip-path to define custom shapes inside a container!
Percentages units has the benefit of keeping things responsive
There is many clip-path functions: inset, circle, ellipse, polygon and... path for maximum flexibility
clip-path: inset(x x x x)
is useful for clipping blocks of an element and using it as a "controlled" overflow.
This clip-path value represents a thunderbolt: polygon(100% 0, 20% 50%, 35% 50%, 0% 100%, 70% 50%, 50% 50%)
We can transition or animate clip-path. There's one condition. The path must have a consistent structure. For example, if we transition a polygon, that polygon must have a consistent number of points.
Skewing effect: https://codepen.io/enbee81/pen/yLyrmyg
and cyberpunk buttons in CSS: https://jhey.dev/writing/css-cyberpunk-2077-buttons-taking-your-css-to-night-city/
Creating patterns for imgs
This size matches the dimensions of our SVG exports. This is important. This is the one drawback of using clip-path: path(). It's not responsive. The path definition is relative to the dimensions of your element.
Changing the shape:
.portrait {
transition: clip-path 0.2s, transform 0.2s;
transform: scale(var(--scale, 1)) rotate(var(--rotate, 0deg));
clip-path: path(var(--clip, var(--splat)));
}
.portrait:hover {
--scale: 1.15;
--rotate: 30deg;
--clip: var(--splattier);
}
.portrait:active {
--scale: 0.85;
--rotate: -10deg;
--clip: var(--splatted);
}
This is the critical mental-model shift. CSS properties on their own are meaningless. It's up to the layout algorithm to define what they do, how they're used in the calculations.
Here's an example which blew my mind: Did you know that the width property is implemented differently depending on the layout algorithm?
I didn't know 😱
Inline space under images are due to the Flow layout and its inline elements. It adds extra-space to make sure that inline elements, such as <img />
, don't negatively affect the legibility of the surrounding text.
There are a lot of layout algorithms in CSS, and they all have their own quirks and hidden mechanisms. When we focus on CSS properties, we're only seeing the tip of the iceberg. We never learn about really important concepts like stacking contexts or containing blocks or cascade origins!
Our intuition is the best tool we have. And when we start using CSS snippets without truly understanding them, it's only a matter of time until some hidden aspect of the layout algorithm throws a wrench into our gears, stopping us in our tracks.
.full-width {
width: 100vw;
margin-left: 50%;
transform: translate3d(-50%, 0, 0);
}
Or a responsive approach with CSS grid:
.wrapper {
display: grid;
grid-template-columns:
[full-start] 1fr [wrapper-start]
minmax(0, 70rem) [wrapper-end] 1fr [full-end];
/* Optional gap */
column-gap: var(--pad, 1rem);
}
Then
.wrapper > * {
grid-column: wrapper;
}
.wrapper > .full-width {
grid-column: full;
}
Check for font-palette
and @font-palette-values
.
Only usable in Chrome and Safari for now :(
Generate a CSS grid easily
- aspect-ratio
- padding-bottom depending of the aspect-ratio
- css variables, but one dimension needs to be known:
--aspect-ratio: calc(4/3); --height: 30vmin; --width: calc(var(--height) * var(--aspect-ratio)); height: var(--height); width: var(---width);
- all property: change heritance rule of all CSS properties
- currentColor : value of the element's current color property
- custom property fallback value
- counters
- interaction media queries: selector depending on the primary input mechanism — touch, stylus, mouse pointer, etc. Which is not what we have
:where
and:is
pseudo-selectors:scroll-padding
: add padding on scroll, for example for a top header :Disolation: isolate
: create a new stacking context without relying on z-index magic numberscontent-visibility
andcontain-instrinsic-size
for render performance optimization
An example of clip-path
to better understand how it works
Nice blob shapes for boxes :D
With another border-radius on hover and a transition: border-radius, it creates god damn cool effects.
A css only typewriter !