Tony Tony - 6 months ago 8
CSS Question

display: inline not working even with float

I'm trying to create a horizontal nav bar using CSS and display: inline; but I'm having no joy with it. Using

<ul><li>
, I am getting a vertical list rather than a horizontal one. I've Googled the web and poured over SO but can't find a fix.



#menu ul {
height: 15px;
padding: 8px 0px;
margin: 0px;
}
#menu li {
text-decoration: none;
display: inline-block;
padding: 20px;
float: left;
}
.logo {
font-family: 'Mr De Haviland', cursive;
font-size: 32px;
}
.logo a {
color: black;
text-decoration: none;
}
#nav a {
color: black;
text-decoration: none;
}
#nav {
max-width: 600px;
width: auto;
height: 35px;
font-size: 16px;
font-family: Helvetica, Geneva, sans-serif;
text-align: center;
text-shadow: 3px 2px 3px #666666;
background-color: #999999;
border-radius: 8px;
list-style-type: none;
}

<!DOCTYPE html>
<html lang="en-gb">

<head>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Mr+De+Haviland' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="index.css">
<title>Anthony Jones</title>
</head>

<body>
<div id="main">
<div class="logo">
<p align="center">
<a class="logo" href="index.html">Anthony Jones</a>
</p>
</div>

<div id="nav">
<ul style="list-style-type: none;">
<a href="about.html">
<li>About</li>
</a>
<a href="cv.html">
<li>Curriculum Vitae</li>
</a>
<a href="services.html">
<li>Services</li>
</a>
<a href="random.html">
<li>Random</li>
</a>
<a href="contact.html">
<li>Contact Me</li>
</a>
</ul>
</div>

</div>
</body>





The
ul style="list-style-type: none;"
in the
<style>
tag is there because I couldn't remove the bullet points within the index.css file, this was the only solution I could find.

I've tried many variations on the code, rearranged it, deleted and started over and still no joy. Any ideas?

Answer

1: you can't wrap an a tag around li. a tag must be inside li.

Like this:

<div id="nav">
<ul style="list-style-type: none;">
<li><a href="about.html">About</a></li>
<li><a href="cv.html">Curriculum Vitae</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="random.html">Random</a></li>
<li><a href="contact.html">Contact Me</a></li>
</ul>
</div>

2: Set li to display: inline

Like this:

#nav li {
    display: inline;
}