+ 2

How do you center an img?

i cant get it

6th Jan 2017, 2:17 AM
Matrix Gaming
Matrix Gaming - avatar
5 Antworten
+ 3
@Chris James img {text-align: center} will not align the image to the center because it aligns all the children and the content of the tag only. <div><img></div> with div {text-align: center} will.
6th Jan 2017, 3:08 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
text-align: center; will also center images
6th Jan 2017, 3:05 AM
Chris James
Chris James - avatar
+ 1
@cheese, u r stating the obvious. <center> tag is not supported in html5
6th Jan 2017, 3:17 AM
Chris James
Chris James - avatar
+ 1
Don't use the align attribute as that is deprecated in HTML 4 and marked as obsolete in HTML 5. Use Flexbox if you are targeting a remotely modern browser. Otherwise you should be able to use something like this: .my-img { display: inline-block; margin: 0 auto; }
6th Jan 2017, 4:31 AM
James Durand
James Durand - avatar
0
You can add a css "class" .center { text-align: center; align-content: center; }
6th Jan 2017, 4:35 AM
Jesús Alejandro Panduro Diaz
Jesús Alejandro Panduro Diaz - avatar