home.social

#tinycsstip β€” Public Fediverse posts

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

  1. #tinyCSStip

    I like shorthands, I find them immensely useful. But it doesn't always make sense to drop it all in the shorthand and to have repetitions. Yeah, you can store that `.2s` in a #CSS variable. But is it really worth it if you're not even using it elsewhere in addition to not being dynamic?

  2. #tinyCSStip

    Sometimes, if you notice a teeny tiny misalignment and you cannot understand why because *nothing* in your CSS looks like it could have caused it... try using `round()` to round to an integer number of pixels.

    It just solved my own tiny misalignment problem that was driving me batty. πŸ¦‡

    #CSS #cssMaths #code #coding #frontend #web #dev #webDevelopment #webDev

  3. #tinyCSStip

    Sometimes, if you notice a teeny tiny misalignment and you cannot understand why because *nothing* in your CSS looks like it could have caused it... try using `round()` to round to an integer number of pixels.

    It just solved my own tiny misalignment problem that was driving me batty. πŸ¦‡

    #CSS #cssMaths #code #coding #frontend #web #dev #webDevelopment #webDev

  4. #tinyCSStip

    Sometimes, if you notice a teeny tiny misalignment and you cannot understand why because *nothing* in your CSS looks like it could have caused it... try using `round()` to round to an integer number of pixels.

    It just solved my own tiny misalignment problem that was driving me batty. πŸ¦‡

    #CSS #cssMaths #code #coding #frontend #web #dev #webDevelopment #webDev

  5. #tinyCSStip

    Sometimes, if you notice a teeny tiny misalignment and you cannot understand why because *nothing* in your CSS looks like it could have caused it... try using `round()` to round to an integer number of pixels.

    It just solved my own tiny misalignment problem that was driving me batty. πŸ¦‡

    #CSS #cssMaths #code #coding #frontend #web #dev #webDevelopment #webDev

  6. RE: mastodon.social/@anatudor/1106

    Nowadays, we can do better:

    ```
    box-shadow: 0 1px 2px
    rgb(from currentcolor r g b/ .65)
    ```

    Cross-browser since September 2024.

    #tinyCSStip #CSS #code #coding #frontend #web #dev #webDev #webDevelopment

  7. Because I often see this and it's a major #CSS pet peeve of mine, makes me want to scream "do you even understand what `cover` does?" at the screen every time...

    #tinyCSStip

  8. #tinyCSStip Want the same border, but only for two edges, not for the others?

    Don't set borders on the two edges to the same value, set border, then override border-width. If you later need to make the border thicker or thinner or pink or green, you only need to make that change in one place.

    #CSS #cssBasics #code #coding #web #dev #webDev #webDevelopment #frontend

  9. And here's a cards demo with a cool, yet very simple trick: these left to right gradients are vibrant at the top, but then progressively get more and more desaturated going down, until fully grey.

    Live on @codepen codepen.io/thebabydino/pen/xxz - only 2 CSS declarations necessary!

    #CSS #tinyCSStip #blending #blendMode #cssGradient #code #coding #frontend #web #dev #webDev #webDevelopment

  10. #tinyCSStip `clip-path` or `mask` are applied after `filter`.

    This means we cannot clip/ mask, then add a `drop-shadow()` on the same element for the clipped/ masked shape.

    We need to apply the `filter` on a parent of the clipped/ masked (pseudo-)element.

    codepen.io/thebabydino/pen/BRR

    #CSS #filter #cssFilter #clipPath #clipping #cssClipPath #cssMask #coding #frontend #web #dev #webDev #webDevelopment #code

  11. #tinyCSStip Simplifying animations with variables and mathematical functions.

    Same result, just not writing almost the same `text-shadow` a bunch of times in a bunch of keyframes.

    Live test on @codepen codepen.io/thebabydino/pen/MYW

    #CSS #Maths #code #coding #frontend #web #dev #webDev #webDevelopment
    #cssMaths #trigonometry

  12. #tinyCSStip

    🚫 DON'T use layered text-shadows for text outlines just because text-stroke is broken (mastodon.social/@anatudor/1124), they are going to produce ugly corners, thickened roundings and angled lines.

    βœ… DO: use `paint-order: stroke fill` instead!

    #CSS #typography #code #coding #web #dev #webDev #webDevelopment #frontend

  13. Know how border-image & border-radius don't play nice together?

    (interactive codepen.io/thebabydino/pen/jxZ)

    #tinyCSStip there's a workaround IF corner radius ≀ border-width: use inset() clip-path + a round value!

    clip-path: inset(0 round $r)

    @codepen demo: codepen.io/thebabydino/pen/qBE

    (and yes, this is a tip I first shared on twitter over half a decade ago x.com/anatudor/status/12199161 )

    #CSS #clipPath #cssClipPath #coding #web #dev #webDev #webDevelopment #code #frontend #borderImage #borderRadius

  14. Also, those letters in the squares? #CSS counters!

    ```
    .item { counter-increment: c }

    .item::after { content: counter(c, upper-alpha) }
    ```

    #tinyCSStip #cssCounter #code #coding #web #dev #webDev #webDevelopment
    #frontend

  15. #tinyCSStip Create a fancy double border with dashes in between without any pseudos and with minimal #CSS!

    The relevant code is just 3 simple CSS declarations!

    Live demo on @codepen

    codepen.io/thebabydino/pen/PwY

    #cssBasics #code #coding #frontend #web #dev #webDev #webDevelopment

  16. #tinyCSStip if you want to make an absolutely positioned pseudo cover its parent's entire `padding-box`, use `inset: 0`!

    (love grid for stacking/ full coverage too, but there are differences between how the two solutions work and there are cases when absolute positioning is still preferable)

    #CSS #code #coding #frontend #layout #web #dev #webDev #webDevelopment #cssLayout

  17. #tinyCSStip Want to avoid ugly checkerboard edges when pattern size depends on viewport?

    Round it to be a multiple of 2px so every square edge is an int number of pixels!

    --s: round(10vmin, 2px);
    background:
    repeating-conic-gradient(red 0% 25%, tan 0% 50%)
    0 0/ var(--s) var(--s)

    #CSS #code #coding #frontend #gradient #web #dev #webDev #webDevelopment #cssGradient #conicGradient

  18. #tinyCSStip

    Pretty sure I've posted about this before, but a quick search at the morning hours didn't find it, plus I saw someone ask about it yet againΒΉ, so... fixed aspect-ratio box within variable size container!

    Live on @codepen codepen.io/thebabydino/pen/ogv

    ΒΉhere reddit.com/r/css/comments/1hhf

    #CSS #aspectRatio #code #coding #web #frontend #dev #webDevelopment #webDev #containerQuery #containerQueryUnits #container

  19. #tinyCSStip

    Ever want to mask something out of an element, but not cut out blur or box-shadow or a pseudo outside the element's border box?

    Well, subtract whatever you want masked out from a fully opaque layer with `mask-clip` set to `no-clip`!

    mask:
    conic-gradient(red 0 0) no-clip subtract,
    var(--masked-area)

    @codepen demo: codepen.io/thebabydino/pen/MYg

    #CSS #cssMask #code #coding #frontend #web #dev #webDev #webDevelopment

  20. #tinyCSStip

    Range input browser inconsistencies may mean needing different styles for different browsers. Possible for track & thumb via different pseudos, but what about the actual range input?

    Well, `@​supports selector()` to the rescue!

    Live test on @codepen

    #CSS #HTML #cssSelector #code #frontend #webDev #web #dev #webDevelopment #coding

  21. #tinyCSStip

    Range input browser inconsistencies may mean needing different styles for different browsers. Possible for track & thumb via different pseudos, but what about the actual range input?

    Well, `@​supports selector()` to the rescue!

    Live test on @codepen

    #CSS #HTML #cssSelector #code #frontend #webDev #web #dev #webDevelopment #coding

  22. #tinyCSStip

    Range input browser inconsistencies may mean needing different styles for different browsers. Possible for track & thumb via different pseudos, but what about the actual range input?

    Well, `@​supports selector()` to the rescue!

    Live test on @codepen

    #CSS #HTML #cssSelector #code #frontend #webDev #web #dev #webDevelopment #coding

  23. #tinyCSStip

    Range input browser inconsistencies may mean needing different styles for different browsers. Possible for track & thumb via different pseudos, but what about the actual range input?

    Well, `@​supports selector()` to the rescue!

    Live test on @codepen

    #CSS #HTML #cssSelector #code #frontend #webDev #web #dev #webDevelopment #coding

  24. #tinyCSStip

    Range input browser inconsistencies may mean needing different styles for different browsers. Possible for track & thumb via different pseudos, but what about the actual range input?

    Well, `@​supports selector()` to the rescue!

    Live test on @codepen

    #CSS #HTML #cssSelector #code #frontend #webDev #web #dev #webDevelopment #coding

  25. #tinyCSStip

    Want the shadow of an element or some other visual to be a semitransparent version of the `currentColor`, which was given as a hex or keyword value?

    No need to convert to rgb() or hsl() anymore!

    #CSS #code #coding #frontend #webDev #web Dev #webDevelopment

  26. #tinyCSStip Want your page background to contain an integer number of dots?

    Use `background-repeat: space`! This inserts a bit of space in between background repetitions so we have an integer number of them. Well-supported for ages. πŸ₯³

    Live on @codepen codepen.io/thebabydino/pen/RwX

    #CSS #pattern #gradient #cssPattern #cssGradient #code #coding #frontend #web #dev #webDev #webDevelopment

  27. #tinyCSStip Container queries on the body? Why, when media queries have better support?

    Well, container queries make it an IF depending on the width of the body's content-box.

    That is, subtracting the scrollbar IF we have one (we can't know).

    **Heavily** commented @codepen demo codepen.io/thebabydino/pen/ZEg

    #CSS #container #containerQuery #layout #cssLayout #grid #cssGrid #frontend #code #web #dev #webDev #webDevelopment #coding #containerQueryUnits

  28. #tinyCSStip/ fun fact: same aspect ratio is also what we need for a regular hexagon because that can made up of only equilateral triangles!

    We just need more points for the clip-path (6 for a hexagon vs. 3 for a triangle).

    #CSS #cssMaths #trigonometry #maths #mathematics #frontend #code #coding
    #web #dev #webDevelopment #webDev #hexagon

  29. #tinyCSStip Want to create a triangle with all edges equal in 4 simple #CSS declarations?

    Such a triangle also has all vertex angles equal = (sum of angles in a triangle)/3 = 180Β°/3 = 60Β°

    πŸ‘‰ en.wikipedia.org/wiki/Sum_of_a

    Knowing its edge length a, its height is aΒ·sin(60Β°).

    Aspect ratio of the box
    a/(aΒ·sin(60Β°)) = 1/sin(60Β°)

    #cssMaths #Maths #Mahematics #code #trigonometry #triangle #coding #webDev #frontend #web #webDevelopment #dev

  30. #tinyCSStip If you don't need the start angle and the sector angle to be decoupled, you can simplify things by making the sector angle depend on the start one. πŸ’‘

    4 base declarations + 1 simple animation = magic! πŸͺ„

    All pure #css

    #code #coding #frontend #web #webDev #dev #webDevelopment

  31. #tinyCSStip Simplest circle sector in 4 CSS declarations!

    1⃣ set width to desired diameter
    2⃣ square element with aspect-ratio
    3⃣ turn square into disc
    4⃣ conic-gradient() magic! πŸͺ„

    The start angle and sector angle can also be animated for fun results.

    Because someone asked reddit.com/r/css/comments/1fvo

    #CSS #gradient #cssGradient #code #coding #frontend #web #dev #webDev #webDevelopment

  32. Because I just saw a checkerboard pattern done with 4 CSS gradients: you don't need to overcomplicate! 🏁

    A single conic gradient does it! ✨

    Detailed explanation of the how behind this + other patterns css-tricks.com/background-patt

    #tinyCSStip #CSS #cssPattern #cssGradient #code #coding #frontend #web #webDev #dev #webDevelopment

  33. #tinyCSStip Double stop position is well-supported and has been well-supported for about half a decade, so there's no reason not to use it!

    ❌ DON'T 😬
    orange 40%, hotpink 0, hotpink 60%, purple 0

    βœ… DO 😎
    orange 40%, hotpink 0 60%, purple 0

    Also see:
    codepen.io/thebabydino/pen/XWJ

    #css #gradient #cssGradient #code #web #dev #coding #frontend #webDev #webDevelopment

  34. #tinyCSStip to avoid repetition and make your code more maintainable! 🌟

    If you set a stop position to a value smaller than that of the previous, it's taken to be equal to the previous!

    Want an abrupt change at 30% between aqua and blue?

    Just write `aqua 30%, blue 0`! 😎

    #CSS #gradient #cssGradient #coding #code #webDev #dev #frontend #cssTricks #webDevelopment

  35. #tinyCSStip to avoid repetition and make your code more maintainable! 🌟

    If you set a stop position to a value smaller than that of the previous, it's taken to be equal to the previous!

    Want an abrupt change at 30% between aqua and blue?

    Just write `aqua 30%, blue 0`! 😎

    #CSS #gradient #cssGradient #coding #code #webDev #dev #frontend #cssTricks #webDevelopment

  36. #tinyCSStip to avoid repetition and make your code more maintainable! 🌟

    If you set a stop position to a value smaller than that of the previous, it's taken to be equal to the previous!

    Want an abrupt change at 30% between aqua and blue?

    Just write `aqua 30%, blue 0`! 😎

    #CSS #gradient #cssGradient #coding #code #webDev #dev #frontend #cssTricks #webDevelopment

  37. #tinyCSStip to avoid repetition and make your code more maintainable! 🌟

    If you set a stop position to a value smaller than that of the previous, it's taken to be equal to the previous!

    Want an abrupt change at 30% between aqua and blue?

    Just write `aqua 30%, blue 0`! 😎

    #CSS #gradient #cssGradient #coding #code #webDev #dev #frontend #cssTricks #webDevelopment

  38. #tinyCSStip to avoid repetition and make your code more maintainable! 🌟

    If you set a stop position to a value smaller than that of the previous, it's taken to be equal to the previous!

    Want an abrupt change at 30% between aqua and blue?

    Just write `aqua 30%, blue 0`! 😎

    #CSS #gradient #cssGradient #coding #code #webDev #dev #frontend #cssTricks #webDevelopment

  39. #tinyCSStip Know when you set a background gradient or a gradient mask and you get an ugly banding effect?

    Tons of questions asked about this - the advice always is noise/ grain/ dither.

    graphicdesign.stackexchange.co

    That's a simple #SVG filter, but did you know you should be able to apply it to a #CSS gradient?

    #cssGradient #cssMask #mask #gradient #borderImage #filter #svgFilter #grain #grainy #noise #dither #code #coding #web #dev #webDev #webDevelopment #frontend

  40. #tinyCSStip As I just saw this in a '24 tutorial to make an absolutely positioned pseudo extend `8px` outside its parent in all directions.

    ❌ DON'T πŸ™€
    width: 100%; height: 100%;
    left: 50%; top: 50%;
    translate: -50% -50%;
    padding: 8px

    βœ… DO 😼 (1 declaration, not 6)
    inset: -8px

    Notes:
    ✨ yes, there are still valid use cases for `position: absolute` pseudos instead of `grid`
    ✨ no, that `padding` wasn't relevant later

    #css #cssTrick #cssTip #code #coding #frontend #web #webDev #dev #webDevelopment

  41. #tinyCSStip What if you need to set `color` to the inverted value of a CSS variable? You can't invert the whole element because the rest of it shouldn't be inverted. And you can't use the Sass `invert()` on a CSS var.

    Here's how! πŸ‘‡

    (see developer.mozilla.org/en-US/do for more details)

    #css #cssVariable #code #coding #rgb #frontend #web #webDev #webDevelopment #dev

  42. #tinyCSStip What if you need to set `color` to the inverted value of a CSS variable? You can't invert the whole element because the rest of it shouldn't be inverted. And you can't use the Sass `invert()` on a CSS var.

    Here's how! πŸ‘‡

    (see developer.mozilla.org/en-US/do for more details)

    #css #cssVariable #code #coding #rgb #frontend #web #webDev #webDevelopment #dev

  43. #tinyCSStip What if you need to set `color` to the inverted value of a CSS variable? You can't invert the whole element because the rest of it shouldn't be inverted. And you can't use the Sass `invert()` on a CSS var.

    Here's how! πŸ‘‡

    (see developer.mozilla.org/en-US/do for more details)

    #css #cssVariable #code #coding #rgb #frontend #web #webDev #webDevelopment #dev