CSS Height 100% Percent Not Working

Css height in percent not working

You need to set a 100% height on all your parent elements, in this case your body and html. This fiddle shows it working.

html, body { height: 100%; width: 100%; margin: 0; }div { height: 100%; width: 100%; background: #F52887; }
<html><body><div></div></body></html>

Why is percentage height not working on my div?

Use vh (viewport height) instead of percentage. It will get the height of the browser and size it accordingly, e.g.

height:90vh;

try this code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id ="wrapper">
<div id="tabs" ng-controller="TabsDataCtrl">
<tabset>
<tab id="tab1" heading="{{tabs[0].title}}" ng-click="getContent(0)" active="tabs[0].active"
disabled="tabs[0].disabled">
</tab>

<tab id="tab2" heading="{{tabs[2].title}}" ng-click="getContent(2)" active="tabs[2].active"
disabled="tabs[2].disabled">
</tab>
</tabset>
</div>

<div id="leaflet_map" ng-controller="iPortMapJobController">
<leaflet center="center" markers="markers" layers="layers"></leaflet>
</div>
</div>
</body>
</html>

with css

<style>
#wrapper{height:60vh;}
#tabs {width:20% float:left; height:60vh; overflow-y:scroll; overflow-x:hidden;}
#leaflet-map{width:78%; height:60vh; overflow-y:scroll; overflow-x:hidden;}
</style>

CSS div height 100% not working

You could set the height of parent div1 to 1000px and set the children's height to :inherit.
Here's an example:

#div1{    width:1024px;    height:1000px;    background:red;    overflow:hidden;}#div2{        float:left;    width:100%;    height:inherit;    background:yellow;}#div3{        float:left;    width:460px;    height:inherit;    background-image:url('http://www.ricoh-imaging.co.jp/english/r_dc/caplio/r7/img/sample_04.jpg');    background-size:100% 100%;    background-position:bottom;    background-repeat:no-repeat;}
#div4{ float:left; width:270px; height:inherit; background:violet;}
#div5{ float:left; width:25px; height:inherit; background:black;}
#div6{ float:left; width:269px; height:inherit; background:blue;}
<div id="div1" class="center">    <div id="div2">        <div id="div3"></div>        <div id="div4"></div>        <div id="div5" ></div>        <div id="div6"></div>    </div></div>

Why doesn't height: 100% work to expand divs to the screen height?

In order for a percentage value to work for height, the parent's height must be determined. The only exception is the root element <html>, which can be a percentage height. .

So, you've given all of your elements height, except for the <html>, so what you should do is add this:

html {
height: 100%;
}

And your code should work fine.

* { padding: 0; margin: 0; }html, body, #fullheight {    min-height: 100% !important;    height: 100%;}#fullheight {    width: 250px;    background: blue;}
<div id=fullheight>  Lorem Ipsum        </div>

Height percentage not working in CSS

When you are using % for width, or height, the 1st question you should ask is that 80% of what? So you also need to apply height to the parent element, so assuming that this element of yours is inside the body tag, you need to use this in your CSS

html, body {
height: 100%;
}

So now your div element will be 80% of 100%

Demo

Side Note: Also when you are dealing with absolute positioned elements, you may come across a scenario where your div won't exceed the current viewport height, so in that case you need to have min-height

Div height: 100% not working with body min-height: 100vh

The answer is simple as percentage min-height is calculated based on parent container's height value not min-height.

* {margin:0;}

body {
background: gray;
height: 100vh; /* look here */
}

.container {
background: silver;
margin: 0 20px;
min-height: 100%; /* look here */
}
<div class="container">
<h1>Some generic title</h1>
<p>Some random paragraph</p>
</div>

CSS height 100% not working on TD

Use height:inherit for p tag element.

CSS height: 100% not working in html or body

Thanks everyone for your answers, without them I would not have been able to come up with my solution:

I remembered reading you can mix values in calc(), so I changed the flexbox class to:

.flex-box {
display: flex;
height: -moz-calc(100vh - 105px);
height: -webkit-calc(100vh - 105px);
height: calc(100vh - 105px);
}

That still gave me some padding at the bottom, so I removed the height: 100%; from the html and body tags, and it works perfectly.

Working fiddle: https://jsfiddle.net/n2nkmgvs/



Related Topics



Leave a reply



Submit