Go Back   Velocity Reviews > Newsgroups > HTML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

HTML - max-height

 
Thread Tools Search this Thread
Old 12-24-2004, 04:29 PM   #1
Default max-height


I have been struggling for some time, trying to make IE behave as if it
actually understand the css attribute max-height.

In fireFox this code vill work perfectly:

<div style="width: 300px; max-height: 60px; overflow:auto">Some
text</div>

If the amount of text isn't enough to fill out the space, the box decreases
til fit the text. If the amount of text exceeds the height defined, the box
will get a scroll bar.

IE does not understand that and the height of the box depends solely on the
amount of content.

I have come up with a hack (placed in header), that limits the height in IE
too:

<!--[if IE]>
<style type="text/css" media="screen">
#maxi {
height:expression(
document.body.clientHeight > (100/12) *
parseInt(document.body.currentStyle.fontSize)?
"60px":
"auto" );
}
</style>
<![endif]-->

But when the amount of text doesn't fill out the specified height, all that
happens is, the scroll bar dissapears. The box is still at the max height.

Anyone who knows how to make IE do as wanted?

--
Yours
Erik Ginnerskov
http://hjemmesideskolen.dk - http://html-faq.dk
http://ginnerskov.frac.dk




Erik Ginnerskov
  Reply With Quote
Old 12-24-2004, 08:12 PM   #2
Spartanicus
 
Posts: n/a
Default Re: max-height

"Erik Ginnerskov" <> wrote:

>I have been struggling for some time, trying to make IE behave as if it
>actually understand the css attribute max-height.


Google is your friend: http://www.doxdesk.com/software/js/minmax.html

--
Spartanicus
  Reply With Quote
Old 12-24-2004, 11:44 PM   #3
Erik Ginnerskov
 
Posts: n/a
Default Re: max-height

Spartanicus wrote:

>> I have been struggling for some time, trying to make IE behave as if
>> it actually understand the css attribute max-height.

>
> Google is your friend: http://www.doxdesk.com/software/js/minmax.html


I actually knew about this javascript solution, but i'd prefer a css
solution if possible.

--
Yours
Erik Ginnerskov
http://hjemmesideskolen.dk - http://html-faq.dk
http://ginnerskov.frac.dk


  Reply With Quote
Old 12-25-2004, 08:48 AM   #4
Spartanicus
 
Posts: n/a
Default Re: max-height

"Erik Ginnerskov" <> wrote:

>>> I have been struggling for some time, trying to make IE behave as if
>>> it actually understand the css attribute max-height.

>>
>> Google is your friend: http://www.doxdesk.com/software/js/minmax.html

>
>I actually knew about this javascript solution, but i'd prefer a css
>solution if possible.


Not possible. Min/max width/height are typically optional enhancements,
hence using js to get the old beast into line is appropriate.

--
Spartanicus
  Reply With Quote
Old 12-25-2004, 10:46 AM   #5
Erik Ginnerskov
 
Posts: n/a
Default Re: max-height

Spartanicus wrote:
>>> http://www.doxdesk.com/software/js/minmax.html

>>
>> I actually knew about this javascript solution, but i'd prefer a css
>> solution if possible.

>
> Not possible.


Well, this isn't 100% css. But it is small and nice. I just found it this
morning and it works fine in IE:

<!--[if IE]>
<style type="text/css" media="screen">
div.maxi {
height:expression(
this.scrollHeight > 60? "60px" : "auto" );
}
</style>
<![endif]-->

--
Yours
Erik Ginnerskov
http://hjemmesideskolen.dk - http://html-faq.dk
http://ginnerskov.frac.dk


  Reply With Quote
Old 12-25-2004, 02:28 PM   #6
Spartanicus
 
Posts: n/a
Default Re: max-height

"Erik Ginnerskov" <> wrote:

>>> I actually knew about this javascript solution, but i'd prefer a css
>>> solution if possible.

>>
>> Not possible.

>
>Well, this isn't 100% css. But it is small and nice. I just found it this
>morning and it works fine in IE:
>
><!--[if IE]>
><style type="text/css" media="screen">
>div.maxi {
>height:expression(
> this.scrollHeight > 60? "60px" : "auto" );
>}
></style>
><![endif]-->


http://www.spartanicus.utvinternet.ie/test/erik.htm

--
Spartanicus
  Reply With Quote
Old 12-25-2004, 02:31 PM   #7
Dylan Parry
 
Posts: n/a
Default Re: max-height

Spartanicus wrote:

> http://www.spartanicus.utvinternet.ie/test/erik.htm


Indeed, this shows that the code obviously doesn't work, but it's easily
fixed:

<!--[if IE]>
<style type="text/css" media="screen">
div.maxi {
height:expression(
this.scrollHeight > 60? "60px" : "auto" );
overflow:hidden;
}
</style>
<![endif]-->

IE treats the height as a minimum height, even when the scripting is
used, as so will expand the division if necessary. Adding the
overflow:hidden; property tells it not to expand even if necessary.

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
  Reply With Quote
Old 12-25-2004, 02:44 PM   #8
Spartanicus
 
Posts: n/a
Default Re: max-height

Dylan Parry <> wrote:

>> http://www.spartanicus.utvinternet.ie/test/erik.htm

>
>Indeed, this shows that the code obviously doesn't work, but it's easily
>fixed:
>
><!--[if IE]>
><style type="text/css" media="screen">
>div.maxi {
> height:expression(
> this.scrollHeight > 60? "60px" : "auto" );
> overflow:hidden;
>}
></style>
><![endif]-->
>
>IE treats the height as a minimum height, even when the scripting is
>used, as so will expand the division if necessary. Adding the
>overflow:hidden; property tells it not to expand even if necessary.


And that differs from

<style type="text/css" media="screen">
div.maxi {
height:60px;
overflow:hidden;
}
</style>

how ?

--
Spartanicus
  Reply With Quote
Old 12-25-2004, 02:48 PM   #9
Dylan Parry
 
Posts: n/a
Default Re: max-height

Spartanicus wrote:

> And that differs from
>
> <style type="text/css" media="screen">
> div.maxi {
> height:60px;
> overflow:hidden;
> }
> </style>
>
> how ?


Because that code will cause the height to *always* be 60px, even when
the content is less than 60px high. Whereas the code I gave would allow
for heights upto and including 60px but no higher.

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
  Reply With Quote
Old 12-25-2004, 05:54 PM   #10
Erik Ginnerskov
 
Posts: n/a
Default Re: max-height

Dylan Parry wrote:

> Because that code will cause the height to *always* be 60px, even when
> the content is less than 60px high. Whereas the code I gave would
> allow for heights upto and including 60px but no higher.


And your code is the one, I this afternoon implemented as you can se at
http://hjemmesideskolen.dk/html/testsider/maxheight.asp

It works exactly like I wanted.

--
Yours
Erik Ginnerskov
http://hjemmesideskolen.dk - http://html-faq.dk
http://ginnerskov.frac.dk


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump