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