Home > Web Front-end > CSS Tutorial > How to make a div fill the entire screen (css)

How to make a div fill the entire screen (css)

不言
Release: 2018-05-09 11:41:08
Original
4837 people have browsed it

This article mainly introduces the method (css) of making div fill the entire screen. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

There is only one in the body When p, you can use this method to make p fill the entire screen.

1. Set positioning for p.

 Review——

There are five attributes of position in css:

Static: Default value, No positioning

Absolute: Absolute positioning, positioning relative to the parent element

## Relative: Relative positioning

Fixed: Fixed positioning, positioned relative to the browser window

Inherit: Inherit positioning information from the parent element

In addition to the default values ​​​​static and In addition to inherit, adding the other three can achieve window adaptation.

The code is as follows:

 1 <style> 
 2         *{ 
 3             margin: 0; 
 4             padding: 0; 
 5         } 
 6         div{ 
 7             width:100%; 
 8             height: 100%; 
 9             background: yellow;
 10             position: absolute;
 11         }
 12 
 13 </style>
 14 
 15 
 16 <body>
 17 
 18 <div></div>
 19 
 20 </body>
Copy after login

2. Let p fill the screen by setting the width and height of html and body

 1 <style> 
 2         *{ 
 3             margin: 0; 
 4             padding: 0; 
 5         } 
 6         html,body{ 
 7             width: 100%; 
 8             height: 100%; 
 9         }
 10         div{
 11             width:100%;
 12             height: 100%;
 13             background: yellow;
 14         }
 15 </style>
 16 
 17 <body>
 18 <div></div>
 19 </body>
Copy after login

The above is the entire content of this article, more For related content, please pay attention to the PHP Chinese website.


The above is the detailed content of How to make a div fill the entire screen (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