+ Reply to Thread
Results 1 to 7 of 7

Thread: css question

  1. #1
    Daiphron is offline x10Hosting Member Daiphron is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    25

    css question

    Hi,

    I am trying to create a webpage that is devided into subpages with css. This means that visitors would be on one and the same page but when the click a link on that page it would take them to a different section and it would look like they are on a different page. I have seen this before but I forgot the url. I know that this is possible with the overflow:hidden and display:none properties and the sections looked something like this in the url:

    www.webaddress.com/#section1
    www.webaddress.com/#section2
    ...

    Can anyone help me out with a generic code snippet to accomplish this effect?

    Thanks!

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: css question

    This can be easily done with JavaScript or PHP... But here is the code:
    HTML Code:
    <body>
    <table style="height: 800px; width: 100%; overflow: hidden;" align="center" border="0" cellpadding="0" cellspacing="0">
    <tr><td><a href="#section1"></a>
    Site Code (exactly 800px)...
    <a href="#section2"></a>
    Site Code (exactly 800px)...
    </td></tr></table></body>
    Or better with PHP:
    PHP Code:
    <body>
    <table style="height: 100%; width: 100%; overflow: hidden;" border="0" cellpadding="0" cellspacing="0">
    <tr><td style="display: <?php echo ($_GET["section"]===1)? "block;" "none;"?>">
    Site Code (any Length)...
    </td></tr><tr><td style="display: <?php echo ($_GET["section"]===2)? "block;" "none;"?>">
    Site Code (any length)...
    </tr></td></table></body>
    The URL instead of #section1 would be ?section=1, but it's still easier and more reliable to do.
    Adjust size measurements
    Last edited by Twinkie; 03-01-2008 at 09:56 PM.

  3. #3
    Daiphron is offline x10Hosting Member Daiphron is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    25

    Re: css question

    Thanks a lot for the help. PHP won't work on the site that's why I was asking for the CSS version

  4. #4
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: css question

    You are thinking of AJAX. A mix of javascript and PHP.
    Unless you want to load both pages into that one page.

    Give me a sec I'll give you a demo of how to do it.

    Here is the script:

    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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <style>
    	.show{
    		display:block;
    		visibility:visible;
    	}
    	.hide{
    		display:none;
    		visibility:hidden;
    	}
    </style>
    <body>
    <script language="javascript1.2">
    	function swapPages(p){
    		document.getElementById('section1').className = "hide";
    		document.getElementById('section2').className = "hide";
    		document.getElementById(p).className = "show";
    	}
    </script>
    <a href="#" onclick="swapPages('section1');">Show Section 1</a><br />
    <a href="#" onclick="swapPages('section2');">Show Section 2</a>
    <div id="section1" class="hide">
    	<div>This is the first page.</div>
    	<div>This contains the content of section1</div>
    </div>
    <div id="section2" class="hide">
    	<div>This is the second page.</div>
    	<div>This contains the content of section2</div>
    </div>
    </body>
    </html>
    Last edited by VPmase; 03-03-2008 at 11:23 AM.

  5. #5
    jowda is offline x10Hosting Member jowda is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    6

    Re: css question

    What is the benefit of doing it through ajax/php vs. the div tags?

  6. #6
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: css question

    That is not AJAX, that is HTML DOM. With HTML DOM, you can make elements disappear and reappear, although you cannot specify which sections to be displayed in the URL. However, if you use VPmase's suggestion, you would have to load section one and click the link before section two is displayed.

  7. #7
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: css question

    Quote Originally Posted by jowda View Post
    What is the benefit of doing it through ajax/php vs. the div tags?
    The difference is that with Ajax you won't have to load both of the 'pages' at once which will decrease the load times.

+ Reply to Thread

Similar Threads

  1. Lottery Website (kind of)
    By admintwo in forum Earning Money
    Replies: 4
    Last Post: 12-29-2007, 05:07 PM
  2. Question about reputation....
    By Swiblet in forum Off Topic
    Replies: 4
    Last Post: 12-17-2007, 12:56 AM
  3. Odd question but will I be banned for this?
    By sielk in forum Free Hosting
    Replies: 3
    Last Post: 09-28-2007, 11:29 AM
  4. Question about Phpbb and welcom
    By Mr. Coolkat in forum Free Hosting
    Replies: 2
    Last Post: 10-17-2005, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers