代码之家  ›  专栏  ›  技术社区  ›  Matt

将鼠标悬停在flexbox中的文本下方

  •  0
  • Matt  · 技术社区  · 6 年前

    我想画一条下划线 hover 竖直 nav flexbox . 水平 没有 柔性箱 下划线很好用,但越快越好 柔性箱

    在下面的第一段代码中,请看它是如何按预期工作的,但只要我 main_nav 垂直于 在第二段中,下划线断开。

    如何修复此问题,使其在保持 导航 竖的

    #wrapper {
      width: 100%;
      height: 300px;
      background-color: black;
    }
    
    
    #wrapper #main_nav {
      //display: flex;
      //flex-direction: column;
    }
    
    .nav_item {
      text-decoration: none;
      color: white;
      display: inline-block
    }
    
    .nav_item:after {
      display: block;
      content: '';
      width: 0;
      height: 2px;
      background-color: white;
    }
    
    .nav_item:hover:after {
      width: 100%;
      transition: width 150ms ease-in;
    }
    <div id="wrapper">
        <nav id="main_nav">
          <a href="#" class="nav_item">Item1</a>
          <a href="#" class="nav_item">Item2</a>
          <a href="#" class="nav_item">Item3</a>
          <a href="#" class="nav_item">Item4</a>
        </nav>
    </div>

    #wrapper {
      width: 100%;
      height: 300px;
      background-color: black;
    }
    
    
    #wrapper #main_nav {
      display: flex;
      flex-direction: column;
    }
    
    .nav_item {
      text-decoration: none;
      color: white;
      display: inline-block
    }
    
    .nav_item:after {
      display: block;
      content: '';
      width: 0;
      height: 2px;
      background-color: white;
    }
    
    .nav_item:hover:after {
      width: 100%;
      transition: width 150ms ease-in;
    }
    <div id=“包装器”>
    <导航id=“主导航”>
    <a href=“#”class=“导航项目”>项目2</a>
    <a href=“#”class=“导航项目”>项目3</a>
    </导航>
    </部门>
    2 回复  |  直到 6 年前
        1
  •  2
  •   Helenesh room13    6 年前

    使用 display: inline-flex; display:flex; ,这是块级别。

        2
  •  2
  •   Henfs    5 年前

    stretch 这些项目。
    对于 flex-direction: column 配置,您必须添加 align-items: flex-start

    #wrapper #main_nav {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
    }