Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css height 100% does not honor the background color on slide/show in jquery

Tags:

css

i have this code:

<div id="left">
    <div>text</div>
    <p>
        text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br> text<br>
    </p>
</div>

js:

$('div').click(function() {
    $('p').show();
});

and css:

html, body {
    height: 100%;
}
#left {
    background: red;
 height: 100%;   
    width: 200px;
}
p { display: none; }

-- http://jsfiddle.net/AfRH2/1/

now, when you click on "text" the "p" should appear with its text. why my background color does not work? i want the div to expand with the color

enter image description here

like image 959
pupa Avatar asked Apr 10 '12 18:04

pupa


People also ask

Why is my background color not showing up CSS?

that is because you have set the background color, and then overwritten it by using the background shorthand…. either move the background-color call after the background shorthand, or add it TO the shorthand… the browser interprets your current code like this…

What does CSS height 100% do?

height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

Why is height percent not working CSS?

Height % is based on it's parent (so you have to set every element above the target element to 100%) , there are a few workarounds to this though. For instance you can set it to height: 100vh; This will create the element to be 100% of your window height. Or you can use px instead.

How do I change my background height to full color in CSS?

We can set a full-page background color by simply changing the screen height of an HTML body. In Tailwind CSS, we use an alternative of CSS background-color property which is represented as background-color-opacity ( eg: bg-blue-200 ) and it is used to specify the background color of an element.


2 Answers

You have to add the height: auto or height: auto !important and the min-height: 100%;

html, body {
    height: 100%;
}
#left {
    background: red;
    height: auto !important;
    min-height: 100%;
    width: 200px;
}
p { display: none; }

see the jsfiddle: http://jsfiddle.net/AfRH2/7/

like image 166
Book Of Zeus Avatar answered Sep 23 '22 19:09

Book Of Zeus


If you remove the height: 100% then you don't get the red background before all the text is shown. Change it to min-height: 100% and it solves your issue (at least it does in the fiddle).

like image 41
idrumgood Avatar answered Sep 23 '22 19:09

idrumgood