Reputation: 3823
My html:
<p>
<a href="#">
<img src="image.png" />
</a>
</p>
<p>Some text</p>
I want to move image to center without making it block. With block link goes clickable in all width.
Tried:
img{
margin:0 auto;
display:inline-block;
}
but it doesn't work.
Fiddle with centered image but wrong link.
Image width can be different.
Any idea how to make image center and leave clickable area only on image?
Upvotes: 1
Views: 3671
Reputation: 902
try this
<p id="imgPara">
<a href="#">
<img id="image" src="http://httpd.apache.org/docs/current/images/feather.gif" />
</a>
</p>
<p>Some text</p>
#imgPara{
text-align: center;
}
http://jsfiddle.net/Shashi0812/YAusb/
Upvotes: 1
Reputation: 38252
You can set this CSS for the a
tag:
a{
margin:0 auto;
display:table;
}
The demo http://jsfiddle.net/9653Y/4/
Upvotes: 1
Reputation: 15699
Align parent of img
to center.
HTML:
<p class="center">
<a href="#">
<img src="http://httpd.apache.org/docs/current/images/feather.gif" />
</a>
</p>
CSS:
.center{text-align:center;}
Upvotes: 0