CSS sets the box container (div) height to always be 100%

CSS sets the box container (div) height to always be 100%

Preface

Sometimes you need to keep the height of a box container at 100% at all times, no matter how you zoom the browser. Just like the sidebar on some websites, but directly setting the height of the box container to 100% does not work.

demo

If you want an element's percentage height: 100%; to work, you need to set a valid value for the height of all of its parent elements. Take the demo below for example. The parent elements of div are body and html. So just set both the parent element and the element itself to 100% height.

<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
I want the <div> to have 100% height so I can scale it as I like. </div>
</body>
</html>

CSS:

html,body,div{
   height:100%;
}
/* Simply add some styles to the div */
div{
   background:red;
   width:200px;
}

Effect:

This is the end of this article about how to set the box container (div) height to always be 100% with CSS. For more information about how to set the div height to always be 100%, 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!

<<:  MySQL foreign key constraint (FOREIGN KEY) case explanation

>>:  jQuery implements all shopping cart functions

Recommend

Detailed explanation of Vue px to rem configuration

Table of contents Method 1 1. Configuration and i...

jQuery plugin to implement accordion secondary menu

This article uses a jQuery plug-in to create an a...

Ubuntu starts the SSH service remote login operation

ssh-secure shell, provides secure remote login. W...

Detailed usage of MYSQL row_number() and over() functions

Syntax format: row_number() over(partition by gro...

How to view the database installation path in MySQL

We can view the installation path of mysql throug...

How to update v-for in Vue

Tips: Array change method will cause v-for to upd...

Three ways to configure Nginx virtual hosts (based on domain names)

Nginx supports three ways to configure virtual ho...

Reasons and solutions for slow MySQL query stuck in sending data

Because I wrote a Python program and intensively ...

Setting up shadowsocks+polipo global proxy in Linux environment

1. Install shadowsocks sudo apt-get install pytho...

How to find out uncommitted transaction information in MySQL

A while ago, I wrote a blog post titled "Can...

MySQL reports an error: Can't find file: './mysql/plugin.frm' solution

Find the problem Recently, I found a problem at w...

How to Change Colors and Themes in Vim on Linux

Vim is a text editor that we use very often in Li...

Detailed explanation of Linux zabbix agent deployment and configuration methods

1. Install zabbix-agent on web01 Deploy zabbix wa...