伪元素的Z索引样式

时间:2018-10-02 07:49:58

标签: html css angular html5 css3

目前,我正在导航栏菜单上。将鼠标悬停在我的CSS borders项目上时,我希望能够使用使用nav创建的箭头。目前这是可行的,但是创建的:after箭头在nav border上方时被隐藏了一半。即使按如下所示设置z-index的样式,它也仍然是隐藏的。

我只能输入一小段代码,否则可能会太多,但希望您能明白我的意思。

#navbar {
  overflow: hidden;
  background-color: white;
  font-size: 11px;
  z-index: 2;
  border: 1px solid grey;
  height: 50px;
}

.navbar-links {
  margin-left:10em;
  height: 100%;
  padding: 0em 4em 0em 1em;
  min-width:348px;
  margin-top:auto;
  margin-bottom:auto;
}

#navbar .navbar-links a {
  display:block;
  float: left;
  color: grey;
  padding: 14px 20px 14px 20px;
  text-decoration: none;
  font-size: 14px;
  margin-top: auto;
  margin-bottom: auto;
  position:relative;
}

#navbar .navbar-links a:hover::after {
  left: calc(50% - 10px);
  content: '';
  position: absolute;
  bottom: -12px;
  width: 0;
  height: 0;
  text-align: center;
  border-width: 10px 10px 0;
  border-style: solid;
  border-color: grey transparent;
  margin: auto;
  display: block;
  left:0;
  right: 0;
  z-index:10;
}
  <div id="navbar">
        <div class="navbar-links">
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link1']" (mouseover)="displayInsightDropDown();" (mouseleave)="hideInsightDropDown();">LINK 1</a>
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link2']">LINK 2</a> 
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link3']">LINK 3</a> 
        </div>
  </div>

我只希望能够在导航框之外显示这些箭头。任何建议,将不胜感激。

1 个答案:

答案 0 :(得分:1)

它是隐藏的,因为它是#navbar的子元素,因此您声明应该隐藏溢出。

您只需在overflow: visible;上设置#navbar

#navbar {
  overflow: visible; /* ← This does the trick */
  background-color: white;
  font-size: 11px;
  z-index: 2;
  border: 1px solid grey;
  height: 50px;
}

.navbar-links {
  margin-left:10em;
  height: 100%;
  padding: 0em 4em 0em 1em;
  min-width:348px;
  margin-top:auto;
  margin-bottom:auto;
}

#navbar .navbar-links a {
  display:block;
  float: left;
  color: grey;
  padding: 14px 20px 14px 20px;
  text-decoration: none;
  font-size: 14px;
  margin-top: auto;
  margin-bottom: auto;
  position:relative;
}

#navbar .navbar-links a:hover::after {
  left: calc(50% - 10px);
  content: '';
  position: absolute;
  bottom: -16px;
  width: 0;
  height: 0;
  text-align: center;
  border-width: 10px 10px 0;
  border-style: solid;
  border-color: grey transparent;
  margin: auto;
  display: block;
  left:0;
  right: 0;
  z-index:10;
}
<div id="navbar">
        <div class="navbar-links">
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link1']" (mouseover)="displayInsightDropDown();" (mouseleave)="hideInsightDropDown();">LINK 1</a>
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link2']">LINK 2</a> 
          <a [routerLinkActive]="['navbar-links-active']" [routerLink]="['link3']">LINK 3</a> 
        </div>
  </div>

相关问题