View Full Version : making a div appear on the screen
AaronCampbell
07-14-2004, 02:06 PM
I want to make a div change from hidden to visible, but I want to make sure that it is positioned in the center of the users screen. The page will be pretty long, and I want to make sure they see it whether they are at the top or bottom. How could I do this?
coothead
07-14-2004, 03:49 PM
Hi there Aaron,
this will center the div as you desire. I have used a button for display puposes.
You, of course, can use whatever means you need to initiate it :D
<!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">
<head>
<title>Dead Center Div</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #404080;
margin: 0px;
padding:0;
}
#horizon {
background: transparent;
text-align: center;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
overflow: visible;
visibility: visible;
display: block
}
#content {
font-family: verdana, geneva, arial, sans-serif;
color:#000000;
background: #ffffff;
margin-left: -162px;
position: absolute;
top: -100px;
left: 50%;
width: 324px;
height: 200px;
border:solid 1px #ff00ff;
display: none;
}
.bodytext {
font-size: 14px;
margin-top:70px;
}
.headline {
font-weight: bold;
font-size: 24px
}
button {
background:#ffffff;
color:#000000;
margin:20px;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function displayDiv() {
if(document.getElementById("content").style.display=="block") {
document.getElementById("content").style.display="none";
}
else {
document.getElementById("content").style.display="block";
}
}
//]]>
</script>
</head>
<body>
<div><button onclick="displayDiv()">div on / off </button></div>
<div id="horizon">
<div id="content">
<div class="bodytext">
This div is<br />
<span class="headline">DEAD CENTRE</span><br />
and stays there!
</div>
</div>
</div>
</body>
</html>
coothead
07-14-2004, 04:06 PM
Sorry Aaron,
I did not read your quetion properly, my code will
only position the div in the center of the visible page
before scrolling. Oh well, back to the drawing board :o
AaronCampbell
07-14-2004, 04:07 PM
I was JUST going to say that. Getting close though!
Subjective Effe
07-14-2004, 04:59 PM
Use block instead of visibilty, imho.
coothead
07-14-2004, 05:39 PM
Hi there Aaron,
I have found a Floating Menu script by...Roy Whittle,
and added the on/off button to it :D
This may suit your needs, but you will probably need to
place extra buttons or links in appropriate places down
the page in additon to the one at the top :D
Anyway check out the attachment...see what you think ;)
p.s. Roy Whittle's script needs to be in the body section rather than in the head :supereek:
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.