remove link underline from image only if the anchor tag contains an img

后端 未结 5 2111
灰色年华
灰色年华 2020-12-19 13:28

        
    

for the above html code I am using the fol

5条回答
  •  粉色の甜心
    2020-12-19 14:04

    After a lot of Googling I finally found a neat trick that worked for me:

    a img { border:none; vertical-align:top; }
    

    Why this works?

    By default both anchors and images are inline elements and by applying vertical-align:top; to an image inside an anchor, we move the anchor to the top of the image. For some reason images have higher z-index than anchors.

    Source: Remove Border from Image Links

    By the way, it would work great with a parent selector like a < img ... unfortunately this isn't implemented yet, but is in the workings. Take a look here: https://stackoverflow.com/a/45530/114029

提交回复
热议问题