Any one got a bit of css to center text or element in a div please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Any one got a bit of css to center text or element in a div please?

Hi all, I'm looking for a snippet of code for centering anything in a div.

7th May 2020, 3:54 PM
Speedyridge
Speedyridge - avatar
3 Answers
+ 1
<title>Page Title</title> <style> div{ background-color:blue; width:200px; height:200px; align-items:center; justify-content:center; display:flex; } </style> </head> <body> <div>SoloLearn</div> </body> taken from here https://stackoverflow.com/questions/5703552/css-center-text-horizontally-and-vertically-inside-a-div-block
7th May 2020, 4:11 PM
Abhay
Abhay - avatar
0
<div align="center" width=200 height=500>SoloLearn</div>
7th May 2020, 3:59 PM
Dasarath Singh
0
always remember, when a div is containing another div or container elements then you can use margin:0 auto; at the div.. it will center it.. but if the div has child as text formatting tags such as h1 to h6, p, span then text-align:center; to the element or to the parent will do the job and other best use it flexbox properties
7th May 2020, 4:51 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar