A deep understanding of CSS attribute display: inline-block

Source: Internet
Author: User

Author: Silence

The display: inline-block attribute is often exposed when CSS is used to implement the performance. The attribute is very vague.
Display: inline-block
The object is presented as an inline object, but the content of the object is presented as a block object. The Inline object next to it will be presented in the same row and spaces are allowed.

Not all browsers recognize this attribute.
Supported browsers include opera and safari.


Unfortunately, the most popular IE and Firefox do not support this attribute (display: inline-will be supported in firefox3-
Block ). However, in Firefox, there are private attributes-moz-inline-box and inline-block. Why is it "like" rather than "God "?
Like? This is because the use of-moz-inline-box will bring many unexpected sequelae. For example, after using this attribute, text-align sometimes has problems.
You must use the private property-moz-box-align of Firefox to solve the problem.

Suggestion: it is best not to use the Firefox private property-moz-inline-box.

Some friends may not support the display: inline-block attribute for the IE mentioned above, indicating that they have doubts or objections. "I always use display: inline-block for inline elements such as a or span in IE ".


Otherwise, display: inline-block is used for inline elements in IE. ie does not recognize any other elements, but display: inline-
Block triggers layout in IE, so that the inline element has the table image of the display: inline-block attribute. From the above analysis, it is not difficult
Understand why setting the display: inline-block attribute for block elements in IE cannot achieve the effect of inline-block. At this time, the block element is only
Layout is triggered by display: inline-block, and it is the row layout. After triggering, the block element is still the row layout, instead of being like in opera.
The block elements are presented as inline objects.

Extended question: How can I implement the display: inline-block effect for block elements in IE?

There are two methods:


1. Use the display: inline-block attribute to trigger the block element, and then define the display: inline so that the block element is presented as an inline object (two
Display must be placed in two CSS statements to achieve the effect. This is a classic bug in IE. If you define display: inline-
Block, and then set the display back to inline or block. layout will not disappear ).CodeAs follows (... Is omitted from other attributes ):

Example source code [Www.52css.com] Div {display: inline-block;...} Div {display: inline ;}

2. Set the block element to inline object submission (set the attribute display: inline), and then trigger the layout of the block element (for example, Zoom: 1 ). The Code is as follows:

Example source code [Www.52css.com] Div {display: inline; ZOOM: 1 ;...}
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.