+ 1

[HTML] Does the align code work with the image?

I tried making my own website in Notepad; I'm having trouble aligning my image to the center. My first question is: is it possible to align the image? If yes, how? Here is the code: <img src= "https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/HTML.svg/1200px-HTML.svg.png" alt="" align="center" height="30%" width="20%">

13th Jan 2018, 1:06 AM
SoloMoney
SoloMoney - avatar
3 ответов
+ 3
align="center" will align the content inside. Not the element itself. Make your image block-level element and center it with margin: 0 auto;
13th Jan 2018, 1:19 AM
Toni Isotalo
Toni Isotalo - avatar
+ 2
Thanks guys, that worked. Really appreciate it.
13th Jan 2018, 3:31 AM
SoloMoney
SoloMoney - avatar
+ 2
"align" attribute and <center> tag are deprecated in html5... You should use css instead: apply "text-align:center;" to container of the <img> element, which is default of inline type (behaviour as text-content) ^^ <p style="text-align:center;"> <img src="url" alt="" style="width:20%; height:30%;"> </p> However, be careful when sizing your <img> element: percentage values are relative to parent size (if parent height was not specified -- auto value -- it should be relative to the viewport height)... so, it will not preserve the original image ratio (to preserve it, define only one dimension, and let the other with its default auto value) ;)
13th Jan 2018, 6:38 AM
visph
visph - avatar