Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

positioning inside table cells 1

Status
Not open for further replies.

jpadie

Technical User
Nov 24, 2003
10,094
FR
i have a table cell that looks something like this
Code:
<td>
	<div class="weekday">1</div>
	<div class="itemsContainer">
		<span class="item">something</span>
		<span class="item">something else</span>
	</div>
</td>
i am looking for some css to position the weekday at the top left of the cell and the contents of the itemsContainer at the bottom right. The cells are variable height but a fixed width. It may be possible for me to contrain the height if this is required.

I'm drawing a blank at present. i would normally try absolute positioning on the items Container and relative on the td but this does not seem to work on firefox/safari ( and i have not tried other browsers).

all help gratefully received.
thanks
Justin
 
Hi

Something like this ?
Code:
td {
  clear: both;
}
div.weekday {
  float: left;
}
div.itemsContainer {
  float: right;
}
Of course, this may look bad unless you force some adequate [tt]width[/tt]s.

Or I just misunderstood you...

Feherke.
 
thanks for your reply. how does the above force the itemsContainer to the bottom of the table cell? i can see how it creates the right alignment.

thanks
Justin
 
Hi

You wrote that "The cells are variable height but a fixed width.", so I supposed this means the cell will as high as the content, so the itemsContainer will always touch its bottom...

Feherke.
 
sorry. i should have been more clear and provided a more fulsome snip of html.

to try and abstract the issue, let's say that the cell height is 100px.

 
i'd rather go with xhtml strict, but can live with transitional.

Off topic: [btw BRPS - could you check the email from your site's contact form]
 
Try this for size:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta http-equiv="content-language" content="en" />

	<title>Table test</title>

	<style type="text/css">
		.hasWeekday {
			width: 100px;
			height: 200px;
			position: relative;
			display: block;
		}

		.weekday {
			position: absolute;
			top: 0px;
			left: 0px;
		}

		.itemsContainer {
			position: absolute;
			bottom: 0px;
			right: 0px;
		}

	</style>
</head>

<body>

	<table border="1">
		<tr>
			<td>A cell</td>
			<td class="hasWeekday">
				<div class="weekday">1</div>
				<div class="itemsContainer">
					<span class="item">something</span>
					<span class="item">something else</span>
				</div>
			</td>
			<td>Another cell</td>
		</tr>
	</table>
</body>
</html>

Of course it's not perfect because of the absolute positioning... you might be better off putting a nested table in that cell and using valign and align to do the job.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks, Dan. i'll give it a whirl later this evening and post back.
 
Dan

thanks for your post.

the position attribute did not work with a table cell (in ff for mac and safari). and the display:block murdered the table in those browsers too.

but following on from your example, I create a 100% height/width div inside the table cell (this works because i had previously given the table cell a fixed height/width) and positioned this as relative. the absolute positioning of the other two divs then worked as expected.

thanks again
Justin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top