将1px边框应用于CSS语音泡泡?

时间:2016-07-03 08:39:47

标签: css css-shapes

我们如何将1px边框应用于这些气泡?

similar SO post在这里不起作用,因为我们使用不同的方法来生成对话气泡

.chat-messages {
  width: calc(100%);
  padding-bottom: 5px;
  background-color: #f3f3f4;
}
.sb-time {
  font-size: 10pt;
  font-weight: 400;
  margin: 7px -5px 0px 10px;
  float: right;
}
.sb {
  font-size: 13pt;
  font-weight: 500;
  border-radius: 6px;
  display: block;
  padding: 10px 15px 5px 15px;
  position: relative;
  vertical-align: top;
  clear: both;
}
.sb::before {
  content: "\00a0";
  display: block;
  height: 15px;
  position: absolute;
  top: 10px;
  -moz-transform: rotate(30deg) skew(-35deg);
  -ms-transform: rotate(30deg) skew(-35deg);
  -o-transform: rotate(30deg) skew(-35deg);
  -webkit-transform: rotate(30deg) skew(-35deg);
  transform: rotate(30deg) skew(-35deg);
  width: 15px;
}
.sb-0 {
  background-color: #ffffff;
  float: left;
  margin: 5px 17% 5px 20px;
}
.sb-0::before {
  background-color: #ffffff;
  left: -8px;
}
.sb-1 {
background-color: #EEFFDD;
float: right;
margin: 5px 20px 5px 17%;
}

.sb-1::before {
    background-color: #EEFFDD;
    right: -8px;
}
<div class="chat-messages" style="max-height: 472px; overflow: hidden; width: auto; height: 472px;">
  <div class="sb sb-text sb-0">Hi
    <div class="sb-time">09:16</div>
  </div>
  <div class="sb sb-text sb-0">Fine. Thnks
    <div class="sb-time">09:19</div>
  </div>
  <div class="sb sb-text sb-1">What subject u are talking about ?
    <div class="sb-time">09:19</div>
  </div>
</div>

2 个答案:

答案 0 :(得分:2)

看看这个Jsfiddle

以下是我所做的更改:

{{1}}

修改

更新Jsfiddle以包含右侧的气泡。

答案 1 :(得分:1)

更新

不再需要transform 2D的前缀,请参阅CanIUse

.sb {
  ....
  border: 1px solid red;
}
.sb-0::before {
  ....
  border-left: 1px solid red;
  border-bottom: 1px solid red;
  transform: rotate(35deg) skew(-25deg) translate(-1px, 0);
  width: 16px;
  height: 14px;
}

.sb-1::before {
   ....
  border-right: 1px solid red;
  border-top: 1px solid red;
  transform: rotate(35deg) skew(-25deg) translate(1px, 0);
  width: 16px;
  height: 14px;
}

&#13;
&#13;
body {
  background: #000;
}
.chat-messages {
  width: calc(100%);
  padding-bottom: 5px;
  background-color: #666;
}
.sb-time {
  font-size: 10pt;
  font-weight: 400;
  margin: 7px -5px 0px 10px;
  float: right;
}
.sb {
  font-size: 13pt;
  font-weight: 500;
  border-radius: 6px;
  display: block;
  padding: 10px 15px 5px 15px;
  position: relative;
  vertical-align: top;
  clear: both;
  border: 1px solid red;
}
.sb-0:before {
  content: "\00a0";
  display: block;
  position: absolute;
  top: 10px;
  transform: rotate(25deg) skew(-35deg) translate(-1px, 0);
  width: 16px;
  height: 14px;
  border-left: 1px solid red;
  border-bottom: 1px solid red;
}
.sb-1:before {
  content: "\00a0";
  display: block;
  position: absolute;
  top: 10px;
  transform: rotate(25deg) skew(-35deg) translate(1px, 0);
  width: 16px;
  height: 14px;
  border-right: 1px solid red;
  border-top: 1px solid red;
}
.sb-0 {
  background-color: #ffffff;
  float: left;
  margin: 5px 17% 5px 20px;
}
.sb-0::before {
  background-color: #ffffff;
  left: -8px;
}
.sb-1 {
  background-color: #EEFFDD;
  float: right;
  margin: 5px 20px 5px 17%;
}
.sb-1::before {
  background-color: #EEFFDD;
  right: -8px;
}
&#13;
<div class="chat-messages" style="max-height: 472px; overflow: hidden; width: auto; height: 472px;">
  <div class="sb sb-text sb-0">Hi
    <div class="sb-time">09:16</div>
  </div>
  <div class="sb sb-text sb-0">Fine. Thnks
    <div class="sb-time">09:19</div>
  </div>
  <div class="sb sb-text sb-1">What subject u are talking about ?
    <div class="sb-time">09:19</div>
  </div>
</div>
&#13;
&#13;
&#13;