我想为我的标题创建一个特殊的CSS Shape。必须看起来像这个网站http://nicolasgallagher.com/pure-css-speech-bubbles/demo/的第一个讲话泡泡,但是,箭头必须是半圆,半圆必须始终在中间。这是我的标题,所以即使形状是浏览器长度的100%,圆圈也必须保持在浏览器的中间,当我调整浏览器窗口的大小时。
所以我的问题是,这是可能的,如果是的话,怎么样?
答案 0 :(得分:1)
将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;
}
答案 1 :(得分:0)
代码就在页面上。一个叫椭圆语的人:
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);
}