CSS uses calc() to obtain the current visible screen height

CSS uses calc() to obtain the current visible screen height

First, let's take a look at the relative length units of CSS3 (refer to the detailed tutorial):

Relative length units specify the property of one length relative to another length. Relative lengths are more applicable to different devices.

em It describes the size relative to the font used in the current element, so it is also a relative length unit. The default font size of general browsers is 16px, so 2em == 32px;
ex Depends on the height of the English letter x
ch The width of the number 0
rem The font-size of the root element (html)
vw viewpoint width, viewpoint width, 1vw = 1% of the viewpoint width
v viewpoint height, window height, 1vh = 1% of the window height
vmin The smaller of vw and vh.
vmax The larger of vw and vh.

It can be seen that through vh / vw we can get the current screen window width, so in CSS, by calculating this height, the height of the div can be automatically expanded to the screen height. To calculate this height, you can use the calc() function of CSS3 (refer to the detailed tutorial):

The calc() function is used to dynamically calculate the length value.

  • It should be noted that a space is required before and after the operator, for example: width: calc(100% - 10px);
  • Any length value can be calculated using the calc() function;
  • The calc() function supports "+", "-", "*", "/" operations;
  • The calc() function uses standard mathematical operation precedence rules;

So, just set the height of the div to calc(100vh) , 100vh = 100% of the window height, example:

div {
  width: 100%;
  height: calc(100vh);
}

It should be noted that this method is suitable for the web page height being equal to the current screen window height, and JS may still be required according to actual needs.

This is the end of this article about how to use calc() in CSS to get the current visible screen height. For more information about how to use calc() in CSS to get the current screen height, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Discuss the value of Web standards from four aspects with a mind map

>>:  Some simple implementation codes of the form element take registration as an example

Recommend

10 Deadly Semantic Mistakes in Web Typography

<br />This is from the content of Web front-...

Introduction to major browsers and their kernels

Trident core: IE, MaxThon, TT, The World, 360, So...

CocosCreator Skeleton Animation Dragon Bones

CocosCreator version 2.3.4 Dragon bone animation ...

6 solutions for network failure in Docker container

6 solutions for network failure in Docker contain...

How to improve Idea startup speed and solve Tomcat log garbled characters

Table of contents Preface Idea startup speed Tomc...

A brief discussion on the lazy loading attribute pattern in JavaScript

Table of contents 1. Introduction 2. On-demand at...

Detailed steps for installing rockerChat in docker and setting up a chat room

Comprehensive Documentation github address https:...

Solution to the conflict between nginx and backend port

question: When developing the Alice management sy...

Ubuntu 16.04 image complete installation tutorial under VMware

This article shares with you the installation tut...

How to use vw+rem for mobile layout

Are you still using rem flexible layout? Does it ...

JavaScript to achieve Taobao product image switching effect

JavaScript clothing album switching effect (simil...

Detailed explanation of Vue components

<body> <div id="root"> <...

How to use docker to deploy Django technology stack project

With the popularity and maturity of Docker, it ha...