0

I'm trying to create a very basic menu but having some problems why its not alligning horizontally showing up, any help would be appreciated... Code is:

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow:hidden; 
}
li { 
    float: center; 
}
a:link, a visited {
    font-family: arial;
    display: block;
    width: 120px;
    color: white;
    background color: #BBDB88;
    text-align: center; 
}
a:hover, a:active { 
    background-color: #69C08A; 
}
<div id="header">
    <h1>Portfolio</h1> 
</div>

<body> 
    <ul>
        <li><a href="#HomePage">Home</a></li>
        <li><a href="#AboutMe">About Me</a></li>
        <li><a href="#Coding">Coding</a></li>
        <li><a href="#Contacts">Contacts</a></li>
    </ul>
</body>
</html>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Andy1000
  • 1
  • 2
  • possible duplicate of [Make ul elements appear in a horizontal row](http://stackoverflow.com/questions/885691/make-ul-elements-appear-in-a-horizontal-row) – alex Jun 09 '15 at 16:44
  • However, you got an answer below, but if you are really interested in developing a Menu that is even more attractive you may [follow this](http://www.w3schools.com/bootstrap/bootstrap_case_navigation.asp). – Greenhorn Jun 09 '15 at 16:50
  • 1
    why is there a div before your body-tag? and why is your head inside a style-tag? you should really read some words about basic html structure. – cari Jun 09 '15 at 16:51
  • Yeah, I noticed my tagging mistakes, Thanks for noticing! – Andy1000 Jun 12 '15 at 15:22

1 Answers1

0

Try This:

Set the <li> to display: inline-block;

CSS

ul {
    list-style-type:none;
    margin:0;
    padding:0;
    overflow:hidden;
}
li { 
    float:center;
}
a:link, a visited {
    font-family:arial;
    display:block;
    width:120px;
    color:white;
    background color:#BBDB88;
    text-align:center;
}

ul li {
    background: #000;
    display:inline-block;
}

a {
    text-decoration: none;
}

a:hover, a:active {
    background-color:#69C08A;
    color: #fff;
}

HTML

<div id="header"><h1> Portfolio </h1></div>
  <ul>
    <li><a href="#HomePage">Home</a></li>
    <li><a href="#AboutMe">About Me</a></li>
    <li><a href="#Coding">Coding</a></li>
    <li><a href="#Contacts">Contacts</a></li>
  </ul>

DEMO HERE

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Luís P. A.
  • 9,524
  • 2
  • 23
  • 36