div { position: relative; width: 100px; height: 100px; background: #f00; }
div::before { position: absolute; content: ''; width: 75px; height: 75px; background: #0f0; }
div::before::before { position: absolute; content: ''; width: 50px; height: 50px; background: #00f; }
是我的语法错误还是pseudo-element内的伪元素不被支持?伪元素中是否有伪元素?
请注意,我知道::after
伪元素,但我需要另一个伪元素内的实际元素来实现,例如,其中::after
不足以是:
div { position: relative; width: 100px; height: 100px; background: #f00; }
div::before { position: absolute; content: ''; right: 0; bottom: 0; width: 75px; height: 75px; background: #0f0; }
div::after { position: absolute; content: ''; left: 0; top: 0; width: 50px; height: 50px; background: #00f; }
由于::after
是相对于元素和不::before
。
看到这个帖子http://stackoverflow.com/q/9007546/703717 – Danield
因为你正在做的'absolute'定位,没有理由不使用':after',它只需要将它的位置在某些方面计算到':before'的位置(参见http://jsfiddle.net/dBj3c/4/,它将':after'放在哪里,如果它实际上可能是根据你的代码在'before:before'之前)。 – ScottS