简体   繁体   English

CSS悬停问题(填充)

[英]CSS Hover Issue (Padding)

Trying to have padding around the menu items and when they hover over it changes background colour. 尝试在菜单项周围填充鼠标,并将其悬停在菜单项上时会更改背景颜色。 However, at the moment padding is only effecting the side of the elements and not the top or bottom. 但是,目前,填充仅影响元素的侧面,而不影响顶部或底部。

HTML: HTML:

<html>
<head>
    <link rel="stylesheet" href="style.css" type"text/css" />
</head>
<body>
    <div id="container">
        <div id="header">
            <ul id="menu">
                <li><a href="index.html">Home</a></li>
                <li><a href="index.html">About</a></li>
                <li><a href="index.html">Contact</a></li>
            </ul>
        </div>
    </div>
</body>
</html>

CSS: CSS:

#container {
    margin:auto;
    border:1px solid black;
    width:960px;
    height:700px;
}

#header {
    width:960px;
    height:150px;
    border: 1px solid blue;
}

#menu {
    width:800px;
    list-style:none;
}

#menu li {
    float:left;
    margin-left:20px;
    border:1px solid black;
}

#menu a:hover {
    background:blue;
    padding:20px;
}

#menu a {
    padding:20px;
    height:20px;
    text-decoration:none;
}

Simply replace height:20px with display:block for #menu a as height seems redundant from what I can see. 只需更换height:20pxdisplay:block用于#menu a作为height似乎从我所看到的冗余。

#menu a {
  padding:20px;
  display:block;
  text-decoration:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM