我想为我的标题创建一个特殊的 CSS 形状。必须看起来像这个网站http://nicolasgallagher.com/pure-css-speech-bubbles/demo/上的第一个语音气泡,但是,箭头必须是半圈,半圈必须始终在中间。这是我的标题,所以即使形状是浏览器长度的 100%,圆圈也必须保持在浏览器的中间,当我调整浏览器窗口大小时也是如此。
所以我的问题是,这可能吗?如果可以,怎么做?
我想为我的标题创建一个特殊的 CSS 形状。必须看起来像这个网站http://nicolasgallagher.com/pure-css-speech-bubbles/demo/上的第一个语音气泡,但是,箭头必须是半圈,半圈必须始终在中间。这是我的标题,所以即使形状是浏览器长度的 100%,圆圈也必须保持在浏览器的中间,当我调整浏览器窗口大小时也是如此。
所以我的问题是,这可能吗?如果可以,怎么做?
Use border-radius: 50%
for the semi-circle, then set the bottom
to 1/2 of the circle's height, left: 50%
to center it mostly, and then margin-left
to negative 1/2 the width:
.half-circle {
background: orange;
padding: 1em;
position: relative;
text-align: center;
}
.half-circle::after {
background: orange;
border-radius: 50%;
bottom: -10px;
content: '';
display: block;
height: 20px;
left: 50%;
margin-left: -10px;
position: absolute;
width: 20px;
}
代码就在页面上。一种叫做椭圆形语音:
HTML:
<div class="oval-speech">test</div>
CSS
.oval-speech {
position:relative;
width:270px;
padding:50px 40px;
margin:1em auto 50px;
text-align:center;
color:#fff;
background:#5a8f00;
/* css3 */
background:-webkit-gradient(linear, 0 0, 0 100%, from(#b8db29), to(#5a8f00));
background:-moz-linear-gradient(#b8db29, #5a8f00);
background:-o-linear-gradient(#b8db29, #5a8f00);
background:linear-gradient(#b8db29, #5a8f00);
/*
NOTES:
-webkit-border-radius:220px 120px; // produces oval in safari 4 and chrome 4
-webkit-border-radius:220px / 120px; // produces oval in chrome 4 (again!) but not supported in safari 4
Not correct application of the current spec, therefore, using longhand to avoid future problems with webkit corrects this
-webkit-border-top-left-radius:220px 120px;
-webkit-border-top-right-radius:220px 120px;
-webkit-border-bottom-right-radius:220px 120px;
-webkit-border-bottom-left-radius:220px 120px;
-moz-border-radius:220px / 120px;
border-radius:220px / 120px;*/
}
.oval-speech p {font-size:1.25em;}
/* creates part of the curve */
.oval-speech:before {
content:"";
position:absolute;
z-index:-1;
bottom:-30px;
right:50%;
height:30px;
border-right:60px solid #5a8f00;
background:#5a8f00; /* need this for webkit - bug in handling of border-radius */
/* css3 */
-webkit-border-bottom-right-radius:80px 50px;
-moz-border-radius-bottomright:80px 50px;
border-bottom-right-radius:80px 50px;
/* using translate to avoid undesired appearance in CSS2.1-capabable but CSS3-incapable browsers */
-webkit-transform:translate(0, -2px);
-moz-transform:translate(0, -2px);
-ms-transform:translate(0, -2px);
-o-transform:translate(0, -2px);
transform:translate(0, -2px);
}
/* creates part of the curved pointy bit */
.oval-speech:after {
content:"";
position:absolute;
z-index:-1;
bottom:-30px;
right:50%;
width:60px;
height:30px;
background:#fff;
/* css3 */
-webkit-border-bottom-right-radius:40px 50px;
-moz-border-radius-bottomright:40px 50px;
border-bottom-right-radius:40px 50px;
/* using translate to avoid undesired appearance in CSS2.1-capabable but CSS3-incapable browsers */
-webkit-transform:translate(-30px, -2px);
-moz-transform:translate(-30px, -2px);
-ms-transform:translate(-30px, -2px);
-o-transform:translate(-30px, -2px);
transform:translate(-30px, -2px);
}