Delta_Cmdr
Delta_Cmdr

Reputation: 180

Positioning an Unordered List horizontally

I have an Unordered List which functions as a basic navigation bar.

My goal is to display it in line at a width of 60% of the screen and to be centred. The issue I am having is that it displays a little off centre and the size also varies. I use an external style sheet. Any help will be much appreciated.

Here is the page:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Help</title>
        <link rel="stylesheet" type="text/css" href="Styles/mainStyle.css"/>
        <meta charset="UTF-8">
    </head>
    <body>
        <h2>Home</h2>
        <ul>
            <li><a href="link.htm">Home</a></li>
            <li><a href="link2.htm">Link2</a></li>
            <li><a href="link3.htm">Link3</a></li>
        </ul>
        <div id="container">
            <p>
                Some Text. Some Text. Some Text. Some Text. Some Text.
            </p>
            <p>
                More Text. More Text. More Text. More Text. More Text.
            </p>
        </div><!-- End of container -->
    </body>
</html>

Here is the external style sheet:

h2
{
    /* Positioning */
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    /* Colours */
    background-color: #99CCCC;
    /* Border */
    border: 1px solid #000000;
    border-radius: 25px;
}
ul
{
    /* Positioning */
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}
li
{
    /* Positioning */
    padding-left: 5px;
    padding-right: 5px;
    display: inline-block;
    vertical-align: top;
    /* Colours */
    background-color: #99DDBB;
    /* Border */
    border: 1px solid #000000;
    border-radius: 25px;
}
a
{
    /* Colours */
    color: #000000;
}
a:hover
{
    font-style: italic;
}
#container
{
    /* Positioning */
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}
p
{
    /* Positioning */
    padding: 10px;
    text-align: left;
    /* Colours */
    background-color: #99CCCC;
    /* Border */
    border: 1px solid #000000;
    border-radius: 25px;
}
img
{
    /* Positioning */
    width: 50%;
    border: 1px solid #000000;
    border-radius: 25px;
}

Upvotes: 2

Views: 12852

Answers (1)

pinoy_ISF
pinoy_ISF

Reputation: 1182

Reset the padding of the ul tag. Put this in the beginning of your css: ul { padding:0; }

If you want to completely reset your css go to: Reset CSS

Upvotes: 2

Related Questions