Ana Tudor 🐯 · @anatudor
701 followers · 440 posts · Server mastodon.social

If you have 3 inputs for values of translation/ rotation/ scale along/ around the 3 axes and you want to update a CSS variable for each, here's how (not) to do it.*

*we assume we're using a translation:
transform:
translate3d(var(--x), var(--y), var(--z))

#css #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
628 followers · 363 posts · Server mastodon.social

I got slapped with one of these and I thought I could make better button hover transitions than the one they use (which involve changing the button `color` and horizontally shrinking to nothing a span underneath the text).

So here it is, normal version and slow motion with only 1 button element: codepen.io/thebabydino/pen/ExR

For the how behind the technique (and more similar cool techniques), see my Taming Blend Modes: `difference` & `exclusion` css-tricks.com/taming-blend-mo

#css #codepen #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
595 followers · 335 posts · Server mastodon.social

Because I saw a piece of used to illustrate the 1st principle of animation & almost screamed in horror...

❌ DON'T
.b { -webkit-animation: a 1s ease infinite alternate }

@-webkit-keyframes a {
0% { -webkit-transform: scaley(1.0) }
50% { -webkit-transform: translatey(-300%) scaley(1.2) }
100% { -webkit-transform: scale(1.0) }
}

✅ DO
.b { animation: a .5s ease-out infinite alternate }

@keyframes a {
to { transform: translatey(-300%) scale(.83, 1.2) }
}

Why? 👇

#css #tinycodingtips #cssanimation

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
579 followers · 302 posts · Server mastodon.social

This is the little bit of code that does the magic of showing the "yay, supported!" box or the "sorry, not supported" one depending on whether the browser supports a particular feature (values, properties, selectors) or not.

Conditional display of info boxes depending on browser support and all in pure CSS, no JS needed.

#css #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
574 followers · 296 posts · Server mastodon.social

Something I've been including in my demos containing bleeding edge features lately: have two info boxes, one saying "yay, your browser supports [feature]!" and the other "sorry, your browser doesn't support [feature]." and toggle their display depending on support.

Live demo on codepen.io/thebabydino/full/qB

This is a pure support test, using `@​supports` - no JS is required.

Another example of such info boxes in my partial `grayscale(1)` demo: mastodon.social/@anatudor/1094

#codepen #css #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
537 followers · 250 posts · Server mastodon.social

Bonus, this is also what helps solve a recent challenge (this one mastodon.social/@anatudor/1094): instead of a sharp gradient transition between transparent and grey, have a smooth one in order to progressively desaturate the top layer going from top (vibrant) to bottom (completely desaturated).

Live demos:

💫 codepen.io/thebabydino/pen/yLE

💫 codepen.io/thebabydino/full/xx

#css #tinycodingtips #codepen #blending #csschallenge2022

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
534 followers · 239 posts · Server mastodon.social

What if you wanted the filter: grayscale(1) effect to apply only to (a part of) the background?

There's filter() (w3.org/TR/filter-effects/#Filt), but, while Safari has supported it since 2015, it's not in any other browser 😿

Better solution: blend with a grey (*any* grey works because all that matters is saturation being 0%) background-color or gradient layer underneath using luminosity! 🌟

Test codepen.io/thebabydino/full/qB

Cool use case codepen.io/thebabydino/pen/KKg

#css #codepen #blending #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
439 followers · 174 posts · Server mastodon.social

Want your absolutely positioned pseudo/ child to cover its entire parent?

❌DON'T
```
top: 0;
left: 0;
width: 100%;
height: 100%
```

or

```
top: 0;
right: 0;
bottom: 0;
left: 0
```

✅ DO
```
inset: 0
```

Live demo codepen.io/thebabydino/pen/xxX

`inset` is well supported and can take 1, 2, 3 or 4 values, just like `margin` or `padding`.

On MDN developer.mozilla.org/en-US/do

#css #codepen #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
377 followers · 132 posts · Server mastodon.social

Saw getcssscan.com/css-shapes - the code for some of them (polygons, tooltips) is terribly outdated.

Here's how you make tooltips with *no pseudos* codepen.io/thebabydino/pen/dyK

`--i` & `--j` are all that differ between the four tooltip directions and indicate where the tooltip is along the horizontal & vertical axes respectively.

+more interesting ones

💫 gradient background codepen.io/thebabydino/pen/GRo
💫 border + text gradient & transparency codepen.io/thebabydino/pen/pog

#css #tinycodingtips #codepen

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
368 followers · 128 posts · Server mastodon.social

Bonus tip to the one @chenry shared mastodon.social/@chenry/109325 - you can have a `background` for an `<img>`.

This helps with getting a gradient `border` for the image when the image also has rounded corners or for a multi-gradient layer border pattern: codepen.io/thebabydino/pen/JjZ

Because `border-image` only accepts one gradient image (can't have more to get ⭐ or ❤️ patterns) & doesn't play nice with `border-radius` (codepen.io/thebabydino/pen/jxZ).

#css #CSSTips #tinycodingtips #codepen

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
354 followers · 116 posts · Server mastodon.social

The `aspect-ratio` property relates to `box-sizing`.

Let's say we have `aspect-ratio: 4/ 3`

By default, this is the aspect ratio of the `content-box`.

But if we set `box-sizing: border-box`, 4/ 3 becomes the aspect ratio of the `border-box`.

Bonus, here's a cool little thing I've used `aspect-ratio` for: cards with 2 conic gradients at opposite corners, meeting along the diagonal in between the 2 corners css-tricks.com/variable-aspect (this should get easier with atan in CSS)

#css #tinycodingtips

Last updated 2 years ago

Ana Tudor 🐯 · @anatudor
352 followers · 115 posts · Server mastodon.social

Something I've shared before (years ago on twitter):

DON'T ❌

@​keyframes b {
0% { color: tan }
49.99999% { color: tan }
50.00001% { color: red }
100% { color: red }
}

p { animation: b 2s infinite }

Instead, DO ✅

@​keyframes b { 50% { color: red } }

p {
color: tan;
animation: b 2s steps(1) infinite
}

Some examples of demos where I've used this:
codepen.io/thebabydino/pen/Bad
codepen.io/thebabydino/pen/vNx
codepen.io/thebabydino/pen/yQe
codepen.io/thebabydino/pen/MQe

#css #tinycodingtips #codepen

Last updated 2 years ago