<li> 悬停效果,肯定是和:after有关

<li> hover effect, pretty sure it's something to do with :after

我有一个 UL 菜单,我想在鼠标悬停时在 LI 下方设置一条线,我想从这个开始:

.menu-container li:after {
  content: "";
  width: 0px;
  height: 4px;
  position: absolute;
  bottom: 0;
  left: 0;
  display: block;
  z-index: 2;
  background: #fff;
  -webkit-transition: width 0.3s;
  transition: width 0.3s;
}
a:hover .menu-container li:after {
  width: 100%;
}
<div class="menu-container">
  <ul>
    <a href="#">
      <li>About</li>
    </a>
    <a href="#">
      <li>Food & Farming</li>
    </a>
    <a href="#">
      <li>Cookbook</li>
    </a>
    <a href="#">
      <li>Schools</li>
    </a>
    <a href="#">
      <li>Get Involved</li>
    </a>
  </ul>
</div>

不过没用...

任何对此的帮助都很棒!!

干杯

尝试使用 .menu-container li:hover a:after {} 或 .menu-container li a:hover:after {}

定位它

试试这个

.menu-container li:after {
  content: "";
  width: 0px;
  height: 4px;
  bottom: 0;
  /*  position: absolute; remove */
  left: 0;
  display: block;
  z-index: 2;
  background: #fff;
  -webkit-transition: width 0.3s;
  transition: width 0.3s;
  width: 0%;
  /* add */
  background: red;
  /* add */
}
.menu-container a:hover li:after {
  /* change */
  width: 100%;
}
<div class="menu-container">
  <ul>
    <a href="#">
      <li>About</li>
    </a>
    <a href="#">
      <li>Food & Farming</li>
    </a>
    <a href="#">
      <li>Cookbook</li>
    </a>
    <a href="#">
      <li>Schools</li>
    </a>
    <a href="#">
      <li>Get Involved</li>
    </a>
  </ul>
</div>

这是您要找的东西吗??

<html>

<head>
  <style type="text/css">
    .menu-container li:after {
      content: "";
      width: 0px;
      height: 4px;
      position: absolute;
      bottom: 0;
      left: 0;
      display: block;
      z-index: 2;
      background: #fff;
      -webkit-transition: width 0.3s;
      transition: width 0.3s;
    }
    a:hover .menu-container li:after {
      width: 100%;
    }
    .menu-container a {
      text-decoration: none;
    }
    .menu-container a:hover {
      text-decoration: underline;
    }
  </style>
</head>

<body>
  <div class="menu-container">
    <ul>
      <a href="#">
        <li>About</li>
      </a>
      <a href="#">
        <li>Food & Farming</li>
      </a>
      <a href="#">
        <li>Cookbook</li>
      </a>
      <a href="#">
        <li>Schools</li>
      </a>
      <a href="#">
        <li>Get Involved</li>
      </a>
    </ul>
  </div>
</body>

</html>