Forum Moderators: not2easy

Message Too Old, No Replies

That 100% height thing again . . .

         

rocknbil

3:22 am on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I try to avoid 100% height. Maybe I'm going at this wrong, but have an existing tabled layout I'm trying to convert without visual change.

Scenario:

----- bunch of content here, then --------------
------------------------------------------------
----- a "Box" with graphic borders -------------
----- in the vertical middle of the -----------
----- graphic borders are two graphics --------
<--------------------- HERE ------------------->
----- that must stay in the --------------------
----- approximate visual "middle" --------------
----- of variable content ----------------------
------------------------------------------------

Never know how much content, must resize with zoom or text change.

I know about parent height having to have a 100% height. But I think . . . I'm up against the height of the viewport. This is verified by setting body height to 200%. Which of course won't work.

Is there a better way? Of course tables behave fine, like the Apollonian structures they are . . . ptooey.

The code demonstrates the mess I've gotten into. Borders for clarification only.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Vertically center div in side divs</title>
<style type="text/css">
/* without it, side boxes containing side borders won't go to 100% height */
body,html { height:100%; }
#outer-div { width: 100%; height:100%; border: 1px solid #ff0000; }
#left-vert { float:left; width: 27px; height:100%; border: 1px solid #0000ff; }
#right-vert { float:right; width: 27px; height: 100%; border: 1px solid #0000ff; }
#left-vert div,
#right-vert div {
width:27px;
height:100px;
position:relative;
top:50%;
border:1px solid #000;
}
.clear-div { clear:both; }
</style>
</head>
<body>
<div id="outer-div">
<div id="left-vert"><div></div></div>
<div id="right-vert"><div></div></div>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<div class="clear-div"></div>
</div>
</body>
</html>

limbo

12:19 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Rocknbil

You seen these two posts?

[webmasterworld.com...]
[webmasterworld.com...]

rocknbil

7:40 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The second, absolutely and is how I arrived at the above, the first, I must have overlooked in digging through the results, will review shortly, thanks . . . However it occurred to me I could do

<div (border left)
<div (border right)
<div (left graphic, transparent + bg image, bg position middle)
<div (right graphic, transparent + bg image, bg position middle)

Which is warming up to a serious case of divitis worse than tables, or close to it . . .

rocknbil

10:56 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Played around with swa66's ingenious solution [webmasterworld.com] quite a bit. Neither his or my thoughts above seem to work. The "bordered puzzle" above has to fit below all the content, doesn't work inside ".middle" and placing it below .middle robs the left-vert and right-vert boxes of their 50% top positioning (carefully insuring the descending parents are 100% height.)

Worse, something I'd left out (err, overlooked) in my original post: the borders above and below those two boxes are different fills, like


-- border image is shades of red
-- "joining" graphic
-- border image is shades of gold

I'm beginning to think I've found one that will only work with tables with indeterminate content. Tabled layout example below, I've subb'ed out the background graphics for colors so it's a quick copy/paste. The blue and green "boxes" are the different divider graphics, and as you can see they stay perfectly centered vertically, the content inside the table can expand and contract as required.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Vertically center div in side divs - table version</title>
<style type="text/css">
#main, #content,
#list-table{ min-width: 700px; max-width:1020px; width: 100%; padding:0; }
#main{ width: 98%; margin: 0 auto 0 auto; border:1px solid #000; }
#content{ border:1px solid #ff0000; }
#lt-border-top,#rt-border-top,
#lt-border-bot,#rt-border-bot,
#lt-graphic,#rt-graphic{ font-size:2px; width: 27px; }
/* these are actually IMAGES */
#lt-border-top{ background:#ffff00; }
#rt-border-top{ background:#992626; }
#lt-border-bot{ background:#992626; }
#rt-border-bot{ background:#ffff00; }
#lt-graphic{ height:27px; background:#16dee9; }
#rt-graphic{ height:27px; background:#50bf40; }
</style>
</head>
<body>
<div id="main">
<div id="content">
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
</div> <!-- end content div -->
<table id="list-table" cellspacing="0">
<tr>
<td id="lt-border-top">&nbsp;</td>
<td id="list-content" rowspan="3">
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
</td>
<td id="rt-border-top">&nbsp;</td>
</tr>
<tr>
<td id="lt-graphic">&nbsp;</td>
<td id="rt-graphic">&nbsp;</td>
</tr>
<tr>
<td id="lt-border-bot">&nbsp;</td>
<td id="rt-border-bot">&nbsp;</td>
</tr>
</table>
</div> <!-- end main content -->
</body>
</html>


Since my "conversion" (6 years or so this year) I haven't had to use a table for layout even once. This is making me ill. :-P

rocknbil

6:55 pm on Mar 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One more try, per the latest code posted above - does anyone have any general ideas how I can avoid this table? Not asking to fix it for me, just some ideas I might chase that aren't addressed by the usual 100% height layouts.

TheMadScientist

5:50 am on Mar 29, 2010 (gmt 0)

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




<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Vertically center div in side divs</title>
<style type="text/css">
/* without it, side boxes containing side borders won't go to 100% height */
html { height:100%; }
body { height:100%; }
#outer-div { width: 100%; min-height:100%; border: 1px solid #ff0000; }
#left-vert { float:left; width: 27px; margin-top:30%; height:100px; border: 1px solid #0000ff; }
#right-vert { float:right; width: 27px; margin-top:30%; height:100px; border: 1px solid #0000ff; }
#mid-content { float:none; width:auto; margin:0 27px; border:1px solid green; }
.clear-div { clear:both; }
</style>
</head>
<body>

<div id="top-content">
Content above goes here<br><br>
Content above goes here<br><br>
Content above goes here<br><br>
Content above goes here<br><br>
Content above goes here<br><br>
Content above goes here
</div>

<div id="outer-div">
<div id="left-vert"></div>
<div id="right-vert"></div>
<div id="mid-content">
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
<p> list</p><p> list</p><p> list</p><p> list</p><p> list</p><p> list</p>
</div>
<div class="clear-div"></div>
</div>
</body>
</html>


Not sure if this'll give you some ideas or not. It may just do what swa66's example does in the other thread because I didn't really look at it too much...

The only thing I didn't have time to really figure out was your other background colors...

Maybe with the colors (fades) being set as the background image of the 'outer-div' (no-repeat center center) and making the graphic too tall and wide for any window?

So, create the BG fades for the top and bottom of the left and right cols (full width colors for different width windows and 2000 or so px high) no-repeat center center and the left and right boxes should act as a divider for the color differences...

The above seems to sort of, kind of do what you are looking for in FF 3.6 on a Mac anyway, I think...

TheMadScientist

6:20 am on Mar 29, 2010 (gmt 0)

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



You could probably use JS to change the margin-top setting onLoad on the side DIVs based on window height if you wanted to do the math and didn't mind depending on JS to make sure it's right for everyone across all browsers and window sizes.

rocknbil

10:09 pm on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, thank you . . . but . . . sadly . . .

Worse, something I'd left out (err, overlooked) in my original post: the borders above and below those two boxes are different fills, like

-- border image is shades of red
-- "joining" graphic
-- border image is shades of gold


Your code is similar to post #1, in which I had a temporary lapse of sanity (in trying to middle-center, I'd left out the above requirement.)

Test the second set of code, it has colors above/below the side graphics that are different within the same "column."

TheMadScientist

10:47 pm on Mar 29, 2010 (gmt 0)

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



I did and that's why I suggested to adding an image with the fades you wanted to the background of the outer div... Solid colors (or fade) that switch to the opposite in the middle.

It'll have exactly the same effect as coloring (or adding a graphic to) a div above and below the mid-graphics. You don't need the extra divs for the fill if you leave the mid-div smaller than the outer div and center the mid-graphic on the sides vertically.

A solid or 'non-complicated' graphic is relatively small, so you could create the graphic and set it as the background on the outer-div... I'd show you but I can't link an image here.


TOP COLOR FADE 1 | TOP COLOR FADE 2
TOP COLOR FADE 1 | TOP COLOR FADE 2
TOP COLOR FADE 1 | TOP COLOR FADE 2
TOP COLOR FADE 1 | TOP COLOR FADE 2
MID GRAPHIC | MID GRAPHIC
TOP COLOR FADE 2 | TOP COLOR FADE 1
TOP COLOR FADE 2 | TOP COLOR FADE 1
TOP COLOR FADE 2 | TOP COLOR FADE 1
TOP COLOR FADE 2 | TOP COLOR FADE 1

