我想为我的标题创建一个特殊的CSS形状。必须看起来像这个网站上的第一个讲话泡泡http://nicolasgallagher.com/pure-css-speech-bubbles/demo/,但箭头必须是半圈,而半圈必须始终位于中间。这是用于我的标题,所以即使形状是浏览器长度的100%,该圆也必须留在浏览器的中间,当我调整浏览器窗口的大小时也是如此。创建特殊的CSS形状
所以我的问题是,这是可能的,如果是这样,如何?
我想为我的标题创建一个特殊的CSS形状。必须看起来像这个网站上的第一个讲话泡泡http://nicolasgallagher.com/pure-css-speech-bubbles/demo/,但箭头必须是半圈,而半圈必须始终位于中间。这是用于我的标题,所以即使形状是浏览器长度的100%,该圆也必须留在浏览器的中间,当我调整浏览器窗口的大小时也是如此。创建特殊的CSS形状
所以我的问题是,这是可能的,如果是这样,如何?
使用border-radius: 50%
为半圈,然后将bottom
1/2圆的高度,left: 50%
以大部分为中心,然后margin-left
变为负1/2的宽度:
.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);
}
谢谢!但我需要在底部而不是三角形的一个半圈;) – Mario
我改变了我的答案,但你可能只是看了一个来源。我只是复制并粘贴了他们在您提供的页面中使用的内容。 – coopersita
谢谢!但这也是错误的,只有小箭头应该是半圈而不是整个泡泡!而不是箭头上的箭头,它必须是一个半圆。谢谢:) – Mario
这样的事情? http://jsfiddle.net/f5r9W/ –
首先我想说谢谢!但你忘了底部的半圈而不是箭头;) – Mario