HTML,CSS:Color属性无法正常工作

时间:2016-03-26 07:40:53

标签: html css

我正在尝试建立一个网站但由于某种原因我的css颜色属性无法正常工作。我需要将下拉菜单中文本的字体颜色更改为白色。

HTML代码:

<!DOCTYPE html>
<html>
    <head>
        <meta  charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>My Cycle - Home</title>
        <link rel="stylesheet" href="css/style.css" type="text/css" />
    </head>
    <body>
        <header>
            <div id="heading">
                <img src="http://i.imgsafe.org/5d32881.png" id="image_symbol"/>
            </div>
            <div id="navbar">
                <ul id="main_navbar">
                    <li>
                        <a href="#" style="z-index: -1" class="active">Home</a>
                    </li>
                    <li class="dropdown">
                        <a class="dropbtn" style="z-index: -1">Rent</a>
                        <div class="dropdown-content">
                            <a href="rental/mountain_bikes.html">Mountain Bikes</a>
                            <a href="rental/hybrid_bikes.html">Hybrid Bikes</a>
                            <a href="rental/road_bikes.html">Road Bikes</a>
                            <a href="rental/city_bikes.html">City Bikes</a>
                        </div>
                    </li>
                    <li>
                        <a href="faq.html" style="z-index: -1">FAQ's</a>
                    </li>
                    <li>
                        <a href="about.html" style="z-index: -1">About</a>
                    </li>
                </ul>
                <ul id="sub_navbar">
                    <li>
                        <a href="contact_us.html" style="margin-right: 15px">Contact Us</a>
                    </li>
                    <li>
                        <a href="sign_up.html">Sign Up</a>
                    </li>
                    <li>
                        <a href="log_in.php">Log In</a>
                    </li>
                </ul>
            </div>
        </header>
        <section>

        </section>
        <footer>

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

CSS代码:

body {
  font-family: 'Open-sans', sans-serif, Helvetica;
  text-align: center;
  box-sizing: border-box;
}

#main_navbar {
  text-align: center;
  margin-top: 7px;
  float: left;
  padding-left: 0;
}

#main_navbar li, #sub_navbar li {
  list-style-type: none;
  display: inline-block;
  min-width: 5em;
}

#main_navbar li a, #sub_navbar li a {
  text-decoration: none;
  font-size: 1em;
  color: black;
  font-weight: normal;
}

#sub_navbar {
  float: right;
  position: relative;
  right: 15px;
  bottom: 10px;
}

.dropdown {
  position: relative;
}

.dropdown:active {
  color: #32673f;
}

.dropdown-content {
  display: none;
  min-width: 150px;
  transform: translate(15%,0);
  position: absolute;
  padding: 10px 0;
  border-bottom: 1px solid #6b6767;
  /*border-radius: 5px;*/
  box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.2);
}

.dropdown:hover .dropdown-content {
  display: block;
  background-color: black;
}

#image_symbol {
  position: relative;
  float: left;
  bottom: 10px;
  left: 0px;
}

header {
  height: 40px;
  width: 100%;
  padding-right: 30px;
  margin-left: -20px;
  margin-top: -20px;
  padding-top: 20px;
  position: fixed;
  opacity: 0.8
}

#sub_navbar li a:hover, #main_navbar li a:hover {
  color: #FFCC00;
}

#sub_navbar li .active, #main_navbar li .active {
  color: #09c;
}

header {
  background-color: #f6f6f6;
}

.dropdown-content a {
  display: block;
  font-weight: normal;
  text-align: left;
  line-height: 2em;
  font-size: 0.8em;
  padding-left: 10px;
  color: white;
}

提前谢谢你!

3 个答案:

答案 0 :(得分:1)

请试试这个:

.dropdown-content a {
  display: block;
  font-weight: normal;
  text-align: left;
  line-height: 2em;
  font-size: 0.8em;
  padding-left: 10px;
  color: white !important;
}

答案 1 :(得分:0)

更改为:

#main_navbar li > a, #sub_navbar li > a {
  text-decoration: none;
  font-size: 1em;
  color: black;
  font-weight: normal;
}

答案 2 :(得分:0)

改变你的班级,

dropdown-content a

#main_navbar .dropdown-content a

它不仅仅是颜色,还有一些其他样式也可能无法应用于下拉内容,因为它的偏好低于#main_navbar的偏好。您可以随时选择将!important放在任何地方,但请记住,!important只是一个懒惰的黑客,应该尽可能避免。