Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Max-Height with Hidden Overflow

Tags:

html

css

I've looked for quite some time now to find a question identical to mine, and have had no luck. Most of those allowed for fixed-heights whereas mine has to be percentages.

I'm using Google Chrome Beta for development, and IE is not at the top of my priority list. Below is a highly simplified example of my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en-US">
<head>
<title></title>
<style type="text/css">
#container {
    position: absolute;
    top: 0;
    left: 0;
    width: 20%;
    min-height: 64px;
    max-height: 100%;
}

#inner {
    overflow: hidden;
    min-height: 64px;
    max-height: 100%;
}

#border {
    position: absolute;
    top: 20px;
    right: -21px;
    width: 20px;
    bottom: 20px;
}
</style>
</head>
<body>
<div id="container">
    <div id="inner">
        <!-- Content -->
    </div>
    <div id="border">
        <!-- Border Content -->
    </div>
</div>
</body>
</html>

The problem is that #inner extends beyond the bottom of the page, instead of remaining the height of the page. I'm not quite sure how to fix this.

like image 661
skeggse Avatar asked Sep 20 '25 05:09

skeggse


2 Answers

On #container, changing max-height: 100% to height: 100% seems to work.

However, after applying this fix I'm not sure that the other elements in your page look as you intend when there is only a few lines of content inside #inner.

If this isn't quite what you want, I need to know how you want your page to look where there is not much content inside #inner. Also, is it permitted to change the HTML?

Edit:

Attempt #2:

These two demos have the same HTML/CSS as each other, just with a different amount of content:
Long content
Short content

I didn't change your HTML.

CSS changes:

  • + #container {overflow: hidden; padding-right: 22px}
  • changed #border {right: -21px} to #border {right: 1px}
like image 89
thirtydot Avatar answered Sep 21 '25 21:09

thirtydot


Use overflow: hidden, it hids/clips the content that is overflowing the parent container/element. In your case the parent is #container and the child is #inner.

like image 23
João Vitor Gomes Avatar answered Sep 21 '25 22:09

João Vitor Gomes