33 votes

How to center a div

14 comments

  1. em-dash
    Link
    I use http://howtocenterincss.com/ for this, mostly because I can remember the URL. I am deeply amused, and not at all surprised, that there are multiple such resources.

    I use http://howtocenterincss.com/ for this, mostly because I can remember the URL.

    I am deeply amused, and not at all surprised, that there are multiple such resources.

    13 votes
  2. pete_the_paper_boat
    Link
    I like the minimal examples that you can interact with and show margins. Nice find :)

    I like the minimal examples that you can interact with and show margins. Nice find :)

    6 votes
  3. skybrian
    Link
    There are multiple ways and seeing them side-by-side is handy.

    There are multiple ways and seeing them side-by-side is handy.

    4 votes
  4. [5]
    rustbucket
    Link
    I just throw everything I've got at it until it works. There's a reason I'm not a professional web developer. In all seriousness, I just started the process of rebuilding my personal website, this...

    I just throw everything I've got at it until it works. There's a reason I'm not a professional web developer.

    In all seriousness, I just started the process of rebuilding my personal website, this article will save me some time and sanity. Thanks!

    3 votes
    1. [3]
      teaearlgraycold
      Link Parent
      Flexbox is pretty easy!

      Flexbox is pretty easy!

      2 votes
      1. [2]
        rustbucket
        Link Parent
        Haha, that's exactly what I'm messing around with right now. It seems to be a good solution for most of my needs at the moment. Making a responsive website is so much easier that's for sure.

        Haha, that's exactly what I'm messing around with right now. It seems to be a good solution for most of my needs at the moment. Making a responsive website is so much easier that's for sure.

        1 vote
        1. teaearlgraycold
          Link Parent
          You can also try tailwind. It’s usually used with React but I’m sure it can work in lots of contexts. It makes handling page with breakpoints easy. But fundamentally it’s meant for use in a...

          You can also try tailwind. It’s usually used with React but I’m sure it can work in lots of contexts. It makes handling page with breakpoints easy. But fundamentally it’s meant for use in a component framework.

          1 vote
    2. skybrian
      Link Parent
      For my latest project I'm using Tailwind CSS, which I chose because Deno Fresh has direct support for it. I was skeptical of the concept, but I think it works pretty well for someone like me who...

      For my latest project I'm using Tailwind CSS, which I chose because Deno Fresh has direct support for it. I was skeptical of the concept, but I think it works pretty well for someone like me who knows some CSS but isn't very fluent. For any common thing you want to do, there's probably a class for it. You can read what the class does if you're curious.

      Searching on "center," it has multiple classes along similar lines to what's described in this article.

      2 votes
  5. [2]
    archevel
    Link
    <center><div>$$$ Profit!!! Should work fine in all browsers :)
    <center><div>$$$ Profit!!!
    

    Should work fine in all browsers :)

    2 votes
  6. chroma
    Link
    When I was first learning CSS, I remember purchasing a "Flexbox Zombies" educational game which, well, taught you CSS flexbox. I think it was by David Geddes. I found it so effective that I...

    When I was first learning CSS, I remember purchasing a "Flexbox Zombies" educational game which, well, taught you CSS flexbox. I think it was by David Geddes. I found it so effective that I haven't forgotten, 7 years later, and with my career now quite removed from frontend development, haha.

    Nowadays flexbox is the only "complicated" thing I really memorize from CSS. I flail when it comes to a lot of other things. I never grokked grid.

    1 vote
  7. [3]
    FlippantGod
    Link
    Can anyone here explain why Firefox's CSS debug overlay misaligns when using scrollbar-gutter? It drives me insane every time but I've never seen anyone mention it.

    Can anyone here explain why Firefox's CSS debug overlay misaligns when using scrollbar-gutter? It drives me insane every time but I've never seen anyone mention it.

    1. [2]
      forked_bytes
      Link Parent
      https://bugzilla.mozilla.org/show_bug.cgi?id=1874091
      3 votes
      1. FlippantGod
        Link Parent
        Thank you so much! I last checked before the issue was made, and I was seriously considering making one but I also thought it might just be me lol.

        Thank you so much! I last checked before the issue was made, and I was seriously considering making one but I also thought it might just be me lol.

        1 vote