Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

There is a blank problem with the image elements of the HTML-CSS layout img


May 30, 2021 Article blog



In the page's HTML-CSS layout, encounter IE6 (of course, sometimes Firefox will occasionally encounter) the picture element img under the problem of excess white space is absolutely common, for the solution to this problem is also "see the machine", according to the reasons for different to use different solutions, here to solve the image picture layout directly under the redundant gaps of the BUG common methods summarized for your reference.

1, convert the picture to a block-level object

That is, set img to:

display:block;

In this example, add a set of CSS code:

#nav img {vertical-align:top;}

2, set the vertical alignment of the picture

That is, setting the vertical-align property of the picture to "top, text-top, bottom, text-bottom" can also be resolved. As in this example, add a set of CSS code:

#nav img {vertical-align:top;}

3, set the text size of the parent object is 0px

That is, add a line to the .nav:

font-size:0;

can solve the problem. B ut it also raises new questions, where text cannot be displayed in the parent object. S etting the text size of a child object can still be displayed even if the text portion is enclosed by the child object, but prompts for an error that the text is too small when the CSS validates.
4, change the property of the parent object

If the parent object is wide and high, and the picture size depends on the parent object, you can set:

overflow:hidden;

to solve. In this example, you can add the following code to the #sub:

width:88px;height:31px;overflow:hidden;

5, set the floating properties of the picture

That is, add a line of CSS code to this example:

#nav img {float:left;}

This approach is a good choice if you want to implement graphic mixing.

6. Remove the space between the picture label and the last end label of its parent object.

Like what:

<img src="https://www.w3cschool.cn/" />

<div style="width:195pxheight:24px;clear:bothbackground:#B51D9F; ">网页设计</div>

修正为:

<img src="https://www.w3cschool.cn/" /> <div style="width:195pxheight:24px;clear:bothbackground:#B51D9F; ">网页设计</div>