How do I hide old div when opening a new one?

If you go to my site Bonkage.com notice that if clicking image/video editing doesn’t work unless you first click Web site First, and then theres no going back.

So i think I somehow need to make it some click each link closes out all of the others at the same time. It Seemed simple but I was wrong = /

Here is all the code involved. . .

The HTML code for the buttons:

<div id="RightNotes">
<div id="WebDesign" a class="WebDesign" a onclick="document.getElementById('BlogWebDesign').style.display='block'" "document.getElementById('Blog').style.display='close'" ><a>
</div>
<div id="ImageVideoEditing" a class="ImageVideoEditing" a onclick="document.getElementById('BlogImageVideoEditing').style.display='block'"></a>

The CSS code for the buttons:

#WebDesign
	{
		width: 200px;
		height: 92px;
		position:relative;
		top:-860px;
		left:365px;
		z-index:6
	}

	.WebDesign {
		display: block;
		width: 116px;
		height: 92px;
		background: url('../images/RightNav/WebDesign.png') top;
		text-indent: -99999px;
	}
	.WebDesign:hover {
		background-position: bottom;
	}

#ImageVideoEditing
	{
		width: 200px;
		height: 92px;
		position:relative;
		top:-710px;
		left:365px;
		z-index:6
	}

	.ImageVideoEditing {
		display: block;
		width: 190px;
		height: 92px;
		background: url('../images/RightNav/ImageVideoEditing.png') top;
		text-indent: -99999px;
	}
	.ImageVideoEditing:hover {
		background-position: bottom;

</div>



The HTML code for where the content is loaded:

```html
&lt;div id="BlogWebDesign"&gt;&lt;div class="close"&gt;
&lt;/div&gt;
&lt;div id="BlogImageVideoEditing"&gt;&lt;div class="close"&gt;
&lt;/div&gt;

The CSS code for where the content is loaded:

#BlogWebDesign
	{
		display: block;
		width: 690px;
		height: 864px;
		background: url('../images/Body/WebServices.png') top;
		position:relative;
		top:-1945px;
		right:113px;
		display: none;
		.blog display:none;
		z-index:3
	
		}


#BlogImageVideoEditing
	{
		display: block;
		width: 690px;
		height: 864px;
		background: url('../images/Body/ImageVideoEditing.png') top;
		position:relative;
		display: none;
		.blog display:none;
		z-index:3

		}

Any Advice would be greatly appreciated,

Thanks

Chris

So i think I somehow need to make it some click each link closes out all of the others at the same time.

Yes, with Javascript.

You’d need to write a hide/show function which, every time it runs, checks if any divs are in the “open” setting, and closes them. Then goes ahead and opens the one getting clicked.


<div id="WebDesign" a class="WebDesign" a onclick="document.getElementById('BlogWebDesign').style.display='block'" "document.getElementById('Blog').style.display='close'" ><a>

That code is horrible goofy. Was this a bad copy-paste into the forums? There is no attribute “a”.

Also you have an onclick to make some element “display: block” but then later you have “display: close” (there is no display: close… you may have seen similar code, but it would have used display: none).

You will want to visit the Javascript forums about this, because opening/closing message boxes without Javascript is not possible cross-browser (tho I’m seeing more and more good fakery with some of the newer experimental CSS stuff).

Also, keeping accessibility in mind, you may not want to do display: block/none, but pull the boxes offscreen instead to hide them.
Otherwise, get into all the new ARIA roles and attributes, since you’ve got some complex interaction here. And, keep in mind you should want to keep onclick events on focusable elements like anchors… or, if it must be a div or something, give that div a negative tab index (tabindex=“-1”) so that Javascript can change that to a positive number when the user needs to focus on that.

Thanks a ton!

Yeah lol sorry the copy and paste job is fine, the code is actually goofy!

I’m just learning this <div> and CSS stuff, I used to use frames!

The code is a result of me google’ing how to do something or stealing somebody else’s code then trying to make sense of it enough to make it work for my website.

You sound like you know all the In’s and Out’s! If your right about it not working across all browsers then I don’t want to bother and would like to find another route.

You mentioned moving the image over off the screen. Does this work across all browsers? if so do I do it the same way I make my button hover effects go from the top to the bottom half of the pic.

The code is a result of me google’ing how to do something or stealing somebody else’s code then trying to make sense of it enough to make it work for my website.

We all start somewhere. : )

If you’re into books, I can recommend Ian Lloyd’s Build Your Own Web Site the Right Way Using HTML and CSS. (it only happens to be a Sitepoint book I swear). It was my first book, it set me straight on a lot of the basics of HTML/CSS. You don’t get done with that book knowing how to build a site, but you do build “a” site (Bubble Under - The diving club for the south-west UK) and it’s a great start.

You mentioned moving the image over off the screen. Does this work across all browsers?

I meant your divs that you’re opening/closing… instead of display none/block, you can make them absolutely positioned and margin-left: -999em on :hover instead. This removes them from the document flow (they won’t take up space) and they’ll be off-screen (to the left of the screen).
It’s popularly used in dropdown menus, to hide/show the submenus.

if so do I do it the same way I make my button hover effects go from the top to the bottom half of the pic.

That’s a different technique (a css sprite that slides). It’s generally an excellent technique, though yours has a few disadvantages:

You have a :hover state, but no :focus state. Let keyboarders and mobile users know where they are as well: add a :focus state right after your hover state.
Example:
.Home:hover, .Home:focus {

Second, the negative text-indent means, if for whatever reason the image doesn’t load, there’s no text left behind to give people information! It becomes a Mystery Meat menu. One possible solution is to try out Gilder-Levin (my preferred technique much of the time), but it’s somewhat complicated. It took me a while to figure it out myself.
List (somewhat outdated) of various image-replacement techniques (Gilder-Levin is near the bottom).

Your code could use some updating as well : ) If you’re interested, start with a Strict doctype instead of transitional. Then let the W3C validator tell you everything you did wrong, and see where you can go from there.

Your menu:


		<div id="Bonkage"><a class="Bonkage" href="http://www.bonkage.com"></a>
  		</div>
  		<div id="Home"><a class="Home" href="http://www.bonkage.com"></a>

  		</div>
  		<div id="Portfolio"><a class="Portfolio" href="http://bit.ly/m9FsMG?r=bb"></a>
  		</div>
  		<div id="Services"><a class="Services" href="http://www.bonkage.com/Services.html"></a>
  		</div>
  		<div id="Contact"><a class="Contact" href="mailto:bonkageservices@gmail.com"></a>
  		</div>
  		<div id="Logo"><a class="Logo" href="http://www.bonkage.com"></a>
  		</div>

  		<div id="SearchBar">
  		<a class="SearchBar" href="http://www.bonkage.com"></a>
  		</div>

Generally in the web dev community, a menu is considered a list of links… which means we write it as an unordered list:


(I'd have the main-clickable-logo thing separate)
<ul id="menu">
  <li><a class="Home" href="http://www.bonkage.com">Home</a></li>
  <li><a class="Portfolio" href="http://bit.ly/m9FsMG?r=bb">Portfolio</a></li>
  <li><a class="Services" href="http://www.bonkage.com/Services.html">Services</a></li>
  <li><a class="Contact" href="mailto:bonkageservices@gmail.com">Contact</a></li>
</ul>

The search bar would be an HTML form.

Your portfolio link is reliant on the bit.ly servers to be up. They’ll also be able to measure how many people click on that link (every server a link goes through, those servers can catch all that referrer info). If bit.ly goes down, so does your link.

Having the contact button attempt to open someone’s mail program can be rather disorienting: most sites, the Contact button in the main menu goes to a page, where an email may be listed but is more clearly marked as an email.
For example, my graphical mail client sucks and is always broken. I log into a server via SSH to read and send mail. So someone like me would want to be able to highlight/copy the link instead.

Just ideas.

Anyway, with just classes on the anchors, you can style everything.

You’d remove default margins and padding from #menu, set #menu li to display: inline (normally no style at all but IE likes a state set on li’s here), and float the #menu a’s.

Everything that all those anchors have in common, you can state just once as
#menu a {
everything they share;
}

then whatever’s different (widths etc), you can list just those:
#menu .Home {
width: 200px;
}

and you can list everyone’s hover/focus styles the same way. You can combine all those individual images onto a single menu image.

Here is one example I have of the image replacement (tho it was unusual in that the guy who designed it had large spaces between each menu item):
Bella menu

Here’s another, a site design idea by kyllle:
Practice makes
Here’s the image:
http://stommepoes.nl/Kyle/menu.gif (today I would make it a png)

Wow, I can’t thank you enough! It really means a lot that you would spend all that time to help me understand and let me know about what I need to fix.

I haven’t had a chance to test everything out yet but I just finished reading it all and wanted to thank you regardless of my success = )

But I’m sure with your advice I can’t go wrong!

I’ll keep you updated on my progress

Thanks again!

Chris

But I’m sure with your advice I can’t go wrong!

Sure you can. I was given similar advice, and managed to do everything wrong : ) But this isn’t rocket surgery: making mistakes is not only okay, it’s good, and you don’t have to worry about killing astronauts or buildings falling down when you goof up.

Your right, it is harder then I thought, I am real close to getting that one Img Top Nav with hover effects workings the way you suggested. But I cant figure out how to change around the position of each separate button without having some weird duplicating overlap or complete other complete failure. I haven’t had time to even tackle your other suggestions yet but I have saved this and intent to fix them all eventually.

Thanks again

Gilder-Levin is difficult when you start. And even today, I “lose” my images at first. I start all my CSS background positions at 0 0 just so I can see the image when I start. This means all the buttons start out looking like the first one.

Anyway if you really get stuck you can post html/css for the menu and we can see where you’re going wrong.

I have reverted to the easiest yet most tedious method I was trying to avoid after getting insanely frustrated trying to get stuff to load in the divs and close out when you clicked the next one.

I just copied index.html with a separate name for each page I want to load that looks exactly the same except for the area I wanted to change and linked each to a Its own style sheet.

I am happy with how it turned out for now, I just want your input on it now that I have it fully functioning.

don’t be nice, I need to hear the stuff that is going to give me problems so I can fix it.

Thanks

If you got some spare time and want to read through my code, I got the site working perfect in Chrome and Firefox but the Right Notes section and my xbox avatar are screwy in IE. I tried using that W3C Validator but it only screwed things up more, sadly I don’t understand what its telling me to do most the time.

Heres my index.html

<!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">

<HTML>
  <HEAD>
  	<link href="CSS2/homestyle.css" medio="screen" rel="stylesheet" type="text/css" />
    	<TITLE>Bonkage.com</TITLE>
    
<!--[if (gt IE 6)&(lte IE 7)]>
<link href="/css/menu-ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if (gt IE 3)&(lte IE 6)]>
<div id="oldie">
<h1>Old Browser Detected</h1>
Your browser is to old to view this site properly. You can download a newer browser that is compatible with this site here:
<ul>
  <li><a href="http://www.mozilla.com/en-US/firefox/ie.html">FireFox</a></li>
  <li><a href="http://www.microsoft.com/windows/internet-explorer">Internet Explorer</a></li>
  <li><a href="http://www.apple.com/safari/">Safari</a></li>
</ul><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
<![endif]-->
<!--
//This function is used to show or hide a nested div
function show(which){
	m=document.getElementById("mainDiv");
	trig=m.getElementsByTagName("div").item(which).style.display;
	if (trig=="block") trig="none";
	else if (trig=="" || trig=="none") trig="block";
	m.getElementsByTagName("div").item(which).style.display=trig;
}
//-->
  </HEAD>
<BODY>


	<!--                                         Background                                              -->
<center><div id="BG">



	<!--                                         Top Nav                                              -->
		<div id="Bonkage"><a class="Bonkage" href="http://www.bonkage.com"></a>
  		</div>
  		<div id="Home"><a class="Home" href="http://www.bonkage.com"></a>
  		</div>
  		<div id="Portfolio"><a class="Portfolio" href="http://bit.ly/m9FsMG?r=bb"></a>
  		</div>
  		<div id="Services"><a class="Services" href="../indexServices.html"></a>
      </div>
  		<div id="Contact"><a class="Contact" href="mailto:bonkageservices@gmail.com"></a>
  		</div>
  		<div id="Logo"><a class="Logo" href="http://www.bonkage.com"></a>
  		</div>
  		<div id="SearchBar">
  		<a class="SearchBar" href="http://www.bonkage.com"></a>
  		</div>
  	

  	<!--                                         Spotlight                                              -->
   		<div id="BonkageCS"><a class="BonkageCS" href="http://www.bonkage.com/cs"></a>
   		</div>
 



  	<!--                                         Right Notes Content Links                                             -->
  <div id="RightNotes">
      <div id="WebDesign"><a class="WebDesign" href="../indexWebDesign.html"><a>
        </div>
        <div id="ImageVideoEditing"><a class="ImageVideoEditing" href="../indexImageVideoEditing.html"><a>
        </div>
      <div id="PromoAdCreation"><a class="PromoAdCreation" href="../indexPromoAdCreation.html"><a>
        </div>
        <div id="PressMediaKitCreation"><a class="PressMediaKitCreation" href="../indexPressMediaKitCreation.html"><a>
        </div>
      </div>


  

	<!--                                         Footer                                             -->
 		<div id="FooterContact"><a class="FooterContact" href="mailto:bonkagewebdesign@gmail.com"></a>
  		</div>
  		<div id="FooterPortfolio"><a class="FooterPortfolio" href="http://bit.ly/m9FsMG?r=bb"></a>
  		</div>
  		<div id="FooterForum"><a class="FooterForum" href="http://www.bonkage.com/cs"></a>
  		</div>
  		<div id="FooterTwitter"><a class="FooterTwitter" href="http://twitter.com/#!/bonkage"></a>
  		</div>
        <div id="LikeButton"><iframe src="http://www.facebook.com/plugins/like.php?app_id=217360621625938&amp;href=www.bonkage.com&amp;send=true&amp;layout=button_count&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>
        </div>
  



 	<!--                                         Xbox Avatar                                              -->
  		<div id="XboxAvatar">
        <script type="text/javascript" src="http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js"></script><script type="text/javascript">if (WIDGETBOX) WIDGETBOX.renderWidget('c7ca5dd4-3004-493f-b121-6ffcbf7ede7c');</script><noscript>Get the <a href="http://www.widgetbox.com/widget/xbox-live-avatar">Xbox Live Avatar</a> widget and many other <a href="http://www.widgetbox.com/">great free widgets</a> at <a href="http://www.widgetbox.com">Widgetbox</a>! Not seeing a widget? (<a href="http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/">More info</a>)</noscript>
    	</div>


  </BODY>
</HTML>

Thanks Again

Bate145185