2012-01-17 102 views
9

所以我正在研究一個純粹的css語音泡泡http://bit.ly/zlnngM,但我想讓邊框環繞整個對話泡泡,如http://bit.ly/zUgeZi所示。我使用以下標記;帶邊框的純CSS語音泡泡

<div class="speech-bubble"><p>This is a speech bubble created using only CSS. No images to be found here...</p></div 

我到目前爲止的樣式如下;

.speech-bubble { 
margin: 3em; 
width: 320px; 
padding: 10px; 
background-color:rgba(250, 250, 250, 0.95); 
color: #666; 
font: normal 12px "Segoe UI", Arial, Sans-serif; 
-moz-border-radius: 10px; 
-webkit-border-radius: 10px; 
border-radius: 10px; 
border: 10px solid rgba(0,0,0,0.095); 
} 

.speech-bubble:before 
{ 
content: ""; 
border: solid 20px transparent; /* set all borders to 10 pixels width */ 
border-top: 0; /* we do not need the top border in this case */ 
border-bottom-color:rgba(250, 250, 250, 0.95); 
width: 0; 
height: 0; 
overflow: hidden; 
display: block; 
position: relative; 
top: -30px; /* border-width of the :after element + padding of the root element */ 
margin: auto; 
} 

.speech-bubble p { 
margin-top: -15px; 
font-size: 1.25em; 
} 

正如你看到的,我只能將邊框添加到內容框(.speech泡),但沒有標註(.speech泡:之前)我的邊框還需要TRANSPARANT。不知道這是否重要,但要牢記。有什麼建議?

+0

只使用SVG的背景,它的簡單。 – c69 2012-01-17 15:10:36

+0

@ c69剛開始玩弄SVG,但我很好奇,看看它是否可以用純CSS完成。乾杯... – Jedda 2012-01-17 16:56:24

+0

是的,它**可以做**,但它**不應該**。 – c69 2012-01-17 18:14:13

回答

13

你非常接近。您只需要同時使用:before:after來疊加另一個三角形邊框。

這裏有一個的jsfiddle:http://jsfiddle.net/rgthree/DWxf7/和所使用的CSS:

.speech-bubble { 
    position:relative; 
    width: 320px; 
    padding: 10px; 
    margin: 3em; 
    background-color:#FFF; 
    color: #666; 
    font: normal 12px "Segoe UI", Arial, Sans-serif; 
    -moz-border-radius: 10px; 
    -webkit-border-radius: 10px; 
    border-radius: 10px; 
    border: 10px solid rgba(0,0,0,0.095); 
} 
.speech-bubble p { 
    font-size: 1.25em; 
} 

.speech-bubble:before, 
.speech-bubble:after { 
    content: "\0020"; 
    display:block; 
    position:absolute; 
    top:-20px; /* Offset top the height of the pointer's border-width */ 
    left:20px; 
    z-index:2; 
    width: 0; 
    height: 0; 
    overflow:hidden; 
    border: solid 20px transparent; 
    border-top: 0; 
    border-bottom-color:#FFF; 
} 
.speech-bubble:before { 
    top:-30px; /* Offset of pointer border-width + bubble border-width */ 
    z-index:1; 
    border-bottom-color:rgba(0,0,0,0.095); 
} 
+0

好的工作夥伴!非常感謝... – Jedda 2012-01-17 16:54:54

+0

這在Firefox中呈現了一個醜陋的迷你邊框(在Windows中)。我的講話泡泡也有同樣的問題。 – 2013-07-04 17:40:49