Centralized HTML/CSS menu

Asked

Viewed 336 times

1

I need a help with a code I don’t know much about HTML and CSS, I’m learning little by little, and I need a little help.

Inicio Código HTML/CSS

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  xml:lang="pt" lang="pt">

<head>
<title>Menu Horizontal</title>
<style type="text/css">
<!--
body {
padding:0px;
margin:0px;
}

#menu ul {
padding:0px;
margin:0px;
float: left;
width: 100%;
background-color:#EDEDED;
list-style:none;
font:80% Tahoma;
}

#menu ul li { display: inline; }

#menu ul li a {
background-color:#EDEDED;
color: #333;
text-decoration: none;
border-bottom:3px solid #EDEDED;
padding: 2px 10px;
float:left;
}

#menu ul li a:hover {
background-color:#D6D6D6;
color: #6D6D6D;
border-bottom:3px solid #EA0000;
}
-->
</style>
</head>

<body>
<div id="menu">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Sobre</a></li>
<li><a href="">Artigos</a></li>
<li><a href="">Estudos</a></li>
<li><a href="">Diretório</a></li>
<li><a href="">CURSO</a></li>
<li><a href="">Links</a></li>
<li><a href="">Contato</a></li>
</ul>
</div>
</body>
</html>

This and the code that I have, but I can’t put that menu always centered on the page, could help me.

Thanks in advance

1 answer

1


Must put in the #menu ul, #menu ul li and #menu ul li a the following amendments. Notes that display: inline; does not allow you to give comprimento/altura to the element, float: left; is unnecessary too.

body {
padding:0px;
margin:0px;
}

#menu ul {
padding:0px;
text-align: center;
margin: 0 auto;
width: 100%;
background-color:#EDEDED;
list-style:none;
font:80% Tahoma;
}

#menu ul li { display: inline-block; height: 100%;}

#menu ul li a {
background-color:#EDEDED;
color: #333;
text-decoration: none;
border-bottom:3px solid #EDEDED;
padding: 2px 10px;
display: block;
}

#menu ul li a:hover {
background-color:#D6D6D6;
color: #6D6D6D;
border-bottom:3px solid #EA0000;
}
<div id="menu">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Sobre</a></li>
<li><a href="">Artigos</a></li>
<li><a href="">Estudos</a></li>
<li><a href="">Diretório</a></li>
<li><a href="">CURSO</a></li>
<li><a href="">Links</a></li>
<li><a href="">Contato</a></li>
</ul>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.