348 private links
How CSS simplify scrollable images with
display: flex;
overflow-x: auto;
overscroll-behavior-inline: contain;
scroll-snap-type: inline mandatory;
scroll-behavior: smooth;
// On the images
scroll-snap-align: center;
contain: size;
place-self: stretch;
object-fit: cover;Tips and tricks for view transition
In my opinion, the best cases for implementing view transitions are as a way to draw attention to an element, convey movement, and help users remain in context.
Add it to all pages to apply a default cross fade transition.
@view-transition {
navigation: auto;
}
Then mark similar content with the view-transition-name css property.
Custom view transitions can be made with ::view-transition-old, ::view-transition-new, ::view-transition-image-pair.
Full page transition can be done by marking :root.
These transitions should be set only when the media query prefers-reduced-motion is set to no-preference.
Use cases for inherit(). They can be good but I don't see a need currently
There are great animations of ease-in, ease-in-out, ease, spring and bounce. The latest two can not be animated with Bézier curves as other common animations.
To get spring and bounce effects, the linear() function can be used. The linear() function takes a set of numbers, with 0 representing the starting value and 1 representing the final value.
Easing wizard or the Linear() Easing Generator can help.
If JS fails to load, a keyframe remove the effect provided by JS in 2 seconds.
:root {
--w: calc(100vw/1px); /* screen width */
--h: calc(100vh/1px); /* screen height */
/* The result is an integer without a unit! */
}
A version with better support:
:root {
--w: calc(100vw/1px); /* screen width */
--h: calc(100vh/1px); /* screen height */
/* The result is an integer without a unit! */
}::selection ans ::backdrop does not inherit from root. So :root does not guarantee the CSS variable. The html selector does not solve this.
There is currently no global context in CSS, but root is the best workaround currently.
This is going to catch a lot of people off-guard because I, like many others, expect CSS Custom properties defined on :root to just be available everywhere.
The following discussion is there https://github.com/w3c/csswg-drafts/issues/6641
To prevent a custom behavior on Safari Mobile
Rather than helping you build a sitewide design, readable.css provides a base default that is both sensible and beautiful.
For MacOS only
-webkit-font-smoothing: antialiased;
A great CSS reset
It's not available in Firefox yet.
- Link and button states
- color modes
- variables
- any kind of state
- viewport sizes
- anything scrolling or mouse movement related
- variable content
- units & math
- animations & transitions
- device specific details (touch screens, low-bandwidth situations)
- media handling
hsl & rgb had an update:
- hsla is replaced by hsl
- units are now optional when we’re using the space separated syntax
Relative colours
They can be created by mixing colors: rgb( from [#ff0000](https://shaarli.lyokolux.space/./add-tag/ff0000) r g b / 0.5) tells the browser to create an rgb color, from#ff0000 where each hexadecimal is assigned to the variables r, g, b with 50% transparency. Note h s l can be used as notation.
So here is how to plug transparency to a color: rgb(from var(--color-primary) h s l / 0.75);.
Quickwins:
- add transparency
- use lighter and darker versions of a base color in hsl:
--base-light: hsl(from var(--base) h s 75%);. See a one color toast notification: https://codepen.io/piccalilli/pen/XJXMgEB/64c4f56702893dc64d9cd4dc564f5e0e - using
calc(a later post)
Light and dark mode handling
light-dark() allow to define two variants of the color for the dark and light theme, if color-scheme: light dark; is activated. color-scheme can also deactivate it.
Colour spaces
They can be defined, so the browser does a good job of filling in those in-between colours, and sometimes, it falls flat a little. The trick was to add one or two colors in-between. Using the oklch as colour space is better though. The color spaces have to be tried manually though: lch and oklch, lab and oklab, hwb, xyz.
To have rainbow, one can use longer hue as for example linear-gradient(in hsl longer hue 90deg, var(--color-1), var(--color-2));. increasing or decreasing exists too.
As a quick aside, the range of colours in a given space is called its (wide or narrow) gamut.
display-p3 is one reference of a colour space. The chrome color picker also show the limitations of sRGB in display-p3 :)
CSS styling has no perfect solutions but tradeoffs between the different approaches. Choose the one that fits best to the project
Usages:
- Circular menus or item lists
- Wavy layouts (DNA strands, wave)
Fancy animations