How to set the width of div with css

王林
Release: 2023-01-06 11:13:57
Original
6640 people have browsed it

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%;].

How to set the width of div with css

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.

这是段落中的一些文本。这是段落中的一些文本。 这是段落中的一些文本。这是段落中的一些文本。 这是段落中的一些文本。这是段落中的一些文本.

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!