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

How to modify create-react-app's configuration without using eject

1. Why is eject not recommended? 1. What changes ...

CentOS 7 installation and configuration method graphic tutorial

This article records the detailed installation tu...

Thinking about grid design of web pages

<br />Original address: http://andymao.com/a...

Thoroughly understand JavaScript prototype and prototype chain

Table of contents Preface Laying the foundation p...

Nginx Layer 4 Load Balancing Configuration Guide

1. Introduction to Layer 4 Load Balancing What is...

Solution to the paging error problem of MySQL one-to-many association query

The query data in the xml price inquiry contains ...

Detailed explanation of building MySQL master-slave environment with Docker

Preface This article records how I use docker-com...

Detailed analysis of Vue child components and parent components

Table of contents 1. Parent components and child ...

WeChat applet uses canvas to draw clocks

This article shares the specific code of using ca...

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...

Solution to mysql ERROR 1045 (28000) problem

I encountered mysql ERROR 1045 and spent a long t...

Complete steps to install MySQL 8.0.x on Linux

MySQL Introduction to MySQL MySQL was originally ...