Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2012, 04:54 AM   PM User | #1
fujihime
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
fujihime is an unknown quantity at this point
CSS background change within a div

Hello everyone, I'm new here and is a beginner to CSS/jQuery. I'm searching for way to change the background image of a div. When I click on a link on the navigation that will link within the same file (am I making sense?), and with a cross fade transition.

This is the website I'm working on. The pages are fading in and changes but the background image remain fixed. I want to change the background-image in the blackish background (with words), not the sunrise background.

http://entwurvian.net/wip/maxivision/index.html http://entwurvian.net/wip/maxivision/style.css

----

I tried implementing this script which I found online but it didn't seem to work. Is it because it conflicts with some codes in my files?

Thanks in advanced!

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>TheWebsite</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#hdr {
	height : 150px;
	width : 100%;
	background-image: url(gang/Bass.png);
	background-repeat: no-repeat;
  }
.hdr1 {
	height : 150px;
	width : 100%;
	background-image: url(gang/carl.png);
	background-repeat: no-repeat;
  }
.hdr2 {
	height : 150px;
	width : 100%;
	background-image: url(gang/Chet.png);
	background-repeat: no-repeat;
  }
.hdr3 {
	height : 150px;
	width : 100%;
	background-image: url(gang/Mel.png);
	background-repeat: no-repeat;
  }
</style>
 
</head>
<body >
<div id="hdr">Sometext</div>
 
<div><b>Alternate Background Images</b> -<br /> 
    <a href="#none" onclick="document.getElementById('hdr').className ='hdr1'">Option 1</a>
    <a href="#none" onclick="document.getElementById('hdr').className ='hdr2'">Option 2</a>
    <a href="#none" onclick="document.getElementById('hdr').className ='hdr3'">Option 3</a>
    <a href="#none" onclick="document.getElementById('hdr').className ='hdr'">Default</a>
  </div>
 
</body>
</html>
fujihime is offline   Reply With Quote
Old 11-28-2012, 01:47 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
First: change #hdr {..... to .hdr {....
That moves your background from the ID to the class attribute and it's the class attribute that your changing with the onclick.

Lastly: change <div id="hdr">Sometext</div> to <div id="hdr" class="hdr">Sometext</div>
So we have a class to change.

That should do it.
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
background-image, div-background, image-transition

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:11 PM.


Advertisement
Log in to turn off these ads.