home.social

#tinycodingtips — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #tinycodingtips, aggregated by home.social.

fetched live
  1. I was today years old when I learned this... want small caps?

    Use `font-variant: small-caps`!

    #TIL #tinyCodingTips #css

  2. I was today years old when I learned this... want small caps?

    Use `font-variant: small-caps`!

    #TIL #tinyCodingTips #css

  3. 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

  4. 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

  5. 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 & slow motion with only 1 button element: codepen.io/thebabydino/pen/ExR

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

    #css #CodePen #tinyCodingTips

  6. 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 & slow motion with only 1 button element: codepen.io/thebabydino/pen/ExR

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

    #css #CodePen #tinyCodingTips

  7. Because I saw a piece of #CSS 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? 👇
    #tinyCodingTips #cssAnimation

  8. Because I saw a piece of #CSS 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? 👇
    #tinyCodingTips #cssAnimation

  9. This is the little bit of #CSS 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.

    #tinyCodingTips

  10. This is the little bit of #CSS 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.

    #tinyCodingTips

  11. 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 codepen.io/thebabydino/full/qB

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

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

    #tinyCodingTips

  12. 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 codepen.io/thebabydino/full/qB

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

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

    #tinyCodingTips

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. Want to get a square element with the edge a % value of its parent's `width` or `height`?

    Normally, the `width` set in % is a % of the parent's `width` and the `height` set in % is a % of the parent's `height`. So how to get a square box whose edge is a % of either the parent's `width` or `height`?

    Before, there was the padding hack (*but only* for the 1st case, edge being a % of parent `width`) nikitahl.com/css-aspect-ratio

    But now we can do better with `aspect-ratio`! 🌟

    #css #tinyCodingTips

  26. Btw, there are a lot more #newGoodies coming to #css when it comes to theming.

    For example, the ability to modify individual RGBa/ HSLa components without storing each into a variable. 🤯

    So far, only in Safari as an experimental feature. Spec link: w3.org/TR/css-color-5/#relativ

    #tinyCodingTips

  27. Btw, there are a lot more #newGoodies coming to #css when it comes to theming.

    For example, the ability to modify individual RGBa/ HSLa components without storing each into a variable. 🤯

    So far, only in Safari as an experimental feature. Spec link: w3.org/TR/css-color-5/#relativ

    #tinyCodingTips

  28. You've probably used orientation media queries. But have you ever wondered which styles apply when the viewport is square?

    Is it the landscape or the portrait ones?🤔

    Well, just wondered about that & had to test. All browsers apply the portrait ones when the viewport is square.

    If you want the landscape orientation styles applied when the viewport is exactly square, you can use an aspect ratio media query (for example, `min-aspect-ratio: 1/ 1`) 😼

    #css #tinyCodingTips

  29. You've probably used orientation media queries. But have you ever wondered which styles apply when the viewport is square?

    Is it the landscape or the portrait ones?🤔

    Well, just wondered about that & had to test. All browsers apply the portrait ones when the viewport is square.

    If you want the landscape orientation styles applied when the viewport is exactly square, you can use an aspect ratio media query (for example, `min-aspect-ratio: 1/ 1`) 😼

    #css #tinyCodingTips

  30. ✨ `:has()` boolean logic ✨

    💫 OR - use comma-separated values inside `:has()`

    💫 AND - use chained `has()` selectors

    You can play with it here codepen.io/thebabydino/pen/KKe

    #css #tinyCodingTips #CodePen