【发布时间】:2013-07-25 23:17:12
【问题描述】:
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; }
是我的语法错误还是不支持伪元素中的伪元素?
请注意,我知道 ::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。
【问题讨论】:
-
因为你在做
absolute定位,所以没有理由不使用:after,它只需要在某些方面计算它的位置:before的位置(见@987654322 @ 它将:after放在它所在的位置,如果根据上面的代码实际上可能是:before:before)。
标签: css css-selectors pseudo-element