< a>标签不起作用且不响应悬停效果

n53p2ov0  于 2022-09-21  发布在  jQuery
关注(0)|答案(2)|浏览(120)

我正在尝试做一个网页,有一个顶部的导航面板和底部的图像滑块。图像滑块工作正常。但导航面板不会对点击或悬停效果做出React。

body {
  margin: 0px;
  padding: 10px;
  background-color: #ccc9c9;
}

header{
  width: 100%;
  height: 70px;
  background-color: #282828;
}
h1{
  position: absolute;
  padding: 3px;
  float: left;
  margin-left: 2%;
  margin-top: 10px;
  font-family: Calibri;
  color: #39ca74;
}
span{
  color: #ffffff
}
nav-btn a:hover{
  text-decoration:underline;
}

li{
  display: inline-block;
  padding: 15px 30px;
}
a {
  width: auto;
  float: right;
  margin-top: 8px;
  text-decoration:underline;
  text-align: center;
  color:#ffffff
}
.box {
  width: 300px;
  box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  overflow: hidden;
  margin: 25px;
}
.slide-img {
  height: 350px;
  position: relative;
}
.slide-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detail-box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  box-sizing: border-box;
  font-family: calibri;
}
.type {
  display: flex;
  flex-direction: column;
}
.type a {
  color: #222222;
  margin: 5px 0px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding-right: 8px;
}
.type span {
  color: rgba(26, 26, 26, 0.5);
}
.quantity {
  color: #333333;
  font-weight: 600;
  font-size: 1.1rem;
  font-family: poppins;
  letter-spacing: 0.5px;
}
.overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background-color: rgb(190, 204, 191, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  visibility: hidden;
}
.details-btn {
  width: 160px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
  color: #252525;
  font-weight: 700;
  letter-spacing: 1px;
  font-family: calibri;
  border-radius: 20px;
  box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
}
.details-btn:hover {
  color: #ffffff;
  background-color: #288a40;
  transition: all ease 0.3s;
}
.slide-img:hover .overlay {
  visibility: visible;
  animation: fade 0.5s;
}
@keyframes fade {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
.slider {
  width: 50%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: translate(50%);
}
<header>
  <nav>
    <ul class="navigation">
      <li><a href="templates/index.html" class="nav-btn"></a>Home</li>
      <li><a href="templates/index.html" class="nav-btn"></a>Items</li>
      <li><a href="templates/index.html" class="nav-btn"></a>Browse</li>
      <li><a href="templates/index.html" class="nav-btn"></a>Add Items</li>
      <li><a href="templates/index.html" class="nav-btn"></a>Logout</li>
      <li><input type="submit" value="Go to Google" />Logout</button></li>
    </ul>
  </nav>
</header>
<body>
  <section class="slider">
    <ul id="autoWidth" class="cs-hidden">
        <li class="item-a">
            <div class="box">
                <div class="slide-img">
                  <img src="static/images/1.webp" alt="1" />
                  <div class="overlay">
                    <a href="#" class="details-btn">View Details</a>
                  </div>
                </div>

                <div class="detail-box">
                  <div class="type">
                    <a href="#">Camera & Camcorders</a>
                    <span>Available Units: </span>
                  </div>
                  <a href="#" class="quantity"> 0 </a>
                </div>
              </div>
        </li>
       </ul>
 </body>

结果:Above code is the partial code for the html code I am using and the css is code is the complete one. As you can see, the hovering would effect it at all and they dont respond to clicks either

yr9zkbsy

yr9zkbsy1#

nav-btn a:hover{
  text-decoration:underline;
}

看起来你遗漏了。在NAV-BTN班级。

应该是这样的

.nav-btn a:hover{
  text-decoration:underline;
}
q5lcpyga

q5lcpyga2#

也许你可以试试这段代码,确保你在全屏运行

body {
    margin: 0px;
    padding: 10px;
    background-color: #ccc9c9;
  }

header{
  width: 100%;
  height: 70px;
  background-color: #282828;
}
h1{
  position: absolute;
  padding: 3px;
  float: left;
  margin-left: 2%;
  margin-top: 10px;
  font-family: Calibri;
  color: #39ca74;
}
span{
  color: #ffffff
}

.nav-btn {
  text-decoration: none;
}

.nav-btn:hover{
  text-decoration:underline;
}

li{
  display: inline-block;
  padding: 15px 30px;
}
a {
  width: auto;
  float: right;
  margin-top: 8px;
  text-decoration:underline;
  text-align: center;
  color:#ffffff
}
.box {
  width: 300px;
  box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  overflow: hidden;
  margin: 25px;
}
.slide-img {
  height: 350px;
  position: relative;
}
.slide-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detail-box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  box-sizing: border-box;
  font-family: calibri;
}
.type {
  display: flex;
  flex-direction: column;
}
.type a {
  color: #222222;
  margin: 5px 0px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding-right: 8px;
}
.type span {
  color: rgba(26, 26, 26, 0.5);
}
.quantity {
  color: #333333;
  font-weight: 600;
  font-size: 1.1rem;
  font-family: poppins;
  letter-spacing: 0.5px;
}
.overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background-color: rgb(190, 204, 191, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  visibility: hidden;
}
.details-btn {
  width: 160px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
  color: #252525;
  font-weight: 700;
  letter-spacing: 1px;
  font-family: calibri;
  border-radius: 20px;
  box-shadow: 2px 2px 30px rgba(0, 0, 0, 0.2);
}
.details-btn:hover {
  color: #ffffff;
  background-color: #288a40;
  transition: all ease 0.3s;
}
.slide-img:hover .overlay {
  visibility: visible;
  animation: fade 0.5s;
}
@keyframes fade {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
.slider {
  width: 50%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: translate(50%);
}
<header>
  <nav>
     <ul class="navigation">
        <li><a class="nav-btn" href="#">Home</a></li>
        <li><a class="nav-btn" href="#">Items</a></li>
        <li><a class="nav-btn" href="#">Browse</a></li>
       <li><a class="nav-btn" href="#">Add Items</a></li>
        <li><a class="nav-btn" href="#">Logout</a></li>
     </ul>
</nav>
</header>
<body>
  <section class="slider">
    <ul id="autoWidth" class="cs-hidden">
        <li class="item-a">
            <div class="box">
                <div class="slide-img">
                  <img src="static/images/1.webp" alt="1" />
                  <div class="overlay">
                    <a href="#" class="details-btn">View Details</a>
                  </div>
                </div>

                <div class="detail-box">
                  <div class="type">
                    <a href="#">Camera & Camcorders</a>
                    <span>Available Units: </span>
                  </div>
                  <a href="#" class="quantity"> 0 </a>
                </div>
              </div>
        </li>
       </ul>
 </body>

相关问题