2015-12-21 20 views
2

我可能誤解了在CSS中的::之前::之後的功能。::之後似乎沒有做我所期待的?

我想要實現的是一個200x200px的盒子,然後在右上角會有另一個盒子(24x24)。這裏是我的本錢:

https://jsfiddle.net/xd6L3h6v/

<div id="foo">bla test</div> 

#foo { 
    position: relative; 
    width: 200px; 
    height: 200px; 
    background: green; 
} 
#foo::before { 
    position: absolute; top: 0; left: 0; 
    background: red; 
    width: 24px; 
    height: 24px; 
} 

但是,這是行不通的。當我檢查它在Firefox,我沒有看到::之前部分在Firebug的DOM檢查器

我哪裏錯了?

謝謝!

+0

螢火蟲不顯示在DOM檢查僞元素。 Chrome確實... –

回答

1

你只需要添加content: '';

#foo { 
 
    position: relative; 
 
    width: 200px; 
 
    height: 200px; 
 
    background: green; 
 
} 
 
#foo::before { 
 
    position: absolute; top: 0; left: 0; 
 
    background: red; 
 
    width: 24px; 
 
    height: 24px; 
 
    content: ''; 
 
}
<div id="foo">bla test</div>

+0

ARGH ...現在我覺得很蠢!不能相信我錯過了那一點。它是那些日子之一:/它不會讓我接受這個答案,但我會盡快讓它做。 –

+1

無需刪除該問題 - 它可以幫助未來遇到同一問題的其他人:) –

相關問題