這裏是全(S)的CSS complete working example,與 變量鼻子大小的陰影寬度和一個可選的邊界。
訣竅是獲得偏移量並將其轉換爲完美像素,並根據需要使用overflow:hidden
來削減泡泡的鼻子(尤其是在需要邊框時)。
上面的答案中的示例對我們不起作用,因爲陰影被裁剪並放置在主泡區域。
在IE7/8中優雅地降級。
HTML:
<div class="chat">
<div class="bubble">
<span class='tail'> </span>
<p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.</p><p>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
</div>
</div>
SCSS:
$shadow_radius = 6px;
$nose_size = 12px;
$shadow = 0 1px $shadow_radius #B2B2B2;
$border = 1px solid #bbb
.chat {
font-family: sans-serif;
font-size: small;
}
.bubble {
background-color: #F2F2F2;
border-radius: 5px;
border: $border;
box-shadow: $shadow;
display: inline-block;
padding: 10px 18px;
margin-left: ($shadow_radius + $nose_size);
margin-right: ($shadow_radius + $nose_size);
position: relative;
vertical-align: top;
}
.tail {
position: absolute;
top: $nose_size;
left: -($shadow_radius + $nose_size);
height: ($shadow_radius + $nose_size);
width: ($shadow_radius + $nose_size);
overflow: hidden;
}
.tail:before {
border: $border;
background-color: #F2F2F2;
box-shadow: $shadow;
content: "\00a0";
display: block;
position: absolute;
top: 0px;
left: $nose_size;
height: $nose_size;
width: $nose_size;
-webkit-transform: skew(-45deg);
-moz-transform: skew(-45deg);
}
@LordVarlin我最近使用它的iPhone後退按鈕,所以我不必使用圖像。爲了更好玩,你可以使用'transform:skew();'來改變三角形的角度。 – ThinkingStiff 2012-01-15 06:02:10
我用Firefox 14檢出了Fiddle,它顯示了一個矩形而不是三角形。這是爲什麼?在FF14中支持轉換CSS,對吧? – thomthom 2012-08-14 09:59:25
原來是Firefox不喜歡的歪斜轉換... – thomthom 2012-08-14 10:04:41