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

Meta viewport makes the web page full screen display control on iPhone

In desperation, I suddenly thought, how is the Sin...

10 bad habits to avoid in Docker container applications

There is no doubt that containers have become an ...

MySQL database advanced query and multi-table query

MySQL multi-table query Add a worksheet -- User t...

What should I do if I can't view the source file of a web page?

Q: Whether using Outlook or IE, when you right-cl...

6 Uncommon HTML Tags

First: <abbr> or <acronym> These two s...

How to install vim editor in Linux (Ubuntu 18.04)

You can go to the Ubuntu official website to down...

How InnoDB cleverly implements transaction isolation levels

Preface In the previous article Detailed Explanat...

Summary of various forms of applying CSS styles in web pages

1. Inline style, placed in <body></body&g...

Simple implementation of html hiding scroll bar

1. HTML tags with attributes XML/HTML CodeCopy co...

Steps to deploy Docker project in IDEA

Now most projects have begun to be deployed on Do...

How to configure MySQL8 in Nacos

1. Create the MySQL database nacos_config 2. Sele...

The pitfall record of case when judging NULL value in MySQL

Table of contents Preface Mysql case when syntax:...

Ubuntu View and modify mysql login name and password, install phpmyadmin

After installing MySQL, enter mysql -u root -p in...

How to deploy Tencent Cloud Server from scratch

Since this is my first post, if there are any mis...