SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to center a ul within a div

    Hi I am trying to center a ul within a div but am not managing.

    You can view the page here, I am talking about the top part of the footer, the links which are currently aligned to the left, I want them in the center, any help please?

    http://bit.ly/9A5hi9

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One option is to give the ul a width and then set the left and right margins to auto

    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
    <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
    <head>
    <title></title>
    <style type="text/css">
     
    #linksContainer {
        width: 800px;
     border: 1px solid red}
     
    #linksList {
        border: 1px solid blue;
        width: 360px;
        list-style-type: none;
        margin: 20px auto 20px auto;
        padding: 10px 10px 10px 10px}
     
    #linksList li {
     display: inline;
        margin: 0px 20px 0px 20px;
        padding: 0px 0px 0px 0px}
     
    </style>
    </head>
    <body>
     
    <div id="linksContainer">
          <ul id="linksList">
                  <li>Link 1</li>
                  <li>Link 2</li>
                   <li>Link 3</li>
                   <li>Link 4</li>
          </ul>
    </div>
     
    </body>
    </html>

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would like to center it without a fixed width, as those items might change.

    also in the top menu i am trying to change the background image on rollover, which works however i want the link text to align itself to the bottom of the div, not at the middle as it is currently, how do i do that? thanks

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    without a fixed width

    HTML Code:
    <!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></title>
    <style type="text/css">
     
    #linksContainer {
        width: 500px;
        overflow: hidden;
     border: 1px solid red}
     
    #linksList {
     list-style-type: none;
        margin: 0px 0px 0px 0px;
        padding: 0px 0px 0px 0px;
        float: left;
        position: relative;
        left: 50%}
     
    #linksList li {
     float: left;
        margin: 0px 20px 0px 20px;
        position: relative;
        right: 50%}
     
    </style>
    </head>
    <body>
     
    <div id="linksContainer">
            <ul id="linksList">
                    <li>Link 1</li>
                     <li>Link 2</li>
                     <li>Link 3</li>
                     <li>Link 4</li>
              </ul>
    </div>
     
    </body>
    </html>

  5. #5
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, any suggestions for the top menu rollover as well?


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
  •