Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to make a header with some decent css and something was wrong: When I tested this with my localhost (via XAMPP) the list isn't centered in the middle of my background, instead it is above.

How can I solve this problem?

Regards,
Andreas


HTML
<!DOCTYPE html>
<html>
    <header>
        <link rel="stylesheet" type="text/css"href="header.css">
        <ul>
          <li><a href="">Home</a></li>
          <li><a href="">About</a></li>
          <li><a href="">Contact</a></li>
          <li><a href="">Agenda</a></li>
          <li><a href="">Menu</a></li>
        <p>  Cafe <strong> Welkom</strong></p> <br>
        </ul>
        
    
    </header>    
</html>


What I have tried:

CSS:

header
{
text-align: center;
list-style-position: outside;

}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

li {
float: left;

}

li a {
font-size: 15px;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;

}


li a:hover {
background-color: darkkhaki;
}
p
{
font-family: sans-serif;
color: lightgoldenrodyellow;
}
Posted
Updated 28-Sep-16 18:53pm
Comments
Karthik_Mahalingam 29-Sep-16 0:52am    
post a screenshot of it.

1 solution

I made a couple of changes. Firstly, I took out margins and padding from the top and also wrapped the header in a div called heading to get the 100% width affect and then center what was the li as a div; so it could be centered. Also, the p is moved into the li so it is part of the unordered list. To gain the nice font, I wrapped it in a span.
CSS
* {
  margin: 0;
  padding: 0;
}
#header{width: 50%; margin-top: 0px;
  margin-left: auto;
  margin-right: auto;}

#heading{background: #333; width: 100%; height: 50px; margin-top: 0px;}

header
{
text-align: center;
list-style-position: outside;

}
ul  li{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}

li {
float: left;

}

li a {
font-size: 15px;
/*display: block;*/
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;

}


li a:hover {
background-color: darkkhaki;
}
span
{
font-family: sans-serif;
color: lightgoldenrodyellow;
} 

HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"href="header.css">
</head>
<body>
<div id="heading">
    <div id="header">
        <ul>
          <li><a href="">Home</a></li>
          <li><a href="">About</a></li>
          <li><a href="">Contact</a></li>
          <li><a href="">Agenda</a></li>
          <li><a href="">Menu</a></li>
        <li><span>  Cafe <strong> Welkom</strong></span></li>
        </ul>
    </div>
</div>
<body>   
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900