我的HTML:
<p>
<a href="#">
<img src="image.png" />
</a>
</p>
<p>Some text</p>
我想将图像移动到中心而不会阻挡它。使用块链接可以在所有宽度上单击。
尝试:
img{
margin:0 auto;
display:inline-block;
}
但它不起作用。
Fiddle with centered image but wrong link
图像宽度可以不同。
知道如何制作图像中心并仅在图像上留下可点击区域吗?
答案 0 :(得分:1)
试试这个
<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;
}
答案 1 :(得分:1)
答案 2 :(得分:0)
将img
的父级与中心对齐。
HTML:
<p class="center">
<a href="#">
<img src="http://httpd.apache.org/docs/current/images/feather.gif" />
</a>
</p>
CSS:
.center{text-align:center;}
答案 3 :(得分:-1)
将保证金变更为50%
img{
margin:0 50%;
display:inline-block;
}