Home Web Front-end Front-end Q&A How to set div size with css

How to set div size with css

Apr 09, 2021 pm 02:46 PM
css

In CSS, you can control the div size by setting the width and height of the div. The setting method is: first create an HTML sample file; then set the width of the div through the width attribute; finally set the height of the div through the height attribute. That’s it.

How to set div size with css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

The width attribute sets the width of the element; the height attribute sets the height of the element. These two properties define the width and height of the element's content area, and padding, borders, and margins can be added outside the content area.

Inline non-replaced elements will ignore the width and height attributes.

Attribute values ​​of width attribute and height attribute:

  • auto: Default. The browser will calculate the actual height.

  • length: Use px, cm and other units to define the height.

  • %: Based on the percentage height of the block-level object that contains it.

  • inherit: Specifies that the value of the height attribute should be inherited from the parent element.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
div{
margin-top: 20px;
}
.div1{
background-color: pink;
}
.div2{
width: 200px;
height: 100px;
background-color: palegoldenrod;
}
.div3{
width: 400px;
height: 200px;
background-color: powderblue;
}
</style>
</head>
<body>
<div class="div1">未定义大小的div,自适应</div>
<div class="div2">定义大小的div,宽200px,高100px</div>
<div class="div3">定义大小的div,宽400px,高200px</div>
</body>
</html>
Copy after login

Rendering:

How to set div size with css

[Recommended learning: css video tutorial

The above is the detailed content of How to set div size with css. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

What language is the browser plug-in written in?

See all articles