Css3气泡,1px的三角形

时间:2014-01-28 17:12:26

标签: css3 pseudo-element

我正在使用CSS3而且我正在做一些泡泡。

我有一个问题,我需要一个带1px边框的三角形,但是我的代码我有一个胖三角..

这里是我的小提琴:FIDDLE

代码:

<p class="triangle-border right">hi hi</p>

.triangle-border {
  position:relative;
  padding:15px;
  color:#333;
  background:#fff;
  margin-left:100px;
  margin-right:100px;
}

.triangle-border.right {
  margin-right:50px;
  border:3px solid #EEEEEF;
}

.triangle-border:before {
  content:"";
  position:absolute;
  bottom:-20px; /* value = - border-top-width - border-bottom-width */
  left:40px; /* controls horizontal position */
  border-width:20px 20px 0;
  border-style:solid;
  border-color:#EEEEEF transparent;
  /* reduce the damage in FF3.0 */
  display:block;
  width:0;
}

/* creates the smaller  triangle */
.triangle-border:after {
  content:"";
  position:absolute;
  bottom:-13px; /* value = - border-top-width - border-bottom-width */
  left:47px; /* value = (:before left) + (:before border-left) - (:after border-left) */
  border-width:13px 13px 0;
  border-style:solid;
  border-color:#fff transparent;
  /* reduce the damage in FF3.0 */
  display:block;
  width:0;
}

/* creates the larger triangle */
.triangle-border.right:before {
  top:10px; /* controls vertical position */
  bottom:auto;
  left:auto;
  right:-30px; /* value = - border-left-width - border-right-width */
  border-width:15px 0 15px 30px;
  border-color:transparent #EEEEEF;
}

/* creates the smaller  triangle */
.triangle-border.right:after {
  top:16px; /* value = (:before top) + (:before border-top) - (:after border-top) */
  bottom:auto;
  left:auto;
  right:-21px; /* value = - border-left-width - border-right-width */
  border-width:9px 0 9px 21px;
  border-color:transparent #fff;
}

你看到右边的三角形了吗?我需要一个只有1px边框的三角形..谢谢!

2 个答案:

答案 0 :(得分:2)

How's this?

/* creates the larger triangle */
.triangle-border.right:before {
  top:14px; /* controls vertical position */
  bottom:auto;
  left:auto;
  right:-22px; /* value = - border-left-width - border-right-width */
  border-width:11px 0 11px 22px;
  border-color:transparent #EEEEEF;
}

我刚玩过边框宽度和左/右定位

答案 1 :(得分:0)

你可以看到它在这里工作:FIDDLE

.triangle-border.right:before {
    border-color: rgba(0, 0, 0, 0) #EEEEEF;
    border-width: 15px 0 13px 27px;
    bottom: auto;
    left: auto;
    right: -28px;
    top: 11px;
    width: 0;
}
.triangle-border:before {      
    border-color: #EEEEEF rgba(0, 0, 0, 0);
    border-style: solid;       
    content: "";       
    height: 0;      
    position: absolute;

}
.triangle-border.right:after {
    border-color: rgba(0, 0, 0, 0) #FFFFFF;
    border-width: 10px 0 11px 23px;
    bottom: auto;
    left: auto;
    right: -23px;
    top: 15px;
}
.triangle-border:after {
    border-color: #FFFFFF rgba(0, 0, 0, 0);
    border-style: solid;       
    content: "";
    display: block;      
    position: absolute;
    width: 0;
}
.triangle-border.right {
    border: 3px solid #EEEEEF;
    margin-right: 50px;
}
.triangle-border {
    background: none repeat scroll 0 0 #FFFFFF;
    color: #333333;
    margin-left: 100px;
    padding: 15px;
    position: relative;
}

.triangle-border.right:before { border-color: rgba(0, 0, 0, 0) #EEEEEF; border-width: 15px 0 13px 27px; bottom: auto; left: auto; right: -28px; top: 11px; width: 0; } .triangle-border:before { border-color: #EEEEEF rgba(0, 0, 0, 0); border-style: solid; content: ""; height: 0; position: absolute; } .triangle-border.right:after { border-color: rgba(0, 0, 0, 0) #FFFFFF; border-width: 10px 0 11px 23px; bottom: auto; left: auto; right: -23px; top: 15px; } .triangle-border:after { border-color: #FFFFFF rgba(0, 0, 0, 0); border-style: solid; content: ""; display: block; position: absolute; width: 0; } .triangle-border.right { border: 3px solid #EEEEEF; margin-right: 50px; } .triangle-border { background: none repeat scroll 0 0 #FFFFFF; color: #333333; margin-left: 100px; padding: 15px; position: relative; }

只是让它适合您当前的边框宽度,但您可以使用

  

.triangle-border.right:在

之前

用任何边框大小调整它的类。

  

单个三角形的代码太多了,您可以参考以下链接:Tutorial On Speech Bub