Solution to the problem of excess space in IMG images in CSS or gaps in tables

Source: Internet
Author: User

When layout the page Div + CSS, you may encounter IE6 (sometimes in Firefox) the problem of unnecessary blank space under the IMG Image Element in the browser is definitely a common solution to this problem ".

1. convert an image into a block-level object

Set IMG to "display: block ;". In this example, add a set of CSS Code: "# sub IMG {display: block ;}". (Ps, the problem I encountered is solved using this method. After I define a IMG {display: block;}, the height of the attribute will not be higher than expected. Be sure not to define IMG {display: block;}. In this case, some images may have different display effects. When text and text are mixed, the images will not be centered, but at the top .)

2. Set the vertical alignment of the image

You can also set the vertical-align attribute of an image to "Top, text-top, bottom, text-bottom. In this example, add a set of CSS Code: "# sub IMG {vertical-align: Top ;}".

3. Set the text size of the parent object to 0 PX.

Adding a row in # Sub: "font-size: 0;" can solve the problem. But this also raises a new problem, and the text in the parent object cannot be displayed. Even if the text is enclosed in some quilt objects, the text size of the sub-object can still be displayed. However, when CSS verification is performed, an error is displayed, indicating that the text is too small.

4. Change the attributes of the parent object

If the width and height of the parent object are fixed and the image size varies with the parent object, you can set "overflow: hidden. In this example, you can add the following code to # Sub: "width: 88px; Height: 31px; overflow: hidden ;".

5. Set floating attributes of images

In this example, add a line of CSS Code: "# sub IMG {float: Left ;}". This method is a good choice to achieve text-and-text mixing.

6. Cancel the space between the Image Tag and the last ending tag of its parent object.

This method should be emphasized that this method may be messy during actual development, because when writing code, in order to make the code more semantic and hierarchical, it is inevitable to provide code indent display through IDE, which will inevitably display labels and other labels in line, for example, DW's "Apply source format" command. Therefore, this method can be used for us to understand a case where a bug occurs. For specific solutions, please refer to the steps for splitting.

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.