Solved

Vertical align to bottom of floating div

Posted on 2010-08-19
8
798 Views
Last Modified: 2013-11-19
Referencing the attached image, any ideas about how to achieve this layout using floats (rather than tables)?

The part that's giving me trouble is the bottom-left set of links, that should be aligned to the bottom of the container.  Also, the width of the container is not fixed - it shouldn't have width specified at all, and expand to fit it's contents.

I'm not worried at all about fonts, borders, padding, colors, etc, just trying to achieve the attached macro concept using CSS, best-practices and w/out tables.

TYIA
ee-layout-sample.jpg
0
Comment
Question by:moagrius
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:goducks
ID: 33481359
I would start by building a DIV container for the entire thing, then start splitting up your inner areas (links and image) into DIV blocks.

The outer container should have a style="position: relative;" set to it.  The inner DIV's should all be style="position: absolute;" with positioning from left, right, top, bottom accordingly.

For your example, the lower left link should have style="position: absolute; left: 0px; bottom: 0px;" and that should get you going with the rest.
0
 
LVL 19

Author Comment

by:moagrius
ID: 33481389
the problem i ran into with absolute positioning is that i don't know the widths of the columns.

e.g., in the left-most column, the text of a link might be as short as "bob" or as long as "lorem ipsum dolor sit ahmet".  the image should appear to the right of this column, and again i won't know the width, and the final column (right-most) should appear to the right of that.  with absolute positioning, i'd need to pre-plot those positions - which is impossible.  am i missing something?
0
 
LVL 2

Expert Comment

by:goducks
ID: 33481771
What if you set a predefined width to the div's?  I mean, you will need to limit it at some point so the text doesn't wrap or extend over the graphic.  If you float all your div's and give them all display: inline, you should be able to do this.
0
 
LVL 19

Author Comment

by:moagrius
ID: 33481856
the left column needs to expand to fit the links.  the middle column (image) will begin after the left column, and the right column will be after the image column.

i can't define the width of the columns (except the right-most) - all content is dynamically generated.  a link might be a single character of a hundred.  the image might be 50px or 500px.  the description might have just a title or several hundred words.

what i'm describing is easily achieved using tables, and sizes + positions appropriately, but i want to do it with floating divs, not tables.

in the attached example (using tables), all the above requirements are met - despite the size of the links, the size of the image, or the length of the description.

thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" > 
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="noindex, nofollow" />
	<title>Title</title>
	
	<style type="text/css">
		td {
			vertical-align : top;
		}
		td.links {
			text-align : right;
		}
		td.links.bottom {
			vertical-align : bottom;
		}
		td.description {
			width : 150px;
		}
	</style>
	
</head>

<body>

<table>

	<tr>
		<td class="links">
			<a href="#">Link</a>
			<br />
			<a href="#">Another Link</a>
		</td>
		<td rowspan="2">
			<img src="http://static.howstuffworks.com/gif/code-breakers-1.jpg" />
		</td>
		<td class="description" rowspan="2">
			<h1>Title</h1>
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
		</td>
	</tr>

	<tr>
		<td class="bottom links">
			<a href="#">Link</a>
			<br />
			<a href="#">Another Link</a>
		</td>
	</tr>

</table>

</body>
</html>

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:goducks
ID: 33481916
Ok... (not going to look at that table example - I hate em now that I use DIV's exclusively)... here's how I would do it.  But first, some rules:

1.  Column width is not controlled.  Horizontal scrolling must be allowed?
2.  Columns must expand based on their content.
3.  Wrapping or overlapping is not allowed.

Knowing those rules, this is what I would do (sorry, you'll need to do the dirty work, but I'll explain most).

1.  Create three div wrappers - these are your columns.  The wrappers should have the following style info (floating might be an option too):
style="position: relative; display: inline;"
2.  Don't get caught setting heights or widths in the column wrappers!

LEFTMOST COLUMN:
1.  The left most column is a wrapper for your two text items.
2.  Create two div's inside of this column.  The first div is your top link.  The bottom div is your bottom link(s).  Each div should have the following style info:
style="position: absolute; width: 100%; display: inline; text-alignment: right; left: 0px;"
3.  The top div in this column should have the extra style info:
style="top: 0px;"
4.  The bottom div in this column should have the extra style info:
style="bottom: 0px;"

MIDDLE COLUMN:
1.  This one is easy.  Create one div inside this column to hold your image.  The div should have the following style info:
style="position: absolute; top: 0px; left: 0px;"

RIGHT COLUMN:
1.  This column should also only have one div with the following style info:
style="position: absolute; top: 0px; left: 0px; width: 150px;"
2.  Your text would be embedded in this div.

That should do the trick.
0
 
LVL 19

Author Comment

by:moagrius
ID: 33482068
hmm thanks for the reply, but that won't work for several reasons.  with absolute positioning set up like that, they'll all appear on top of each other.  also, not sure why you're using display inline with absolute positioning, since once an element is positioned absolutely, it's taken out of the standard page flow so display settings no longer matter.  also, it's not valid to have block level elements within inline elements, so using display:inline would disallow anything like lists or paragraphs...

EDIT:  just to make sure, i went ahead and wrote it up as described.  my initial presumptions were correct - all content appears top left, each layer over top of the previous.

thanks anyways
0
 
LVL 19

Author Comment

by:moagrius
ID: 33483776
got it.

the solution is:

container div with overflow:auto to clear floating contents.

within container, add a div for bottom-left link list with position: absolute, bottom : 0px

within that also have 3 columns with standard floats containing top links, image, and description
0
 
LVL 2

Accepted Solution

by:
goducks earned 500 total points
ID: 33486919
You're right, using inline was a miss.  And none of the other stuff I said helped?  Really?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now