Why is the height of a label several pixels higher than that of img ?, Label img

Source: Internet
Author: User

Why is the height of a label several pixels higher than that of img ?, Label img

<Li> <a href = "#">  </a> </li>
Style:
Li {
Height: 300px;
A {
Display: block;
Img {
Width: 100%;
Height: 100%;

}
}
}
Effect:

Knowledge supplement: by default, the width and height are the height of the lines in the inline element automatically calculated by the browser, so you can set the background color.
The height of the inline element is related to font-size, but not determined by font-size. It involves anonymous boxes, line boxes, line boxes, content areas, etc.

Answer 1:

Cause:

There is an anonymous text under Element a, and there is an anonymous row-level box outside the text. Some of its default vertical-align is baseline, and it is often affected by line-height, make it have a line-height, so that it has a height. Because of baseline alignment, this anonymous box will sink and open some distance down, so a is elevated.

Solution 1: Eliminate the height of the anonymous box, that is, set line-height: 0 or font-size: 0 for;
Solution 2: Give vertical-align: top to align top, rather than aleline.
Solution 3: Give the img a display: block so that it and the anonymous row-level box are not in the layout context, so there is no line-level box alignment problem.
There are also other solutions, but these are all fundamentally solving the problem. Answer 2: I finally found the reason, because img is a line element, the default display: inline; it is similar to the default behavior of text. The lower edge is aligned with the baseline, rather than sticking to the lower edge of the container. Setting displayp as a block eliminates the difference between the pixels mentioned above. Or set font-size to 0. You can also set the display of label a to block or inline-block, and set the line-height of label a to 0.

 
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.