选择子项时,在父项的活动状态下放下划线

时间:2017-04-04 14:58:42

标签: css nav stylus

这是我的codepen: http://codepen.io/beckbeach/pen/jBJByz?editors=1100

我有一个使用Stylus(css)的导航栏。在导航栏中选择子项时,我希望父项加下划线。示例:当您将鼠标悬停在“关于”并进入子菜单时,我希望“约有下划线”。

我的手写笔:



heading-color = hsl(262, 17%, 24%);
text-color = #7d809f;
accent-color = hsla(349, 85%, 55%, 1);
link-color = #ec1019;
link-color2 = #790000;

* {
  font-family: Helvetica;
}

.theme-a {
  p {
    color: text-color;
  }
  h1, h2, h3, h4, h5, h6 {
    color: heading-color;
  }
  a { 
    color: link-color;
    &:hover {
      color: link-color2;
    }
  }
}

nav {
  @extends .theme-a;
  border-bottom: 1px solid rgba(0,0,0,.0785);
  background: white;
  height: 60px;
  width: 100%;
  display: flex;
  color: link-color;
  padding: 0 30px;
  flex-direction: row;
  justify-contnent: flex-start;
  align-items: center;
  @media screen and (max-width: 1200px) {
    padding-left: calc(((100% - 1200px) / 2) + 30px);
    padding-right: calc(((100% - 1200px) / 2) + 30px);
  }
  p {
    margin: 0;
  }
  a {
    text-decoration: none;
  }
}
.caret {
   position: relative;
  cursor: pointer;
  &:before {
  content: '';
  position: absolute;
  top: 25%;
  left: 8px;
  border-top: 6px solid link-color;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  }
  &:after {
    content: '';
  position: absolute;
  top: 25%;
  left: 9px;
  border-top: 5px solid #fff;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  }
}
// TODO: Cleanup.
.Navbar {
  &_nav-link {
    margin: 0 5rem 0 0;
  }
  &_right {
    display: flex;
    flex-direction: row;
    margin: 0 auto;
    
    * {
      border-top: 18px solid rgba(0,0,0,0);
      border-bottom: 18px solid rgba(0,0,0,0);
    }

    .Dropdown-parent {
      border-top: 18px solid rgba(0,0,0,0);
      border-bottom: 18px solid rgba(0,0,0,0);
      height: 100%;
      margin: 0 5rem 0 0;
      
      .Dropdown-box {
        display: none;
        width: 100%;
        position: absolute;
        top: 55px;
        left: 0;
        z-index: 100;
        background: #f2f2f2;
        padding: 0 0 0 5rem;
      }
      &:hover {
        * {
          border-top: 12px solid rgba(0,0,0,0);
          border-bottom: 12px solid rgba(0,0,0,0);
        }
        > .Dropdown-box {
          display: flex;
          flex-direction: row;
        }
      }
      > .Dropdown-box:hover {
        display: flex;
        flex-direction: row;
      }
    }

  }
}




1 个答案:

答案 0 :(得分:0)

测试这个CSS。问题是身高

heading-color = hsl(262, 17%, 24%);
text-color = #7d809f;
accent-color = hsla(349, 85%, 55%, 1);
link-color = #ec1019;
link-color2 = #790000;

* {
  font-family: Helvetica;
}

.theme-a {
  p {
    color: text-color;
  }
  h1, h2, h3, h4, h5, h6 {
    color: heading-color;
  }
  a { 
    color: link-color;
    &:hover {
      color: link-color2;
    }
    &:active {
      text-decoration: underline;
    }
  }
}

nav {
  @extends .theme-a;
  border-bottom: 1px solid rgba(0,0,0,.0785);
  background: white;
  height: 60px;
  width: 100%;
  display: flex;
  color: link-color;
  padding: 0 30px;
  flex-direction: row;
  justify-contnent: flex-start;
  align-items: center;
  @media screen and (max-width: 1200px) {
    padding-left: calc(((100% - 1200px) / 2) + 30px);
    padding-right: calc(((100% - 1200px) / 2) + 30px);
    &:active {
      text-decoration: underline;
    }
  }
  p {
    margin: 0;
  }
  a {
    text-decoration: none;
  }
}
.caret {
   position: relative;
  cursor: pointer;
  &:before {
  content: '';
  position: absolute;
  top: 25%;
  left: 8px;
  border-top: 6px solid link-color;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  }
  &:after {
    content: '';
  position: absolute;
  top: 25%;
  left: 9px;
  border-top: 5px solid #fff;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  }
}
// TODO: Cleanup.
.Navbar {
  &_nav-link {
    margin: 0 5rem 0 0;
  }
  &_right {
    display: flex;
    flex-direction: row;
    margin: 0 auto;

    * {
      border-top: 18px solid rgba(0,0,0,0);
      border-bottom: 18px solid rgba(0,0,0,0);
    }

    .Dropdown-parent {
      border-top: 18px solid rgba(0,0,0,0);
      border-bottom: 18px solid rgba(0,0,0,0);
      height: 100%;
      margin: 0 5rem 0 0;

      .Dropdown-box {
        display: none;
        width: 100%;
        position: absolute;
        top: 55px;
        left: 0;
        z-index: 100;
        background: #f2f2f2;
        padding: 0 0 0 5rem;
      }
      &:hover {
        * {
          border-top: 12px solid rgba(0,0,0,0);
          border-bottom: 12px solid rgba(0,0,0,0);
          height: 50px;
        }
        > .Dropdown-box {
          display: flex;
          flex-direction: row;
        }
      }
      > .Dropdown-box:hover {
        display: flex;
        flex-direction: row;
      }
    }

  }
}