multiple overlapping divs?

This is a discussion on "multiple overlapping divs?" within the Web Page Design section. This forum, and the thread "multiple overlapping divs? are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Apr 19th, 2007, 06:54
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
multiple overlapping divs?

It's a crazy question, and I think I already know the answer, but I'm going to ask anyway. Is this possible?
Code: Select all
<div class="a">This is div A.
   <div class="b">This is div B and still div A.
</div class="a">This is only div B.
      <div class="c">This is div B and div C.
   </div class="b">
          This is only div C.
       </div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Apr 19th, 2007, 10:06
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Nope, not possible. What were you intending to do with that code? You could place div's over each other using absolute positioning anyway...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Apr 19th, 2007, 14:59
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Quote:
Originally Posted by Ryan Fait View Post
What were you intending to do with that code?
Picture 3 side-by-side floated divs... the center div contains text (height will vary), the left and right ones contain navigational elements. If I could control overlapping divs, I could vertically center the nav elements without resorting to a table. I think I've become obsesses with eliminating tables! :crazy:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Apr 19th, 2007, 16:03
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Just define your three divs one after the other.

Float them all left and control the width of each to suit your total layout width.

Use margin to control space between divs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Apr 19th, 2007, 16:49
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: multiple overlapping divs?

http://www.newguyinennis.com/samples...yout_3_column/
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Apr 19th, 2007, 17:27
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

I get how to stack divs side-by-side. I get how to use width and margins. What I'm trying to do is vertically center small nav images (arrow left and arrow right) in the left and right div - regardless of how the height of the middle div may vary.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Apr 19th, 2007, 17:37
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: multiple overlapping divs?

background: url("foo.jpg") left center no-repeat; no? that will keep the background centered in a div regardless of its height.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Apr 22nd, 2007, 00:17
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Quote:
Originally Posted by moojoo View Post
background: url("foo.jpg") left center no-repeat; no? that will keep the background centered in a div regardless of its height.
I didn't know that, and I'm happy new to have learned something, but...

I can't link using a background image, though, can I? I'll still need a foreground element to serve as link/the nav element. Can I put a clear.gif in the foreground and set its height and width to 100% and have it be the clickable link/nav element? I haven't had great success in the past with setting elements to 100% height and actually have them obey (especially from a cross-browser standpoint.) If you can tell me how to do that, I'll be thrilled!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Apr 22nd, 2007, 00:58
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Code: Select all
a {
  width: 200px;
  height: 200px;
  background: url(img.jpg) no-repeat;
  display: block;
}
You'll need something to hide the text, text-indent: -5000; will do the trick, but as I recall, you can't use that on anchors. So you'll have to select it's parent or something to set the text-indent.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Apr 22nd, 2007, 01:11
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

But you're specifying a height for the anchor... The whole point is that the height will vary. Sometimes 200px will be too much, other times not enough.

I don't understand your point about hiding the text. Unless we're getting back to the whole "never ever use images for navigation" thing. But this is just a simple previous/next arrow thing - and I'll be using alt and title text, so why not just use a clear gif as the anchor?

Hey, wait a minute - what about setting the height of the image to something ridiculously high, then setting overflow on the container to hidden?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Apr 22nd, 2007, 01:41
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Quote:
Originally Posted by Donny Bahama View Post
Hey, wait a minute - what about setting the height of the image to something ridiculously high, then setting overflow on the container to hidden?
Nevermind. That definitely doesn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Apr 22nd, 2007, 01:53
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

OK. Could someone please just say, "Give it up, Donny! The only way to do that currently is using a table!"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Apr 22nd, 2007, 01:57
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Can you show me what you're doing with a table? I'll tell you how to do it with CSS.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Apr 22nd, 2007, 02:30
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Happy to. Here's a link: http://stickpuppy.com/dhs57/yearinre...?event=1010601

Notice the event text. Click the next arrow 4 or 5 times (you could click the previous arrow, but those images won't be preloaded for you) and watch how the event text changes in quantity, ergo height. But the next and previous arrows stay vertically centered, regardless of the height of the middle (text) div.

If you must view source, know that I have overhauled most of this page and eliminated tables everywhere but in the area in question. If I need to use a single row table to do this, so be it, but I thought that since it was a single row table, I should be able to replace it with a div-based layout.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Apr 23rd, 2007, 03:52
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Sorry for taking so long. I forgot about this...

Code: Select all
<!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" xml:lang="en">
	<head>

		<script type="text/javascript">

		</script>

		<style type="text/css">
			body {
				margin: 0;
				padding: 15px;
			}
			.box {
				position: relative;
				height: auto;
				width: 200px;
				background: #ccc;
			}
			.box p {
				margin: 0 35px;
			}
			.box p.leftarrow {
				position: absolute;
				left: 0;
				top: 0;
				height: 100%;
				width: 30px;
				margin: 0;
				text-indent: -5000px;
				background: #aaa url(arrowleft.gif) no-repeat 50% 50%;
			}
			.box p.rightarrow {
				position: absolute;
				right: 0;
				top: 0;
				height: 100%;
				width: 30px;
				margin: 0;
				text-indent: -5000px;
				background: #aaa url(arrowright.gif) no-repeat 50% 50%;
			}
			.box a {
				position: absolute;
				width: 30px;
				height: 100%;
				display: block;
			}
		</style>

		<title>Untitled</title>

	</head>
	<body>

		<div class="box">
			<p class="leftarrow"><a href="#">Left</a></p>
			<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </p>
			<p class="rightarrow"><a href="#">Right</a><p>
		</div>

	</body>
</html>

This was kind of tricky I like tricky things!

Last edited by Ryan Fait; Apr 23rd, 2007 at 03:54.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Apr 23rd, 2007, 04:08
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

You cheated! I don't want to use javascript. (Sorry, should've specified.)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Apr 23rd, 2007, 04:11
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

Quote:
Originally Posted by Ryan Fait View Post
show me what you're doing with a table? I'll tell you how to do it with CSS.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Apr 23rd, 2007, 04:17
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple overlapping divs?

There's no JavaScript. It's just my test page layout. Ignore the script tags.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #19  
Old Apr 23rd, 2007, 04:21
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: multiple