How does CSS implement adaptive div width based on content and CSS div width

Source: Internet
Author: User

How does CSS implement adaptive div width based on content and CSS div width

How does CSS implement adaptive div width based on content:
Suggestion: writing code as much as possible can effectively improve learning efficiency and depth.
In practical applications, there may be such a need, that is, the div needs to be adaptive Based on the width of the content. Many developers may mistakenly think that width can be adaptive with content without setting the div width, because by default, the div width is, that is, the width of the entire parent element is occupied.
The code example is as follows:

<! DOCTYPE html> 

The code above shows that by default, we cannot achieve the desired effect.
The following code is modified:

<! DOCTYPE html> 

The above code achieves what we want, and the compatibility of various browsers is good, mainly to add the following core code:

display:inline-block; *display:inline; *zoom:1;

Of course, inline elements do not have the above troubles, because inline elements do not have the ability to set width and can only adapt width with the content.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 4629.

For more information, see: http://www.softwhy.com/divcss/

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.