Solution to the problem of gap between CSS tags

Source: Internet
Author: User
Today, in the debug code, I encountered a CSS problem. Notice that there are some gaps. Previously encountered such problems, I generally practice is directly add display:block to solve, today in-depth analysis of the reasons.

First look at this gap corresponds to the source code as follows

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>

The code does not seem to have any problems, then the problem really comes:

Where did the gap go?

Problem Reason:

Picture text and other inline elements are aligned to the baseline of the parent element by default, and the baseline has a certain distance from the parent's bottom ( this distance is related to the font-size,font-family, not necessarily 5px), so setting vertical-align:top/bottom/text-top/text-bottom can prevent this from happening. And not only Li, but also the other block elements including IMG will have this phenomenon.

Solution:

Display:block the picture

Set img as "Display:block;". In this example, add a set of CSS code: "img {display:block;}". A more common practice.

Set the alignment of a picture

That is, setting the Vertical-align property of a picture to "Top,text-top,bottom,text-bottom" can also resolve

Set the parent object text size of a picture to 0px

"FONT-SIZE:0;" can solve the problem. However, this raises a new problem, and the text in the parent object cannot be displayed. Even if the text part of the quilt, set child object text size can still be displayed, but in the CSS when the time will prompt text too small error.

Set the float of a picture

In this case, add a line of CSS code: "#sub img {float:left;}". This approach is a good choice if you want to implement a graphic mix.

I prefer to set floats or block shows, and some people prefer to use vertical-align to solve them.

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.