无法将鼠标悬停在导航锚上

时间:2019-05-11 17:18:00

标签: html css hover

无法使菜单链接上的鼠标悬停工作。我正在使用Xampp进行本地远程测试。

.menu ul>li a:hover{
        color: blue;
        font-size: 3rem;
    }

我尝试了不同的选择器,等等...似乎没有任何作用 这是代码:

* {
  box-sizing: border-box;
}

html,
body {
  color: #222;
  font-size: 16px;
  line-height: 1.4;
  height: 100%;
  font-family: 'Roboto', sans-serif;
  margin: 0;
}

header {
  background-image: url("../images/header.jpg");
  height: 70%;
  width: 100%;
  overflow: hidden;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.about {
  background-image: url("../images/bellow_header.jpg");
  height: 70%;
  width: 100%;
  overflow: hidden;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* here starts the styles for the NAvigation bar */

#logo {
  font-size: 2.5rem;
  text-decoration: none;
  display: block !important;
  text-align: center;
  color: black;
  margin: 1rem auto 0 auto;
  font-family: 'Pacifico', cursive;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.menu {
  overflow: hidden;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  margin: 0.5rem 1.5rem;
}

.active a {
  color: #CC5200!important;
  font-size: 1.7rem;
  font-weight: 700;
}

.menu a {
  font-size: 1.5rem;
  font-weight: 500;
  padding: 0.3rem;
  text-decoration: none;
  color: black;
}


/*by default on mobile the navigation isn't visible*/

.menu li {
  display: none;
  color: black;
}

.menu .icon {
  order: 99;
  display: block;
}

.menu.menuOpen {
  position: fixed;
  width: 80%;
  left: 10%;
  flex-direction: column;
  background-color: #161415;
  border-radius: 1rem;
  margin: 0.5rem auto;
}


/*moving the icon to the top-right corner*/

.menu.menuOpen .icon {
  position: absolute;
  right: 0;
  top: 0;
}

.menu.menuOpen li {
  display: block;
  text-align: center;
  color: white;
}


/*tablets */

@media only screen and (min-width: 481px) {
  /* Styles */
  /*hidding the icon*/
  .menu .icon {
    display: none!important;
  }
  .menu li {
    display: inline-block;
    margin-left: 0.5rem;
  }
  .menu ul>li a:hover {
    color: blue;
    font-size: 3rem;
  }
  #logo {
    margin-left: 2rem;
    margin-top: 1rem;
    display: inline-block;
    text-align: left;
  }
}


/*Landscape making the background look good */

@media screen and (min-width: 481px) and (max-width: 768px) and (orientation:landscape) {
  /* Landscape styles */
  header {
    height: 120%;
  }
}


/*laptops */

@media only screen and (min-width: 769px) {
  /* Styles */
  #logo {
    display: inline-block;
    position: relative;
    top: 3rem;
    left: 4rem;
  }
}


/*large screens */

@media only screen and (min-width: 1025px) {
  /* Styles */
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>StyleTravel-Home</title>
  <!-- Javascript -->
  <script type="text/javascript" src="scripts/app.js"></script>

  <meta name="description" content="StyleTravel is one of the most used services for booking HighEnd Sejours">
  <meta name="keywords" content="Sejours,StyleTravel,HighEnd,Expensive,Exotic">
  <meta name="author" content="Bogdan Mihalca">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- normalize -->
  <link rel="stylesheet" href="css/normalize.css">
  <!--layout styles -->
  <link rel="stylesheet" href="css/layout.css">
  <!-- Font Awesome  -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <!-- Google fonts -->
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,400i,500,700,900" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">

  <link rel="shortcut icon" type="image/png" href="images/favicon.png" />
</head>

<body>
  <header>
    <a href="index.html" id="logo">StyleTravel</a>
    <nav class="menu" id="myMenu">
      <ul>
        <li class="active"><a href="#home">Home</a></li>
        <li><a href="#news">News</a></li>
        <li><a href="#contact">Contact</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="search"><i class="fa fa-search"></i>Search</a></li>
        <li>
          <a href="javascript:void(0);" class="icon" onclick="myResponsiveHamburger()">
            <i id="hamb-icon" class="fa fa-bars"></i></a>
        </li>
      </ul>
    </nav>
  </header>
  <div class="about"></div>

</body>

</html>

1 个答案:

答案 0 :(得分:0)

#logo {
font-size: 2.5rem;
text-decoration: none;
/* display: block !important; */

}

您的悬停绝对可以,但是一个错误! display: block !important;这就是您所穿的衣服,它正在伸展并占据了所有可见的宽度。因此,当您将鼠标悬停在链接上时,实际上并没有将鼠标悬停在链接上!如果您删除或取消设置样式,它将起作用!

尽管您的悬停效果并不理想,但是如果您删除代码,它将悬停!这是我的demo

enter image description here

#logo {
  font-size: 2.5rem;
  text-decoration: none;
  display: block !important;  /* Remove this ans code will work!*/
  text-align: center;
  color: black;
  margin: 1rem auto 0 auto;
  font-family: "Pacifico", cursive;
  outline: 1px solid red;  /* for demonestration */
  background: #3333;     /* for demonestration */
}

只需删除评论的样式,就可以了。