css - 将 anchor 的文本放置在其绝对定位的伪元素之上

标签 css z-index pseudo-element

有没有可能把这个:

enter image description here

进入这个?

enter image description here

即。将 anchor 的文本放在其绝对定位的箭头伪元素之上。

我能想到的唯一解决方案是将 anchor 文本包装在一个范围内,然后将其再次绝对定位在所有内容上。 但是有没有办法在不修改标记的情况下做到这一点?

http://jsfiddle.net/pgvx1h04/

.tryout {
  margin-top: 50px;
}

.container {
  position: absolute;
  background: #fff;
  border: 1px solid black;
}

.container a {
  padding: 3px 11px;
  position: relative;
}

.container a:before, .container a:after {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  transform: rotate(45deg);
  top: -8px;
  left: 18px;
}

.container a:before {
  background: black;
  z-index: -1;
}

.container a:after {
  background: white;
  z-index: 1;
  top: -7px;
}
<div class="tryout">
  <div class="container">
    <a>Hello world</a>
  </div>
</div>

最佳答案

也许你可以像这样用 before 和 after 来伪造它:

.tryout {
    margin-top: 50px;
}
.container {
    position: absolute;
    background: #fff;
    border: 1px solid black;
}
.container a {
    padding: 3px 11px;
    position: relative;
}
.container a:before {
    content:"";
    width: 0;
    height: 0;
    border: 10px solid;
    position: absolute;
    border-top-color: transparent;
    border-right-color: transparent;
    border-left-color: transparent;
    border-bottom-color: #000;
    top: -19px;
    left: 18px;
    display: block;
}
.container a:after{
    content:"";
    width: 0;
    height: 0;
    border: 10px solid;
    position: absolute;
    border-top-color: transparent;
    border-right-color: transparent;
    border-left-color: transparent;
    border-bottom-color: #fff;
    top: -17px;
    left: 18px;
    display: block;
}
<div class="tryout">
  <div class="container">
    <a>Hello world</a>
  </div>
</div>

关于css - 将 anchor 的文本放置在其绝对定位的伪元素之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30050358/

相关文章:

css - 颜色数学 : effect of transparent black overlay on lightness

css - 我应该在前、后、首字母和第一行伪元素中使用单冒号 (:) 还是双冒号 (::)?

jquery - CSS nth-child(n) 在附加 jQuery 后没有响应

css - 使用 WKHTMLTOPDF 显示为正方形的汉字

javascript - 每次点击都带有链接的 jQuery 菜单

javascript - AngularJS,如何在 select > options 上使用 min =""来验证表单?

javascript - 遍历元素,改变 z 索引,Javascript

html - 边框不能覆盖两个div

html - Z-index in position fixed under position fixed 元素

css - 仅使用伪元素创建 css 徽章