定义css箭头的度数

时间:2014-05-27 11:33:25

标签: css degrees

如何定义用css创建的箭头的程度

<div class="bubble"></div>

.bubble
{
   background: none repeat scroll 0 0 #FF7401;
   border: 3px solid silver;
   border-radius: 25px;
   bottom: 18px;
   float: right;
   height: 63px;
   margin-right: 10px;
   padding: 0;
   position: relative;
   width: 250px;
}

.bubble:after
{
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 29px 16px 0;
  border-color: #ff7401 transparent;
  display: block;
  width: 0;
  z-index: 1;
  bottom: -29px;
  left: 47px;
}

.bubble:before
{
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 31px 18px 0;
  border-color: silver transparent;
  display: block;
  width: 0;
  z-index: 0;
  bottom: -34px;
  left: 45px;
}

div.bubble p {
  color: #FFFFFF;
  font-size: 21px;
  font-weight: bold;
  margin-top: 10px;
  text-align: center;
}

http://jsfiddle.net/lgtsfiddler/GpUpZ/1/

我想要的是箭头的右边缘应该更长并且不等于左边缘。特别是,左边缘应垂直于文本气泡,右边缘应与其相遇。为了更好地实现可视化,以下是我尝试实现的示例:

enter image description here

2 个答案:

答案 0 :(得分:1)

像这样修改你的css

.bubble:before
{
content: '';
position: absolute;
border-style: solid;
border-width: 33px 18px 0;    // modify this line 
border-color: silver transparent;
/* display: block; */   // remove this line 
width: 0;
z-index: 0;
bottom: -27px;   // modify this line 
left: 50px;
-webkit-transform: rotate(-108deg) skew(11deg,-10deg);     // modify this line 
}

<强> Demo

答案 1 :(得分:0)

箭头的形状和方向由各个边框宽度和颜色决定

对单个值进行简单调整即可轻松进行实验。写出宽度和颜色的各个值通常也很有用,所以看看它是什么。

JSfiddle Demo

CSS

.bubble {
    background: none repeat scroll 0 0 #FF7401;
    border: 3px solid silver;
    border-radius: 25px;
    bottom: 18px;   
    height: 63px;
    margin: 50px;
    padding: 0;
    position: relative;
    width: 250px;
}

.bubble:after {
    content: '';
    position: absolute;
    border-style: solid;
    display: block;
    width: 0;
    z-index: 1;
    top:100%;
    left: 47px;
}

.bubble.one:after { /* straight left side */
    border-width: 29px 29px 29px 0;
    border-color: #ff7401 transparent transparent transparent; 
}


.bubble.two:after { /* straight right side */
    border-width: 29px 0px 29px 29px;
    border-color: #ff7401 transparent transparent transparent ; 
}