将鼠标悬停在导航栏上时选择颜色

时间:2016-08-21 08:20:15

标签: html css twitter-bootstrap colors

所以我有这个导航栏,我想改变用鼠标悬停时的颜色。它的默认值是黑色,我希望它是浅灰色的。我在这做错了什么?

HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Frontend</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="box">
                <div id="header">
                    <br />
                    <div id="searchMenu">
                        <input id="sweBtn" type="button" value="SVENSKA" />
                        <input id="engBtn" type="button" value="ENGLISH" />
                        <input id="searchTxt" type="text" />
                        <input id="searchBtn" type="button" value="SÖK" />
                    </div>
                    <br />
                </div>
                <div class="col-sm-4 text-left" id="imgText">
                    <h3>Title</h3>
                    <p>Paragraph</p>
                </div>
                <div class="col-sm-4">
                    <img id="imgHeader" src="~/img/Header.png" />
                </div>
                <div>
                    <ul id="navBar"> //Here is the navbar I am talking about
                        <li><a>BEHÖVER DU AVOKAT?</a></li>
                        <li><a>ADVOKATETIK</a></li>
                        <li><a>ATT BLI ADVOKAT</a></li>
                        <li><a>UTBILDNING</a></li>
                        <li><a>ADVOKATSSAMFUNDET TYCKER</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <footer>

    </footer>
</body>
</html>

<link href="~/Content/custom.css" rel="stylesheet" />

CSS:

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

li {
    float: left;
}

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

        li a:hover {
            background-color: #111;
        }

#header {
    background-color: #503F31;
    color: white;
    padding: 30px;
}

#searchMenu {
    margin-left: 1450px;
}

#sweBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: grey;
}

#engBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: gold;
}

#searchTxt {
    background-color: grey;
    border-color: grey;
}

#searchBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: gold;
}

#imgText {
    font-size: 25px;
    position: absolute;
}

#imgHeader {
    width: 1904px;
}

#navBar {
    font-family: 'Times New Roman';
    color: gold;
    background-color: #503F31;
}

#footer {
    background-color: grey;
    color: white;
    padding-bottom: -250px;
}

*::selection { /*This should handle the hover color situation right?*/
  background: #cc0000;
  color: #ffffff;
}
*::-moz-selection {
  background: #cc0000;
  color: #ffffff;
}
*::-webkit-selection {
  background: #cc0000;
  color: #ffffff;
}

也是一个旁注:我希望每个列表项都用这样的垂直线分隔:“|”

3 个答案:

答案 0 :(得分:1)

li a:hover背景颜色更改为#CCC,然后将其删除:

*::selection { /*This should handle the hover color situation right?*/
  background: #cc0000;
  color: #ffffff;
}
*::-moz-selection {
   background: #cc0000;
   color: #ffffff;
}
*::-webkit-selection {
   background: #cc0000;
   color: #ffffff;
}

我假设你的#111不是黑色&#39;但是&#39; blackish&#39;因此,被视为黑色;)。

答案 1 :(得分:0)

只需更换此块:

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    /* Separator Border */
    border-right: 1px solid #000;
}

li a:hover {
    /* Background color on hover */
    background-color: silver;
    color: #fff;
}

最终的css:

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

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    border-right: 1px solid #000;
}

li a:hover {
    background-color: silver;
    color: #fff;
}

#header {
    background-color: #503F31;
    color: white;
    padding: 30px;
}

#searchMenu {
    margin-left: 1450px;
}

#sweBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: grey;
}

#engBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: gold;
}

#searchTxt {
    background-color: grey;
    border-color: grey;
}

#searchBtn {
    font-family: 'Times New Roman';
    background-color: Transparent;
    color: gold;
}

#imgText {
    font-size: 25px;
    position: absolute;
}

#imgHeader {
    width: 1904px;
}

#navBar {
    font-family: 'Times New Roman';
    color: gold;
    background-color: #503F31;
}

#footer {
    background-color: grey;
    color: white;
    padding-bottom: -250px;
}

*::selection { /*This should handle the hover color situation right?*/
  background: #cc0000;
  color: #ffffff;
}
*::-moz-selection {
  background: #cc0000;
  color: #ffffff;
}
*::-webkit-selection {
  background: #cc0000;
  color: #ffffff;
}

答案 2 :(得分:-1)

尝试添加大括号:

li a:hover {{background-color: #111;}}