473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Challenging CSS Layout

I have a general design that I think is near impossible to create without using tables. Even with tables it wouldn't be a very easy to lay it out.

I mocked up the layout as a PDF. You can download CSS Challenge.pdf or go here.

The simplest example of the problem is that I have an image that I want to align left, then on the right I have a column of text. The text should by vertically-aligned to the bottom of the picture. This leaves some whitespace above the text, but there is no way to know exactly what height this whitespace is. All of that is do-able with positioning. But my problem is that I want a single line of text to be centered in the whitespace, and I don't even know how big the whitespace is.
Dec 28 '07 #1
12 1515
drhowarddrfine
7,435 Expert 4TB
**sigh**
Don't challenge me grasshopper.
Dec 28 '07 #2
Here are images exported from the PDF to make it a little easier to view the problem without downloading anything.

Easier Layout

Complex Layout
Jan 2 '08 #3
Does that mean you have the solution drhowarddrfine? Because I'm at a total loss here. Any ideas even?
Jan 7 '08 #4
drhowarddrfine
7,435 Expert 4TB
Lots of ideas but a line is crossed where people pay me to do this. :)
Jan 7 '08 #5
...okay. Anyone have any less proprietary ideas? I'm starting to think it's not possible in IE without using tables. CSS seems to be pretty lacking when it comes to vertically stacking elements. It just seems so simple.

Take a column of known height. Place an article in the bottom part of the column. Vertically center a single line quote in the space not used by the bottom article.

It's so simple, but yet impossible to determine how much space the quote has. I can absolutly position the article at the bottom of the column, and I can center the quote in the column's full height (as if the article wasn't there). But I can't come up with any way to center it in the whitespace.
Jan 7 '08 #6
Death Slaught
1,137 1GB
...okay. Anyone have any less proprietary ideas? I'm starting to think it's not possible in IE without using tables. CSS seems to be pretty lacking when it comes to vertically stacking elements. It just seems so simple.

Take a column of known height. Place an article in the bottom part of the column. Vertically center a single line quote in the space not used by the bottom article.

It's so simple, but yet impossible to determine how much space the quote has. I can absolutly position the article at the bottom of the column, and I can center the quote in the column's full height (as if the article wasn't there). But I can't come up with any way to center it in the whitespace.
Hold on I'm working on it :)

Thanks, Death

PS - Odds are I won't have time to finish this today so I'll post them tomorrow.
Jan 7 '08 #7
Death Slaught
1,137 1GB
Well odds are you aren't going to like this, but the only way I'm going to give you the answer is if it has been a learning experience.

So, do you have a failed attempt code? If so please post it, also what makes you think this is possible?

Thanks, Death

PS - I'm talking about the easier one, I'll have the harder one done by tomorrow. Then we can work on the that one.

Jan 7 '08 #8
...the only way I'm going to give you the answer is if it has been a learning experience. So, do you have a failed attempt code?
It's not as simple as a failed attempt that I can't get to work. I can't even come up with any techniques that could potentially work, so I haven't been able to figure out what to attempt. With that justification of my not posting a failed attempt earlier, I did come up with an idea yesterday that sorta works, so I'll will post one now.

This code should work in FF2, IE6, and IE7 for text sizes of 2 steps smaller than "normal" to 2 steps larger. Which is what I want. Essentially it is a solution. If the text size is larger than 2 steps above normal (only possible in FF) then the blue text covers the quote. (Not that big of deal, I'd still be happy with it if that was the only thing wrong.)

The real problem with it is that I just guessed about where to place the quote. I absolutely positioned the quote -8em above the top of the img. Then pushed it back down with a 150px top padding. This puts it in about the right spot for the default font size. When the user increases the font size the -8em becomes larger, pushing the quote up further. Since the article expands vertically when the font size increases it has to move up to remain centered.

While this all works as intended, it's a very messy solution. I just guessed where to position the quote. Everything is just floating around with no relationship to each other. If I change a single word in the text I'll have to play around with the sizes again to make sure it didn't change the way the text wraps.

Anyway without further ado, here is my mostly working, sloppy, slightly unstable solution.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <style>
  3.     body { width: 510px; margin: 80px auto; font-size: 77%; font-family: sans-serif;}
  4.     img { float: left; }
  5.     #column { margin: 0 5px 0 325px; position: relative; height: 280px; }
  6.     #quote { top: -8em; font-size: 1.1em; position: absolute; width: 180px; padding-top: 150px; text-align: center; }
  7.     #text { position: absolute; bottom: 0; left: 0; width: 180px; background-color: #aed8e6; }
  8.     #text p { margin: 0; padding: 0; }
  9. </style>
  10.  
  11. <body>
  12.     <img alt="Image placeholder 320x280" src="http://i258.photobucket.com/albums/hh259/Death_Slaught/Image.jpg?t=1199805813" width="320" height="280" style="background-color: black" />
  13.  
  14.     <div id="column">
  15.         <div id="quote">
  16.             "Short Quote Text"
  17.         </div>
  18.         <div id="text">
  19.             <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  Cras vitae lorem et tortor phare- tra autor. Cras pellentesque.</p> <p>A line I can't see.</p> <p>Another line I can't see.</p> <p>congue.  Ut sed purus. Phasel- lus mi erna, blandit sit amet, lacinia eu, placerat ac, arcu.  Donec ante erat, colutpat eget, pulvinar nec, volutpat ut, odio.</p>
  20.         </div>
  21.     </div>
  22. </body>
If so please post it, also what makes you think this is possible?
I assume you meant: what makes me think this is impossible. Because css doesn't seem to have any styles (that I can think of) for vertical arrangement of items that allow one item to take up some space, and another to use up the remaining space. This is an advantage of tables: you can assign heights to the rows you want and let the others distribute the remaining space amongst themselves.

Normally this problem comes up with widths. And CSS has floats to replace tables in this context....but I don't see how it can be done with heights, since there is no vertical equivalent.
Jan 8 '08 #9
BTW if you don't feel this is enough of a learning experience, you could just point me in the direction of the techniques you used (what type of styles) and I'll see if I can do it myself first. Of course, I won't complain if you post the code to solve all my problems in one swoop.
Jan 8 '08 #10
Death Slaught
1,137 1GB
Give this a shot.

[HTML]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Challenge - Part 1</title>
<style type="text/css">

body {
font-family:Arial, Verdana, Helvetica, sans-serif;
font-size:small;
margin:1;
padding:0;
}

#Quote {
width:109px;
position:absolute;
top:60px;
left:368px;
}

#Text {
width:182px;
background-color:lightblue;
position:absolute;
top:119px;
left:334px;
}

</style>
</head>

<body>

<div id="Image">
<img src="F:\Image.jpg" alt="Image" />
</div>

<p id="Quote">
"Short Quote Text"
</p>

<p id="Text">
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.
Cras vitae lorem et tortor phare-
tra auctor. Cras pellentesque.
A line I can't see. <br />
Another line I can't see.
congue. Ut sed purus. Phasel-
us mi urna, blandit sit amet,
lacinia eu, placerat ac, arcu.
Donec ante erat, volutpat eget,
pulvinar nec, volutpat ut, odio.
</p>

</body>

</html>
[/HTML]

When adding more to the quote just reduce the amount of pixels in the top property.

Don't think I'm just giving this to you without a catch.

Expand|Select|Wrap|Line Numbers
  1. When you finish the hard one post it.
  2.  
Hope it helps, Thanks, Death
Jan 8 '08 #11
@drhowarddrfine
Well, there have been two attempts now. After seeing the limits of absolute positioning, do you still feel like you have a better idea, or was that what you were thinking of trying too?

@Death Slaught
Thanks for the effort. Absolute position everything is a technique that only kinda works; unfortunately it suffers from the same inflexibilty of mine. However, I might see if positioning the text from the top instead of the bottom like yours, but using a combination of em's and px's to allow the layout to scale like I did in mine would let it scale up to a larger font-size. It just seems so wrong to just place these elements around arbitrarily without any relationship to each other.



I hate to say it, but in this case a table is more maintainable solution.

I'll keep working on it, and post back here in a day or two if I come up with anything.
Jan 8 '08 #12
drhowarddrfine
7,435 Expert 4TB
@drhowarddrfine
Well, there have been two attempts now. After seeing the limits of absolute positioning, do you still feel like you have a better idea, or was that what you were thinking of trying too?
It isn't that I had anything specific but these challenges tend not to be specific enough or change the rules on me when I present solutions so I don't participate; and I just don't have time anymore. In fact, I'm taking a much needed two-week hiatus from this board just to catch up with real work.
I hate to say it, but in this case a table is more maintainable solution.
I've never found a need for tables for layout. I've never done it either because I never learned that way. In fact, I find tables for layout to be hideous and hard to figure out.

All that said, I can't even respond properly because I'm eating dinner while I type this and it's back to work. Yes, I'm very tired.
Jan 9 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
20
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
11
by: George | last post by:
Was my question too challenging for everyone? I thought I would get a much quicker response, complete with witty and (sometimes) condescending remarks Here's my question again, in case you missed...
18
by: Frankie | last post by:
I have been hired to go to a former client of mine and train their staff programmers on ASP.NET. These guys have only Mainframe, MS Access, SQL Server, and VB6 desktop application development...
10
by: Luke | last post by:
Hi. I am trying to make correct layout, here is an example of (dynamically generated content via jsp): http://localhost/www/layout.htm Most outer div is positioned absolute (if not then it...
5
by: alainpoint | last post by:
Hi, I have what in my eyes seems a challenging problem. Thanks to Peter Otten, i got the following code to work. It is a sort of named tuple. from operator import itemgetter def...
5
by: Ed Sproull [MSFT] | last post by:
First I'm pretty new to ASP.NET and I'm having a simple problem. I have small website with a header, sidebar and the the content. I want my content to appear beside my sidebar which seems to be a...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.