Sunday, August 27, 2006

Hiding Page Content

Suppose a circumstance arises where - for whatever reason - you want to hide page content from human users but not search engine spiders.

The following code uses CSS to create two divs and then puts one div behind the other by using Z-Index. Human visitors to your site see the top div, search engine spiders see both. Be warned: users surfing in FireFox with CSS turned off will see all content as well.


<html>
<head>
<style type="text/css">
body
{
margin: 0px 0px 0px 0px;
}

#absdiv1
{
z-index: 5;
position: absolute;
width: 100%;
height: 75px;
background-color: #ffffff;
}

#reldiv2
{
z-index: 1;
position: relative;
width: 300px;
height: 75px;
}
</style>
</head>

<body>
<TABLE cellpadding=5 cellspacing=0 width="100%">
<TR>
<TD>
<div id="absdiv1">
This could the div with your header stuff in it,
or your logo in the upper left
</div>

<div id="reldiv2">
You can put all kinds of stuff in this div and no
one can see it; links, keywords, even images
</div>
</TD>
</TR>
</TABLE>
</body>
</html>

No comments: