+ 10
How can we align a div element to center??
https://code.sololearn.com/WrZJZI6mOPyv/?ref=app How can I align this rectangle to center ??
8 Respuestas
+ 12
Now it's centered in my tab
https://code.sololearn.com/Wb7kj4E9n2cc/?ref=app
+ 9
If you want to centred it top no need those <br>
+ 5
you can simply add <center> tag.
<center>
<div></div>
</center>
it will align div element to the center.
+ 3
//I prefer css for this
margin:0 auto;
for inline elements display:block required
+ 2
Thanks
+ 2
thanks
+ 1
well listen this, every div is block level element, that means that every block level element starts on a new line. You can set margin-left and margin-right to auto on div and it will center it, but width have to be 100% and box-sizing: border-box; so margin will affect div and not add margin to div width (div will be "example" 98% width and margins 1% :) If you want something to verticaly align in div, you have to set div to be inline-block , bcs vertical-align works only on inline elements. Hope this helps and sorry on bad language
+ 1
Also note please, many answers recommend using the <center> tag. This tag has been deprecated in HTML 5 and may no longer work in new browser versions so please don't follow this advice.