I'm trying to align my img in center, but not happens with this code:
<div id="foto" style="position:relative; left:50%;">
<img src="Imgs/pa1.PNG" width="160" height="240" alt="foto1" />
</div>
I'm trying to align my img in center, but not happens with this code:
<div id="foto" style="position:relative; left:50%;">
<img src="Imgs/pa1.PNG" width="160" height="240" alt="foto1" />
</div>
Use text-align:
<div id="foto" style="text-align: center;">
<img src="Imgs/pa1.PNG" width="160" height="240" alt="foto1">
</div>
Dont use inline style. See this demo
If you give outer div text-align:center;
then all your text in your div will align in center. So its not a good practice.
<div id="foto">
<img src="http://placehold.it/250x250" width="160" height="240" alt="foto1">
</div>
CSS
#foto {
width: 100%;
}
#foto img {
display: block;
margin: 0 auto;
}
Try below css.
img {
display: block;
margin: 0 auto;
}
or
#foto {
text-align: center;
}
CSS
#foto
{
margin-left:auto;
margin-right:auto;
width:1000px;//give width accordingly
}
HTML
<div id="foto" >
<img src="Imgs/pa1.PNG" width="160" height="240" alt="foto1">
</div>
With an image I feel you can simply apply the css rule "text-align: center;"
But if thats not working for you could try taking out the position rules and giving the "foto" div a width and an auto margin like so:
style="width:960px; margin: 0 auto;"
I am also not sure if you are aware of style sheets but seperating your CSS from your HTML is also good practice.