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