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/