CSS achieves highly adaptive full screen

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:flex to achieve vertical centering. The code is as follows:

<style>
    #login{
        width:100%;
        height: 100%;
        display: flex; 
        justify-content: center;
        align-items: center;
    }
    .login-body{
        width: 600px;
        height: 260px;
        border: 1px solid #000;
    }
</style>

It does not achieve the effect I want, the height of the outer parent element does not fill the entire screen. .

It is horizontally centered, the height of login is not the height of the entire screen

Solution: Give #login a min-height: 100vh, and use display: flex; justify-content: center; align-items: center; to achieve vertical centering.

<style>
    #login{
        width:100%;
        min-height: 100vh;
        display: flex; 
        justify-content: center;
        align-items: center;
    }
    .login-body{
        width: 600px;
        height: 260px;
        border: 1px solid #000;
    }
</style> 

At this time, the height of #login adapts to the height of the entire screen

Viewport units

What is a viewport?

On the desktop, the viewport refers to the visible area of ​​the browser; on the mobile side, it involves 3 viewports: Layout Viewport, Visual Viewport, and Ideal Viewport.

The "viewport" in the viewport unit refers to the visible area of ​​the browser on the desktop; on the mobile side it refers to the Layout Viewport in the Viewport, and the "viewport" refers to the size of the visible area inside the browser, that is, the size of window.innerWidth/window.innerHeight, which does not include the browser area size of the taskbar, title bar, and bottom toolbar. .

According to the CSS3 specification, viewport units mainly include the following 4:

1.vw: 1vw is equal to 1% of the viewport width, and the viewport width is 100vw.

2.vh: 1vh is equal to 1% of the viewport height, and the viewport height is 100Vh.

3.vmin: Select the smallest one between vw and vh.

4.vmax: Select the largest one between vw and vh.

This is the end of this article about how to use CSS to achieve highly adaptive content that fills the entire screen. For more relevant CSS highly adaptive content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of the difference and usage of quotes and backticks in MySQL

>>:  Tips on setting HTML table borders

Recommend

How to periodically clean up images that are None through Jenkins

Preface In the process of continuous code deliver...

In-depth explanation of MySQL stored procedures (in, out, inout)

1. Introduction It has been supported since versi...

Parsing Apache Avro Data in One Article

Abstract: This article will demonstrate how to se...

Introduction to who command examples in Linux

About who Displays users logged into the system. ...

CSS Standard: vertical-align property

<br />Original text: http://www.mikkolee.com...

Vue 2.0 Basics in Detail

Table of contents 1. Features 2. Examples 3. Opti...

Steps to install MySQL 5.7.10 on Windows server 2008 r2

Install using the MSI installation package Downlo...

Problems encountered when uploading images using axios in Vue

Table of contents What is FormData? A practical e...

How to use nginx to simulate blue-green deployment

This article introduces blue-green deployment and...

Draw a heart with CSS3

Achieve resultsRequirements/Functionality: How to...

Briefly understand the MYSQL database optimization stage

introduction Have you ever encountered a situatio...

Web developers are concerned about the coexistence of IE7 and IE8

I installed IE8 today. When I went to the Microso...

MySQL infobright installation steps

Table of contents 1. Use the "rpm -ivh insta...