+ 1

How to center a div horizontally?

Please don't put margin:auto; for the answer because It doesn't work for me.

20th May 2022, 4:45 PM
Coderwe2
Coderwe2 - avatar
3 Answers
0
What is the code you currently have?
20th May 2022, 4:46 PM
Justice
Justice - avatar
0
Show your code, so we can see what you are trying to do. Because margin auto is what centers a div.
20th May 2022, 11:05 PM
Chris Coder
Chris Coder - avatar
0
There are several ways to center a div element in HTML using CSS: Using margin: auto and a fixed width: https://code.sololearn.com/WWS48B9Sy9cu/?ref=app Using display: flex and justify-content: center:Using display: grid and place-items: center: https://code.sololearn.com/WHewXnpSkUOo/?ref=app Using display: grid and place-items: center: https://code.sololearn.com/WlZuG06RSFDI/?ref=app Using display: table and margin: 0 auto: https://code.sololearn.com/WHPX3krVX6cL/?ref=app Using position: absolute and left: 50%, top: 50%, and transform: translate(-50%, -50%): https://code.sololearn.com/W52qUxTHVqgg/?ref=app
21st Dec 2022, 12:56 PM
CalviŐČ
CalviŐČ - avatar