Vertically centering WITHOUT flex or grid? It's so easy now!

Sdílet
Vložit
  • čas přidán 7. 05. 2024
  • We can vertically center in CSS without having to change the display property in CSS! All we need is an align-content: center and we're good to go!
    #css
    ---
    And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!

Komentáře • 54

  • @teugene
    @teugene Před 24 dny +74

    We've come a long way since the days of using and to vertically align content!

    • @Marcel-cg9nq
      @Marcel-cg9nq Před 14 dny +2

      Still have to do it in email templates. Don’t worry.

  • @MarkRMu
    @MarkRMu Před 24 dny +42

    That's great, but I'll still be googling "How to vertically center a div" everytime I have to

    • @joseflanders
      @joseflanders Před 24 dny +2

      I feel so seen.

    • @rafelgrau
      @rafelgrau Před 2 dny

      Yes, it would have been too easy to name it align-vertical ?

  • @Turabbo
    @Turabbo Před 24 dny +12

    This one completely snuck up on me, I only heard about it a few days ago and it's already got such good support. Really nice qol feature!

  • @kemal6039
    @kemal6039 Před 20 dny +4

    Cool!

  • @siegfriedschmitz5260
    @siegfriedschmitz5260 Před 12 dny +2

    I am a backend developer and I really don't like fronted, but of course I cannot avoid it sometimes. Your shorts are really helpful

  • @rayyanabdulwajid7681
    @rayyanabdulwajid7681 Před 20 dny +4

    Can't wait to see 100 more ways to center a div in 25 years from now. 😂

  • @timgerk3262
    @timgerk3262 Před 23 dny +6

    It's a crime this wasn't in the very first release of CSS. Who had to retire/catch an unexpected bus before this was sensibly added?

  • @khodok9636
    @khodok9636 Před 24 dny +11

    THAT WORKS ON BLOCK ELEMENTS?! Oh God

  • @hooooman.
    @hooooman. Před 13 dny +3

    Is there any horizontal alignment equivalent for it?

  • @TOBIKOLO
    @TOBIKOLO Před 14 dny

    Improved! 📈

  • @Sindoku
    @Sindoku Před 18 dny

    I’ll honestly just stick to my flex box for centering unless it’s a page layout, in which I’ll use grid, but still, pretty cool to see they’ve added block level support!

  • @Ella_1994
    @Ella_1994 Před 24 dny +1

    Woaw! That is crazy!

  • @CodeDreamer68
    @CodeDreamer68 Před 18 dny

    About dang time!!!!

  • @eioluseyi
    @eioluseyi Před 24 dny +2

    Lovely! 🎉

  • @goodnewsjohn2482
    @goodnewsjohn2482 Před 18 dny

    That's why i subscribed

  • @adamuk73
    @adamuk73 Před 24 dny +3

    Is there an inline axis version of this for block elements or is margin: auto still the way to go?

    • @KevinPowell
      @KevinPowell  Před 24 dny +7

      margin: auto would still be the way to go there.

  • @WarehouseDev
    @WarehouseDev Před 23 dny

    Awesome! Is this a new feature or been a while but under-used

  • @whoisshahmeer
    @whoisshahmeer Před 24 dny +1

    Savior!!!

  • @nomadshiba
    @nomadshiba Před 21 dnem

    amazing, definitely will use it.
    but still finding grid and outside in control easier. especially with components with isolated styles.
    i wonder how does this behave? espacially with margins and stuff. does it work like grid with a single area? well probably it's not because of margins.
    gonna play around with this when I have time

  • @dasten123
    @dasten123 Před 24 dny +2

    Nowadays we can simply use a table layout

  • @salentipy
    @salentipy Před 21 dnem

    Omg no way!!

  • @dancehalllyrics1303
    @dancehalllyrics1303 Před 23 dny

    @KevinPowell, if i want to center it horizontally and vertically (given that the element is a block level element), I can simply just add “align-content: center;” for vertical centering and “margin: auto;” for horizontal centering, and I should be good to go?

    • @KevinPowell
      @KevinPowell  Před 22 dny

      No, or well, probably not 😅. Align-content will influence the children, margin auto influences the element you declare it on

  • @AnthonyTilahun
    @AnthonyTilahun Před 24 dny

    Ain't no way boi!!

  • @Sealis04
    @Sealis04 Před 14 dny

    Then there's me, who tries every center CSS till it aligns then just uses that permanently.

  • @AlexCrMaReLiLukyanenko

    but won't it create a bit of confusion?
    For example display flex has the same-named property of align-content (along with align-items)

    • @KevinPowell
      @KevinPowell  Před 23 dny +1

      It removes the need to use flex or grid if that's all you want to do, which is often the case.

  • @lexgim
    @lexgim Před 21 dnem

    I just realized this like 2 hours ago, idk if someone's spying me cuz wtf

  • @KP21530
    @KP21530 Před 24 dny

    how this works without display flex?

    • @KevinPowell
      @KevinPowell  Před 24 dny +7

      They updated the spec to remove the requirement for flex or grid

    • @KP21530
      @KP21530 Před 24 dny +2

      ​@@KevinPowellOh, that's great. By the way, I love your videos. They are always very informative and useful.

  • @nash5637
    @nash5637 Před 20 dny

    cant imagine such a basic function need chrome 123 ...

  • @salmanazam9444
    @salmanazam9444 Před 24 dny

    Wait, I thought align-content was always for a flex container...
    Is this why it would never seem to do anything when I applied it on a flex div?
    My go-to method till now has been align-items and justify-content center after display flex.

    • @KevinPowell
      @KevinPowell  Před 24 dny +1

      It won't work with flex because, with flex, you need the ones you said. This is a shorthand for align-content and justify-content

    • @salmanazam9444
      @salmanazam9444 Před 24 dny +1

      @@KevinPowell Thank You Kevin, my Front End Friend & Fountain of Fun Facts.

  • @jwr6796
    @jwr6796 Před 24 dny

    🫨

  • @Ant_Dude_YT
    @Ant_Dude_YT Před 24 dny

    Do you know how to fix the viewport height? Ik the width one but not height

    • @KevinPowell
      @KevinPowell  Před 24 dny

      Not sure what you mean? 🤔

    • @Ant_Dude_YT
      @Ant_Dude_YT Před 24 dny

      Viewport but height cuz phones and PC monitors have different height and width, I can fix the width

    • @ihtishamriaz2598
      @ihtishamriaz2598 Před 24 dny

      ​@@Ant_Dude_YT you can use 100svh

    • @thecoolnewsguy
      @thecoolnewsguy Před 24 dny

      You mean to take the whole screen's height or what

    • @Ant_Dude_YT
      @Ant_Dude_YT Před 24 dny

      @@ihtishamriaz2598 what is that? I'm new to these stuff

  • @BossPetta
    @BossPetta Před 20 dny

    This is about 20 years too late 🤣