• Rose@slrpnk.net
      link
      fedilink
      arrow-up
      15
      ·
      7 个月前

      If using plain CSS, usually it’s enough to set width appropriately, and margin-left and margin-right to auto.

      If using a Modern Frontend/CSS Framework, then may God have mercy on your poor soul.

      (Seriously I just started a new project with TailwindCSS and I’m so confused. But not entirely desperate yet.)

        • toddestan@lemm.ee
          link
          fedilink
          arrow-up
          5
          ·
          7 个月前

          Generally I find many these frameworks will make some complicated things simple, but the cost is some things that were once simple are now complicated. They can be great if you just need the things they simplify - or in other words can stick to what they were intended for, but my favorite way of keeping things simple is to avoid using complicated and heavy frameworks.

        • gradual@lemmings.world
          link
          fedilink
          arrow-up
          1
          ·
          7 个月前

          I think they exist because of ignorance.

          People who don’t understand how to do a task will usually choose the wrong tools for that task.

          If someone is trying to cover up their lack of knowledge, they will usually make things more complicated than they need to be.

      • loics2@lemm.ee
        link
        fedilink
        arrow-up
        3
        ·
        7 个月前

        w-... mx-auto, replace the 3 dots with your desired width value, and that’s it with tailwind

    • impedans@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      7 个月前

      If you define what you mean by centering I’ll give you a straight answer.

      Vertically? Horizontally? Center the text or the entire box? Compared to the viewport, the parent container or the entire page?

      “Centering” isn’t as straight forward as you’d think, and what you actually want usually depends on the situation.

        • impedans@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          7 个月前

          Yeah that works if you wanna center a box of content it relative to the parent container, either horizontally or vertically. For other situations we’ve got different tools

      • Schadrach@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        4
        ·
        7 个月前

        Fuck it, align=‘center’. That’ll center it horizontally relative to some context and if that’s not good enough then you should have been more precise in your request.

    • Blackmist@feddit.uk
      link
      fedilink
      English
      arrow-up
      9
      ·
      7 个月前

      Depends if you’re centering the div or the things in the div. Which has probably been the main issue since CSS was invented.

    • letsgo@lemm.ee
      link
      fedilink
      English
      arrow-up
      7
      ·
      7 个月前

      Same way you did it in 2024 but it’s easier because the springgirdles have been replaced with rotated manglebrackets.