+ 1

How do i centralize a div element in html?

HTML: <body> <div id = 'ss'> </div> </body> CSS: #ss { background-color: #000022; position: relative; width: 40px; height: 40px; left: 50%; } 50% doesn't work because i have to do 50% - ss.width / 2 but that doesn't work in css. Align doesn't work either. So how do i do it?

18th Aug 2018, 11:53 AM
Damon Keane
3 Respostas
+ 4
width: calc(50% - (40px / 2));
18th Aug 2018, 12:01 PM
Toni Isotalo
Toni Isotalo - avatar
18th Aug 2018, 11:58 AM
Janning⭐
Janning⭐ - avatar
0
There are many ways in css to achieve it. If this one helps☺️☺️. https://code.sololearn.com/Wv8bTV92Qz95/?ref=app
18th Aug 2018, 1:05 PM
Meet Mehta
Meet Mehta - avatar