I have a .container div just after body that contains everything in page how to center it?

you are viewing a single comment's thread
view the rest of the comments
[–] 6 points 10 months ago (6 children)

https://www.w3schools.com/howto/howto_css_center_website.asp

Use a container element and set a specific max-width . A common width many websites use is 960px. To actually center the page, add margin: auto .

  • source
  • hideshow 6 child comments
  • [–] [S] 2 points 10 months ago* (5 children)

    How to make it centered vertically as well?

  • source
  • parent
  • hideshow 5 child comments
  • [–] 2 points 10 months ago (3 children)
  • [–] [S] 2 points 10 months ago (2 children)

    Is it a good idea to make body a flexbox? Is there any standards for doing this?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 10 months ago

    Not sure what best practice is broadly, but in general display: flex is the first tool I reach for if I need to position child elements a little more carefully.

    It's good for most things more complex than just margin/padding/text-align. If it gets too complex for flexbox, dig into CSS grid.

  • source
  • parent