+ 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.
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
0
<div align="center" width=200 height=500>SoloLearn</div>
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