/    Sign up×
Community /Pin to ProfileBookmark

Positioning one div on top of another

I’ve got a page with a floated div. Inside the floated div, I have another div and a table.

I would like for the nested div to appear *on top* of the table, and for both the table and the nested div to be positioned at the top of the floated div.

Whew!

Here’s my code that I’m working on for testing:

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Relative positioning vs floating</title>
<style type=”text/css”>
* {
margin: 0;
padding: 0;
}

body {
margin: 10px;
background-color: pink;
}

.float {
width: 300px;
height: 300px;
overflow: hidden;
background-color: #CCFFFF;
float: left;
padding: 10px;
}

div.float table {
postion: relative;
top: -100px;
width: 100%
background-color: #FFFF00;
display: block;
}

div.relative {
position: relative;
top: 0;
width: 100%;
height: 100px;
overflow: hidden;
background-color: #99CCFF;
text-align: center;
}
</style>
</head>

<body>

<div class=”float”>

<div class=”relative”>
Loading Template…
</div>

<table>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc gravida quam et mauris. Aliquam laoreet lorem non massa. Praesent sed risus. Aenean viverra. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Aenean tortor. Nam sodales eleifend felis. Cras non elit. Vivamus dictum lobortis lectus. Nam bibendum. Etiam tempor interdum mi. Sed consequat sapien nec dolor. Sed adipiscing. Phasellus ut nisi sit amet magna scelerisque dapibus. Duis in mauris.</p>
</td>
</tr>
</table>

</div>

</body>
</html>[/CODE]

I can’t seem to get the nested div on top of the table until I assign it a top: 100px while the table has top: -100px, but this of course puts both of them 100px from the top of the floated div.

Any and all help is appreciated. I think there’s something about relative positioning that I’m not understanding.

? Thank you!

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@3PinterJun 12.2006 — Try absolute positioning.

Using relative makes div´s `related´ to another and that´s something you don´t want.

3Pinter
Copy linkTweet thisAlerts:
@FIN23Jun 12.2006 — its just a case of adding a z-index value i think..

i have just done a small site which has a div as the main article and all other elements and divs are nested within it. The main article div is relativly positioned and all 'nested divs' have a higher z-index and are positioned absolutely.. seems to work for me.
Copy linkTweet thisAlerts:
@nataliemacauthorJun 12.2006 — Unfortunately, absolute positioning won't work for my layout. I've posted only a small chunk of a much larger, complex layout for a web application.

I somehow have to work within this floated div to get a "Loading..." message on top of the table that's in that floated div. I can't absolutely position the div because it's position on the page depends on what elements above/before it are hidden.

Thanks for the thought, though.
Copy linkTweet thisAlerts:
@ray326Jun 13.2006 — Move the position:relative to the div.float then use absolute positions on the elements it contains.
Copy linkTweet thisAlerts:
@FIN23Jun 13.2006 — only nested elements will be positioned absolutly..
×

Success!

Help @nataliemac spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...