The way to set the width of a div in css is to add the width attribute to the div and set the attribute value to an appropriate value, such as [width:100px;]. We can also set the percentage width of the div, such as [width:50%;].
The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.
In fact, it is very simple for us to set the width of a div, because there is a ready-made attribute width in CSS, which is used to set the width of the element.
Attribute value:
auto Default value. The browser can calculate the actual width.
#length Use px, cm and other units to define the width.
% Defines the width as a percentage based on the width of the containing block (parent element).
#inherit Specifies that the value of the width attribute should be inherited from the parent element.
Sample code:
这个段落的高和宽是 100px.
这是段落中的一些文本。这是段落中的一些文本。 这是段落中的一些文本。这是段落中的一些文本。 这是段落中的一些文本。这是段落中的一些文本.
Related video sharing:css video tutorial
The above is the detailed content of How to set the width of div with css. For more information, please follow other related articles on the PHP Chinese website!