Css achieves adaptive div width with content

Source: Internet
Author: User
In css, div is a block-level element. When no style is set for div, div excludes one row. When the content is not full, the div width is still the width of a row, not the content width. This article describes how to adapt the div width to the content. For more information about the coders, see. We can use CSS float to set the p width to adapt with the content, so that the default 100% adaptive width of p can be changed to the adaptive width effect starting from 0, and the width increases with the content as the initial width of span increases.

See the following example:

Css achieves adaptive p width with content 

Float content 1 is not set

Float content 2 is not set

Add float style content 3

Add float style content 4 to it

Online operation

Note:The default full-screen width style of p is removed by setting float for p through css. However, when such a box with auto-adaptive content width starting from scratch is used, float floating style cannot be used, we can use the span tag to implement

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.