Some thoughts on the gap between CSS Display:inline-block

Source: Internet
Author: User

Yes, there are always a class of attributes to help you easily find shortcuts, but also for you to add trouble, such as the mastermind of this article Display:inline-block. The role of the front end is to present the object as an inline object, but the object's content is presented as a block object. Adjacent inline objects are presented in the same line, allowing spaces. Unfortunately, it did not get all the browser support, such as IE6, 7 and old Firefox completely ignore it, because the old version of Firefox has almost disappeared from the market, so nominally Firefox is supporting Display:inline-block, In addition, the great Chrome, Opera, Safari can be well supported. Nevertheless, it is still possible to make the IE6, 72-bit pair docile by hack, like this:









<ul class= "Demo01" >
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>


. demo01{width:327px; margin:0 Auto;
Demo01 li{display:inline-block; *display:inline; *zoom:1; width:100px; height:30px; border:1px solid #848484; Background-color: #999;}

What needs to be explained is that display:inline-block in IE only triggers the layout, which is the row layout, and the block element is still the row layout after the trigger. So the block element is presented as an inline object, and Display:inline plays this role (* is identified only by IE6, 7), and then triggers layout through zoom:1. Can realize the so-called inline-block. But things are far from over, this guy faces a number of funeral needs you to deal with, for example, will default to have the outside margin (IE6, 7 except). And before this problem, you may need to relax and look at the following phenomenon.

As mentioned above, although there are gaps in the default Inline-block, So when we try to set Margin-bottom or Padding-bottom for one of these elements (you can also try to set margin-top or padding-top), it renders the following model:


What does that mean? We can use the Vertical-align:top property to eliminate the vertical gap.
So much singularity makes us curious and puzzled about CSS, perhaps because of this, we let floating layout become mainstream. The first part of the article mentions: Inner-block allows spaces, does this mean anything? After some analysis, we were surprised to find the answer: the culprit is a blank break, including line breaks.
So we immediately eliminate the space, line and other guys, the results verify the correctness of this inference. But that's not a good solution, because it's hard to avoid spaces like newline between complex HTML combinations. To solve the bell still need to fasten the person, the phenomenon that CSS causes, should be solved by the CSS itself.

Maybe?? The Gray Huan ㄊ choke on the lemon? Hammer yarn Costing Cong Yi Ping, the?/p> of scandium Zhang P barrel Mulberry


. demo02{width:306px margin:0 Auto; font-size:0;}
Demo02 li{display:inline-block; *display:inline; *zoom:1; width:100px; height:30px; border:1px solid #848484; Background-color: #999; Vertical-align:top;}











The code is as follows
Copy Code


. demo02{width:306px margin:0 Auto; font-size:0;}
Demo02 li{display:inline-block; *display:inline; *zoom:1; width:100px; height:30px; border:1px solid #848484; Background-color: #999; Vertical-align:top;}


Let this question get handshake, is font-size:0; Of course, Vertical-align:top is half a hero, although his role is no longer important when Font-size appears.


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.