伪元素前后的 CSS 在 Edge 和 IE 11 中不起作用

标签 css internet-explorer microsoft-edge pseudo-element

我在使用 :before 和 :after 伪元素通过 css 显示带有斜边的按钮时遇到问题。它适用于 Chrome 和 Firefox,但不适用于 Edge 和 IE 11。 可能是什么问题?

a { text-decoration: none }
.container { margin: 20px; }
.font-jos {
  font-family: Verdana;
}
.btn-ribbon {
  position: relative;
  display:inline-block;
  padding: 13px 11px;
  background-color: #b46b78;
  color: #fff;
  font-size: 15px;
  line-height: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 0;
  border: none;
  margin-left: 20px;
  text-transform: uppercase;
}
.btn-ribbon:before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    display: block;
    width: 0;
    height: 0;
    border-top: 22px solid #b46b78;
    border-bottom: 22px solid #b46b78;
    border-left: 10px solid #fff0;
    z-index: 1;
}
.btn-ribbon:after {
    content: "";
    position: absolute;
    top: 0;
    right: -10px;
    display: block;
    width: 0;
    height: 0;
    border-top: 22px solid #b46b78;
    border-bottom: 22px solid #b46b78;
    border-right: 10px solid #fff0;
    z-index: 1;
}
<div class="container">
  <a href="#" class="btn font-jos btn-ribbon">Read more</a>
</div>

https://codepen.io/nidus/pen/gXJYLg

最佳答案

您需要在 CSS border 中将 #fff0 更改为 rgba(255, 255, 255, 0)transparent -right: 10px solid transparent; and border-left: 10px solid transparent;.它不喜欢颜色的格式。

IE 和 Edge 似乎不支持这种格式。

这是一个工作示例:

a { text-decoration: none }
.container { margin: 20px; }
.font-jos {
  font-family: Verdana;
}
.btn-ribbon {
  position: relative;
  display:inline-block;
  padding: 13px 11px;
  background-color: #b46b78;
  color: #fff;
  font-size: 15px;
  line-height: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 0;
  border: none;
  margin-left: 20px;
  text-transform: uppercase;
}
.btn-ribbon:before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    display: block;
    width: 0;
    height: 0;
    border-top: 22px solid #b46b78;
    border-bottom: 22px solid #b46b78;
    border-left: 10px solid transparent;
    z-index: 1;
}
.btn-ribbon:after {
    content: "";
    position: absolute;
    top: 0;
    right: -10px;
    display: block;
    width: 0;
    height: 0;
    border-top: 22px solid #b46b78;
    border-bottom: 22px solid #b46b78;
    border-right: 10px solid transparent;
    z-index: 1;
}
<div class="container">
  <a href="#" class="btn font-jos btn-ribbon">Read more</a>
</div>

关于伪元素前后的 CSS 在 Edge 和 IE 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47713799/

相关文章:

html - 如何使用html div标签和css进行水平分割

html - 如何使两个 div 具有相同的高度,其中一个必须保持正方形纵横比?

css ie/FF 与 chrome 完全不同

asp.net - TinyMCE:双前色和背景色按钮?

javascript - Microsoft Edge 是否支持用户脚本?

javascript - XMLHttpRequest : Network Error 0x80070005, Microsoft Edge(但不是 IE)上的访问被拒绝

javascript - 内联 SVG 与 CSS 背景 Sprite

css - 如何消除列之间的差距?

internet-explorer - 是什么触发了 Internet Explorer 中的信息栏?

css - IE/ME - 使用 Bootstrap 4 将中间按钮文本与 flex 垂直对齐