CSS invisible voids (inline pits)

Source: Internet
Author: User

Long time no writing, and recently a little busy, plus their own in a video-to-gif thing (GitHub: Portal), is a Node-webkit (Mac version with Atom-shell) do a desktop application, also do not write anything, But when it comes to this thing, there's a problem with the gap, so check the information, discuss, research ...

First look at the debug code

<! Doctype html>

Just plain use div to install an IMG, and then let div more than img 1px (somewhat similar to the border), but the problem is:

It is clear that the yellow part is the div padding, but the following padding is relatively large.

There are 3 ways to solve the problem (that is, my CSS commented out 3 lines):

To the Father element plus--

1:font-size:0;

or add to the IMG element--

2:vertical-align:bottom;

3: Display:block;

But why? If the General monkey, will certainly use, can solve the problem on the line, but we are not the general monkey, we are the program APE!!!

Want to go, since font-size:0, can solve, should be related to font.

To explain why, I cut 2 more diagrams to aid understanding:

The first picture, I use the console to the equivalent ruler, moved to div padding as large, found that only p below is blocked, and the other seems to be the same distance from the console of the gap is the same size, so I cut the second picture,

Vertical-align is used to set the baseline, when the font-size is 0, there is no baseline gap, so the baseline should be the Ghost ~

After a turn over the wall found that the original vertical-align default baseline is base line, (so p will be partially blocked).

Write here, suddenly think of the previous 2 inline elements between the gap, but also to the Father element plus font-size to solve, and this time to IMG Plus block can also solve the problem, in the final analysis or the pan element of the pot ~. all inline elements have the same font size and row height attributes as the text, so IMG is also affected by the baseline, which is the problem

CSS invisible voids (inline pits)

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.