How to indent part of pages (like sub-pages) w/ HTML

Discussion in 'HTML & Website Design' started by DrewAMP, Nov 24, 2007.

  1. #1
    Hey everyone,

    I'm creating a pretty basic HTML site and I would like to have pages, and then sub-pages which are slightly more indented then the main pages.

    Like this:
    [​IMG]

    I know I could use " " but I'm not sure if that'd be the best way to do it. Is there any other way?

    Thanks.
     
    DrewAMP, Nov 24, 2007 IP
  2. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #2
    <ul>
    <li>Page 1</li>
    <li>Page 2</li>
    <li>Page 3
    <ul>
    <li>Sub-Page 1</li>
    <li>Sub-Page 2</li>
    <li>Sub-Page 3 </li>
    </ul></li>
    <li>Page 4</li>
    </ul>
     
    YIAM, Nov 24, 2007 IP
  3. DrewAMP

    DrewAMP Peon

    Messages:
    357
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! How would I avoid the indent the <ul> makes on the first one?

    Now it looks like:
    [​IMG]

    I would prefer if I didn't have the Page 1, Page 2, etc. indent, and just have the Sub-Pages indent, without the gap between "Page 3" and "Sub-Page" :) .
     
    DrewAMP, Nov 24, 2007 IP
  4. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #4
    <ul style="list-style:none; padding:0; margin:0;">
     
    YIAM, Nov 24, 2007 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Drew,

    As YIAM said, you'll have to use an unordered list for this (which makes sense, since a menu is just a list of links), with your nested pages being a nested unordered list.

    Start off by giving your main list an ID, I prefer to use "menu" for this (since that's what it is). From there, you can target the list items, links and nested lists directly via CSS.

    
    <ul id="menu">
    	<li><a href="#">Page 1</a></li>
    	<li><a href="#">Page 2</a></li>
    	<li>
    		<a href="#">Page 3</a>
    		<ul>
    			<li><a href="#">Sub-Page</a></li>
    			<li><a href="#">Sub-Page</a></li>
    			<li><a href="#">Sub-Page</a></li>
    		</ul>
    	</li>
    	<li><a href="#">Page 4</a></li>
    </ul>
    
    Code (markup):
    Then, in your stylesheet, remove the margins, padding and list bullets from the lists.

    
    #menu, #menu li, #menu ul {
    	list-style: none;
    	margin: 0;
    	padding: 0;
    }
    
    Code (markup):
    Then style to taste. If you want the submenu to appear to the right of the main list, give it a left margin. Of course, it does help to give the main list (#menu { } ) a width.

    If you can show me how you want the menu to look exactly, I'll be able to show you how to style it (without changing the HTML) to make it look how you want.
     
    Dan Schulz, Nov 25, 2007 IP
    DrewAMP likes this.