master maste
New Member
- Reaction score
- 32
I am trying to hide and show text when you click on a link... e.g. when you click on the "contact" link it shows the contact div.
My problem is that when I click on the "contact" link and then click on the "about" link it puts them on top of each other, but I want it to hide the contact div when I click on the "about" link. and vice versa so that only one lot of information is being showed at any one time. (but at the start only links are shown, thats why #about and #contact have display set to none)
html:
CSS:
My problem is that when I click on the "contact" link and then click on the "about" link it puts them on top of each other, but I want it to hide the contact div when I click on the "about" link. and vice versa so that only one lot of information is being showed at any one time. (but at the start only links are shown, thats why #about and #contact have display set to none)
html:
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/ico" href="images/favicon.ico" />
<link href="css.css" rel="stylesheet" type="text/css"/>
<title>Default</title>
</head>
<body>
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
//-->
</script>
<div id="image"></div>
<div id="main">
<a href="#" onclick="toggle_visibility('about');">About</a>
<a href="#" onclick="toggle_visibility('contact');">Contact</a>
</div>
<div id="about">
<p>About About About About About About About About About About About About About About About About About About About About About About About About About About About About About About About About rawr</p></div>
<div id="contact">
<p>Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact Contact rawr</p></div>
</body>
</html>
CSS:
Code:
@charset "utf-8";
/* CSS Document */
#image {
float: left;
height: 400px;
width: 250px;
margin: 10% 0 0 0;
background: #999999;
}
#main {
position: absolute;
width: 500px;
margin: 10% 0 0 40%;
background: #0099FF;
}
#about, #contact {
position: absolute;
width: 500px;
margin: 15% 0 0 40%;
background: #0099FF;
}
/*-----Text-----*/
h1, h2, p, ul, a:link, a:visited {
font-family: Arial, Helvetica, sans-serif;
}
/*-----Display-----*/
#about, #contact {
display: none;
}