NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Webmaster Tutorials
Reload this Page CSS for 2 background colors

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search
2 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-28-2007, 02:38 AM THREAD STARTER               #1 (permalink)
NamePros Member
 
RaptorRex's Avatar
Join Date: Dec 2004
Posts: 93
RaptorRex is an unknown quantity at this point
 



CSS for 2 background colors


I've seen this requested a few times. How can someone have 2 background colors split down the middle. The technique here is to use z-index to create a layer of backgrounds then make a new writing canvas as a top z-index onto which you build the actual web page. Here is the code:
????: NamePros.com http://www.namepros.com/webmaster-tutorials/389408-css-for-2-background-colors.html

<html>
<body style='background-color: red; margin: 0px; height: 100%;'>
<div style='position: fixed; top: 0; left: 0; width: 50%; height: 400%; background-color: yellow; z-index: 1;'></div>
<div style='position: absolute; top: 0; left: 0; z-index: 2; width: 100%;'>
To have a web page background be half one color and half another color. Great for a two-tone look.
</div>
</body>
</html>

This example lays down a solid red body background then puts a 50% wide yellow div over top of it. Then over top of all, it makes the new writing canvas.

A few notes:
- you need to set <body> height so that height of elements within <body> can be relative to something.
- the yellow div has height: 400%. This needs to be big enough to exceed the content on the writing canvas. Play with it in explorer (with a HTML4.01 doctype)...you'll see what I mean.
- the last div uses "position: absolute". "fixed" should work just as well but does not in IE. But "absolute" does.
- z-index is the key

See example at: http://upwithabang.com/articles/exam...ackground.html

It is worth noting that this method of creating a layer to be a new writing canvas (overtop of everything else) allows backgrounds to be as complex as you want.
RaptorRex is offline  
Old 10-30-2007, 02:15 PM   #2 (permalink)
MJ
Senior Member
 
MJ's Avatar
Join Date: Jul 2007
Location: Tucson AZ
Posts: 1,241
MJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond reputeMJ has a reputation beyond repute
 


Autism Special Olympics Adoption Baby Health Child Abuse
Ooo! I like this alot. Its great how the deviding line is always in the middle too if you resize it. The reason I like this alot is because it gives the illusion of frames (right and left) but its one page!! Great code thanks!
__________________
Wii Sucks - Wii Fansite
Tucson Dog Training
San Angelo TX
MJ is offline  
Old 11-01-2007, 01:17 AM   #3 (permalink)
Account Suspended
 
mee2k7's Avatar
Join Date: Oct 2007
Location: www.Affifind.com
Posts: 55
mee2k7 is on a distinguished road
 



Great code thanks!
mee2k7 is offline  
Old 01-06-2008, 11:32 PM   #4 (permalink)
Account Suspended
 
wasiflaeeq's Avatar
Join Date: Aug 2007
Posts: 168
wasiflaeeq is on a distinguished road
 



Gr8 Code
wasiflaeeq is offline  
Old 01-19-2008, 11:29 AM   #5 (permalink)
NamePros Member
Join Date: Jan 2008
Posts: 81
halishas is an unknown quantity at this point
 



tnx it nice very ty
halishas is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 11:29 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger