[英]Fit anchor parent to child image
How do you get rid of the element outline that the a
tag inserts, without ruining the child element?你如何摆脱
a
标签插入的元素轮廓,而不破坏子元素?
<a href="">
<img alt="picsum" src="https://picsum.photos/200/300">
</a>
Ideally highlighting the anchor tag should yield the full width and height of the child element理想情况下,突出显示锚标记应该产生子元素的完整宽度和高度
display: block
should fix this issue: display: block
应该解决这个问题:
a, img { display: block; }
<a href=""> <img alt="picsum" src="https://picsum.photos/200/300"> </a>
What's happening is the <a>
and img
are display: inline
by default, which creates extra space underneath them as inline is made to work well with text.发生的事情是
<a>
和img
是display: inline
默认情况下,这会在它们下面创建额外的空间,因为 inline 可以很好地处理文本。 It may seem stupid that things are this way but it allows an image to fit in nicely with text like you would do in a word processor.事情是这样的,这似乎很愚蠢,但它允许图像很好地适应文本,就像你在文字处理器中所做的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.