Results 1 to 5 of 5

Thread: centre horizontal list with current code

  1. #1
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default centre horizontal list with current code

    i have a menu already built but need to expand it to centre in the div. I have seen a few helps and tried them but they dont seem to work

    Code:
    <div id="top"><div id="header">
          <div align="center"><img src="../images/logo1.png" alt="12345" width="960" height="56"></div>
        </div><div id="myMenu">
        <ul>
          <li><a href="../index.html">home</a></li>
          <li><a href="../about-us.html">about us</a></li>
          <li><a href="#">portfolio</a>       
          <ul>
              <li><a href="../1.php">1</a></li>
              <li><a href="../2.php">2</a></li>
              <li><a href="../3.php">3</a></li>
              <li><a href="../4.php">4</a></li>
            </ul>
          </li>
          <li><a href="../contact.html">contact</a></li>
        </ul>
    </div></div>
    the css
    Code:
    @charset "utf-8";
    /* CSS Document */
    
    pre, code {
            font-family: Monaco, Menlo, Consolas, "Courier New", monospace;
            font-size: 12px;
            color: #333;
            -webkit-border-radius: 3px;
            -moz-border-radius: 3px;
            border-radius: 3px;
          }
          pre { border: 1px solid #CCC; background-color: #EEE; color: #333; padding: 10px; overflow: scroll; }
          code { padding: 2px 4px; background-color: #F7F7F9; border: 1px solid #E1E1E8; color: #D14; }
    	a:link {
    	color: #FFF;
    }
        a:visited {
    	color: #FFF;
    }
    
    #top #myMenu {
    	border-top-width: 1px;
    	border-top-style: solid;
    	border-top-color: #FFF;
    	vertical-align: bottom;
    	padding-left: 10px;
    	padding-bottom: 5px;
    	height: 30px;
    	background-image: url(../../images/bgWHite.png);
    }
    
    #top #myMenu ul {
    	list-style-type: none;
    	position: relative;
    	padding-top: 0px;
    	margin-top: 0px;
    	text-align: center;
    }
    #top #myMenu ul li {
    	float: left;
    }
    #top #myMenu ul ul {
    	display: none;
    	position: absolute;
    }
    #top #myMenu ul li a {
    	display: block;
    	color: #9B9A8A;
    	font-family: sans-serif;
    	font-size: 14px;
    	padding-right: 40px;
    	padding-bottom: 5px;
    	padding-left: 40px;
    	padding-top: 5px;
    	margin-top: 2px;
    	text-decoration: none;
    }
    #top #myMenu ul li a:hover {
    	color: #CCC;
    	background-color: #333;
    }
    #top #myMenu li:hover ul {
    	display: block;
    	background-color: #FFF;
    	z-index: 1;
    }
    #top #myMenu li ul li {
      float: none;
    }
    #top #myContent {
      clear: both;
      padding: 10px 0;
    }
    h1 {
      font-family: sans-serif;
      margin: 10px 0 5px;
      font-size: 1.1em;
    }
    p {
      margin: 5px 0;
    }
    
    #top {
    	background-color: #9B9A8A;
    }
    #top #header {
    	padding-top: 0px;
    	padding-bottom: 0px;
    	margin-top: 0px;
    	margin-bottom: 0px;
    	padding-right: 10px;
    	padding-left: 10px;
    	border: 1px solid #FFF;
    	background-color: #9B9A8A;
    }
    any help would be appreciated

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Try
    Code:
    #top #myMenu ul li { display:inline-block }
    instead of float:left

    BTW #top #myMenu .... isn't necessary. ids are specific so just #myMenu ... is fine.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Try
    Code:
    #top #myMenu ul li { display:inline-block }
    instead of float:left

    BTW #top #myMenu .... isn't necessary. ids are specific so just #myMenu ... is fine.
    hi i tried this but something very weird happened. the button with the drop down appears at the top of the div and all the other buttons appear below and dont work. its very disjointed

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    the button with the drop down appears at the top of the div and all the other buttons appear below and dont work.
    I'm not sure what your describing here but remember that the display:inline-block; setting is trickling down to all <li>s, so to get subs to list vertically again you need to counteract it by setting display:block; on child <li>s;
    Code:
    #top #myMenu li ul li { display:block; }
    If you need more help, please provide a link to your page.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    I'm not sure what your describing here but remember that the display:inline-block; setting is trickling down to all <li>s, so to get subs to list vertically again you need to counteract it by setting display:block; on child <li>s;
    Code:
    #top #myMenu li ul li { display:block; }
    If you need more help, please provide a link to your page.
    thats great, that done it. thanks again

Similar Threads

  1. Highlight Current on Bullet List Accordion Menu
    By roef in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 07-11-2010, 09:54 PM
  2. Replies: 12
    Last Post: 05-26-2010, 06:28 AM
  3. Resolved JavaScript in a horizontal list?
    By goo in forum CSS
    Replies: 3
    Last Post: 02-05-2009, 10:01 PM
  4. Horizontal list of lists
    By jasina in forum CSS
    Replies: 0
    Last Post: 07-05-2007, 01:55 PM
  5. horizontal list image?
    By brentnicholas in forum CSS
    Replies: 5
    Last Post: 01-29-2007, 05:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •