Pergunta

How do I enter the following code into CSS so that I don't have to copy and paste it in every HTML page?

ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li
{
float:left;
}
a:link,a:visited
{
display:block;
width:120px;
font-weight:bold;
color:#FFFFFF;
background-color:#98bf21;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a:hover,a:active
{
background-color:#7A991A;
}

My issue is especially with the "ul" and "li" -I am not sure what to do with this! Any help would be greatly appreciated- thanks!

Foi útil?

Solução 2

Place the html in a seperate .CSS stylesheet and reference it as:

<link href="url to stylesheet.css" rel="stylesheet" type="text/css">

To use the ul and li tags you would write something similar to this:

<ul>

<li>
            <a href="#">Item 2</a>
            <ul>
                <li><a href="">Sub Item 1</a></li>
                <li><a href="">Sub Item 2</a></li>
                <li><a href="">Sub Item 3</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Item 3</a>
            <ul>
                <li><a href="">Sub Item 1</a></li>
                <li><a href="">Sub Item 2</a></li>
                <li><a href="">Sub Item 3</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Item 4</a>
            <ul>
                <li><a href="">Sub Item 1</a></li>
                <li><a href="">Sub Item 2</a></li>
                <li><a href="">Sub Item 3</a></li>
            </ul>
        </li>   
    </ul>

Outras dicas

Place your css in a separate file and use the following directive to make it accessible in each page:

<link href="url to stylesheet.css" rel="stylesheet" type="text/css">

Create a CSS file and link it to your HTML file.

Add your css in separate .css file and call it in html file

<!DOCTYPE html >
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" /> 
</head>
<body>
</body>
</html>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top