2

So for quite a time I've been trying to understand what does it mean to center a div 'vertically', I googled it but it returns only solutions to center it 'vertically', can anyone explain what does it mean to center it vertically?

Comments
  • 0
    @rutee07 ELI5, please
  • 3
    Sounds like google returned the exact answer to your question though!

    Centering stuff in html/css can be anything from out of the box to deep magic hacks depending on what you need to do.
  • 3
    Do you know what it means to center a div horizontally? To center a div vertically means the same thing, only vertically instead of horizontally.
  • 2
    Back in the days: margin: 0 auto;
    These days: flex
    If you feel fancy: absolute, top/left 50%, transform: translate(-50%, -50%)
  • 5
    Basically...this.
  • 2
    @C0D4 yeah well in table cells this is easy. But table cells in html are like unitialized memory in c. Of course you can use it but no don't
  • 2
    @nitwhiz i think the image was just to show what centering vertically means, and not a suggestion for a solution...
  • 2
    @nitwhiz what better way to visualise centering of all available positions?

    Also, for frontend web, you don’t have to use a table to do this, but the CSS will force your divs to behave like a table 🤷‍♂️
  • 1
    @C0D4 best answer so far, thanks a lot
  • 1
    @nothappy when in doubt, ask a fellow dev that has to deal with this magical mess on a daily basis 😏
  • 2
    @nitwhiz 🤣 I went through all the stages. But now only grid and flex has meaning to me.
Add Comment