两个伪元素::之前具有不同的属性

nek*_*894 1 html css pseudo-element

使用了两个::before具有不同border属性的伪元素(请参阅js小提琴).尽管"你只能使用一个::before和一个::after伪元素"这实际上是有效的.为什么?

https://jsfiddle.net/8L7zou3e/1/

<div class="el"></div>

.el {
    position: relative;
    margin: 100px 0 0 500px;
    width: 300px;
    height: 100px;
    background-color: #AA4343;
}
.el:before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 50px solid #e86d0a;
    border-left: 50px solid transparent;
    position: absolute;
    top: 0;
    left: -50px;
}

.el:before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-bottom: 50px solid #e86d0a;
    border-left: 50px solid transparent;
    position: absolute;
    top: 0px;
    left: -50px;
}
Run Code Online (Sandbox Code Playgroud)

Soo*_*lie 6

你似乎只有一个伪元素.

缺点

这就是UI中的内容:

伪

你的CSS级联到:

.el:before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 50px solid #e86d0a;
  border-left: 50px solid transparent;
  position: absolute;
  border-bottom: 50px solid #e86d0a;
  border-left: 50px solid transparent;
  top: 0;
  left: -50px;
}
Run Code Online (Sandbox Code Playgroud)

查看Chrome处理组合CSS的方式:

铬处理