rocknbil

8:21 pm on Mar 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, but the problem is, the content inside the table is variable, as well as zoom/text size changes will blow it out of position. So the vertical graphic idea won't work, or at least, that I can tell. I did take a stab at that before.

swa66

10:00 pm on Mar 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bill: all you need is to position elements inside the list. Don't focus on a 100% height solution as that's not what you seek.
What I'd do is just use absolute positioning to get the effect you need inside the list e.g.:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>position absolute rocks</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
min-width: 700px;
max-width: 1020px;
width: 98%;
margin: 0 auto;
border:1px solid #000;
}
#content {
border:1px solid #ff0000;
}
#list {
position:relative;
}
#list ul {
margin: 0 27px;
}
#tl,#tr,#bl,#br,#mr,#ml {
width: 27px;
position:absolute;
}
#tl {
background:#ffff00;
left:0;
top:0;
bottom:50%;
/* if needed a bottom margin could be applied
to avoid an overlap if that's needed for your
graphics
*/
}
#tr {
background:#992626;
right:0;
top:0;
bottom:50%;
}
#bl {
background:#992626;
left:0;
bottom:0;
top:50%;
}
#br {
background:#ffff00;
right:0;
bottom:0;
top:50%;
}
#ml {
height:27px;
background:#16dee9;
left:0;
top:50%;
margin-top:-14px; /* half the height */
}
#mr {
height:27px;
background:#50bf40;
right:0;
top:50%;
margin-top:-14px; /* half the height */
}
</style>
</head>
<body>
<div id="content">
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
<p>Content above goes here</p>
</div> <!-- end content div -->
<div id="list">
<div id="tr"></div>
<div id="br"></div>
<div id="tl"></div>
<div id="bl"></div>
<div id="ml"></div>
<div id="mr"></div>
<ul>
<li>list</li>
<li>list</li>
<li>list</li>
<li>list</li>
<li>...</li>
<li>list</li>
</ul>
</div>
</body>
</html>


It uses position:relative on the #list to make it gain position so that children that are positioned absolutely do get the reference of the closest parent that has position as a reference frame.

It uses the ability to set both top and bottom of an absolutely positioned element. That's something legacy IE versions typically have trouble with (IE7.js fixes IE6 it if you need it)

It also uses the ability to use both a absolute positioned element and a margin at the same time to move things back so you can use a % and an px measurement at the same time and do some basic math and center elements either vertically or horizontally.

As it is now the top and bottom will end up touching in the middle underneath the middle element (so source code order is important). It's quite possible to use the margins on the bottom and top of the top and bottom elements to remove the overlap (at the risk of having to have a pixel perfect layout) if your graphics require that.

HTH and sorry for the slow response

One of those cases of not being afraid of absolute positioning.

In a real layout It's add min-height on the list etc to make sure I don't try to fit too much in too little as it'll blow up under such extreme conditions, but I left it out of here in order to keep it simple.

rocknbil

8:37 pm on Apr 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<smacks head> WOW . . . just wow . . . .

One of those cases of not being afraid of absolute positioning.


Which I do, I always associate it with "out of the normal flow" which was the barrier. That, and seeing it as a 100% height task . . . .

As usual, you rule! <Does the Wayne's 'we're not worthy' dance>

Thank you, I'll study this and get on it!

rocknbil

4:50 am on Apr 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just thought I'd check back in, this project got the back burner for a while . . . works beautifully in everything except Opera.

None of the borders render at all, only the "divider" blocks show, stuffed way up under "content above."

The layout it goes in is even more complex, it held together perfectly everywhere else except in Opera. I'll tweak on it a bit, see if I can get it to play along without a hack.

swa66

12:42 am on Apr 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Strange that you report opera problems.

Was it a recent version of Opera ? Cause I tested what I posted in Opera 10.10 and it worked just fine.

rocknbil

6:39 pm on Apr 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Heh . . . I was afraid you might ask that . . . 8.02 . . . .

I delay updates as long as possible for two reasons, to maintain maximum backward compatibility and laziness or time to do it, take your pick. I guess though, Opera users are more likely to stay on updates. Downloading now . . .