2017-05-22 1 views
0

私のスパンの前にCSSの三角形を置いて何らかの理由で何も表示されていません。スパンの前にCSS三角形を置く方法

.triangle:before { 
 
    width: 0; 
 
    height: 0; 
 
    border-top: 3px solid transparent; 
 
    border-right: 6px solid green; 
 
    border-bottom: 3px solid transparent; 
 
    right: 100%; 
 
    top: 0%; 
 
    position: absolute; 
 
    clear: both; 
 
} 
 

 
.triangle { 
 
    position: relative; 
 
}
<span class="triangle">Hi</span>

答えて

2

あなたはあなたのスパンがclassないclassNameを使用する必要があるとあなたがCSSの前に、あなたにcontent:''を追加する必要があり、あなたのCSSで

.triangle::before{ 
    content:''; 
    width: 0; 
    height: 0; 
    border-top: 3px solid transparent; 
    border-right: 6px solid green; 
    border-bottom: 3px solid transparent; 
    right:100%; 
    top:0%; 
    position: absolute; 
    clear: both; 
} 
+0

は、私は満足している –

+0

を働いたこと、ありがとうそれを聞いて;) –

2

content : ''; 

を忘れてしまいました:

.triangle::before{ 
 
    content:''; 
 
    width: 0; 
 
    height: 0; 
 
    border-top: 3px solid transparent; 
 
    border-right: 6px solid green; 
 
    border-bottom: 3px solid transparent; 
 
    right:100%; 
 
    top:0%; 
 
    position: absolute; 
 
    clear: both; 
 
} 
 
.triangle{ 
 
    position: relative; 
 
}
<span class="triangle">Hi</span>

+0

私は反応しているだから私はclassNameを使用しなければなりません –

+0

ああ、あなたはちょうど 'content: ''' 'が必要です(クラス名は反応が終わったらクラスとしてレンダリングされます) – Pete

2

あなたは、以下の更新スニペットを確認し、あなたのCSSでcontent:''を渡すのを忘れています

.triangle::before{ 
 
    content: ''; 
 
    width: 0; 
 
    height: 0; 
 
    border-top: 3px solid transparent; 
 
    border-right: 6px solid green; 
 
    border-bottom: 3px solid transparent; 
 
    right:100%; 
 
    top:7px; 
 
    position: absolute; 
 
} 
 
.triangle{ 
 
    position: relative; 
 
    display: inline-block; 
 
}
<span class="triangle">HI</span>

関連する問題