Forum Moderators: not2easy

Message Too Old, No Replies

auto height with height attribute specified

auto height with height attribute specified

         

gggmicrosystems

6:33 pm on Oct 16, 2007 (gmt 0)



Is it possible that a div will expand depending on the length of content with the height specified?

Example:

<html>
<head>
<style>
#test {
width: 150px;
height: 100px;
border: 1px #ff0000 solid;
}
</style>
</head>

<body>
<div id="test">
Test
</div>
</body>
</html>

i want the div's height to be exactly 100px in height if the content is as small as that but how can I make that div expand if the content increases? if I specify the height, the text overlaps the div..

Thanks

CodilX

6:52 pm on Oct 16, 2007 (gmt 0)

10+ Year Member



I made my divs relative, and height to auto. if the text expands then the other divs drop down a bit.

hope this helps :)

Demaestro

7:16 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



gggmicrosystems

Try this.....

<style>
#test {
width: 150px;
height: 100px;
overflow:auto;
border: 1px #ff0000 solid;

}
</style>

gggmicrosystems

7:52 pm on Oct 16, 2007 (gmt 0)



Demaestro,

the overflow: auto; would only put a scroll bar on the div, it doesn't change the height of the div.

CodilX,

hmm... i don't want to assign the height as auto because I want the div 's height to remain at 100px when the div has small content.

Thanks for all your reply. Appreciate.

Marshall

8:03 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could use {min-height: 100px;} but that is no guarantee.

Marshall

Demaestro

8:04 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hmmm... try this.. adding in min-height as well... I think you need both to work in IE and FF.

width: 150px;
height: 100px;
min-height: 100px;
overflow:auto;
border: 1px #ff0000 solid;

Demaestro

8:05 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



^^^ of course Marshall beat me to it...

gggmicrosystems

8:07 pm on Oct 16, 2007 (gmt 0)



Marshall,

It's ok.. it worked on Firefox. not on IE. Thanks. It a good start. I'll look for another alternative for this min-height for IE. Thanks..

Demaestro

8:07 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This should do it too

min-height:500px;
height:auto;
height:500px;

It is a whacky hack but it seems to work.

gggmicrosystems

8:18 pm on Oct 16, 2007 (gmt 0)



Demaestro, I got it...

Thanks all for the reply.

min-height doesn't work on IE.

tested: Firefox 2.0.0.7, IE6, Safari

This is the source:

<html>
<head>
<style>
#test {
border:1px solid #f00;
min-height:100px;
height:auto;
}
/* for Internet Explorer */
/*\*/
* html #test {
height: 100px;
}
/**/
</style>
</head>

<body>
<div id="test">
Test
</div>
</body>
</html>

Demaestro

9:26 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



awesome man... glad you got it....

min-height should be the solution for all.. maybe one day

Marshall

11:37 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here's a physical cheat.

Put a 1px wide by 100px high <div> in the div that contains the text and float it right.

<div id="content">
<div style="width: 1px; height: 100px; float: right;">
<p>text text text.............</p>
</div>

It is along the same principle of using an image to force cell height.

Marshall

Setek

1:17 am on Oct 17, 2007 (gmt 0)

10+ Year Member



Something like this is fairly simple, it shouldn’t require superfluous elements…

Problem: IE doesn’t accept

min-height
.
Standards-compliant browsers set
height
explicitly.

Workaround: Thankfully, IE does not set

height
explicitly, rather, fluidly, as in, “it works the way
min-height
does.”

Solution: You should really put IE-specific code in a conditional comment that only affects IE 6, since IE 7 correctly accepts

min-height
. Hacks such as the Star (*) hack are still applied by IE 7 in quirks mode. Conditional comments would be as simple as:

<head>
<style type="text/css">
#container { min-height: 100px; }
</style>
<!--[if IE 6]>
<style type="text/css">
#container { height: 100px; }
</style>
<![endif]-->
</head>

And that’s all you need to know :)

gggmicrosystems

4:19 am on Oct 17, 2007 (gmt 0)



Hey Setek...

Thanks...

This one looks clean... I'll be using this one...

Thanks again Guys... :D