【发布时间】:2019-05-26 02:11:38
【问题描述】:
我正在尝试在左侧和右侧创建一个带有箭头的对话气泡。像下面这样的
我使用下面的 CSS 来实现相同的效果:
.speech-wrapper{
padding: 30px 40px;
}
.chatbox {
padding: 5px;
margin-left: 5px;
margin-right: 5px;
margin-top:3px;
background: #c7edfc;
color: #000;
position: relative;
border-radius: 4px;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
}
.chatbox_other{
padding: 5px;
margin-left: 5px;
margin-right: 5px;
margin-top:3px;
background: #D3D3D3;
color: #000;
position: relative;
border-radius: 4px;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
}
.name_other{
font-weight: 600;
position: absolute;
font-size: 12px;
margin: 0 0 4px;
color: #3498db;
bottom: 8px;
right: 10px;
}
.timestamp_other{
font-size: 11px;
position: absolute;
text-align: left;
bottom: 0px;
left: 10px;
text-transform: uppercase; color: #999
}
.timestamp{
font-size: 11px;
position: absolute;
bottom: 8px;
right: 10px;
text-transform: uppercase; color: #999
}
/* speech bubble 13 */
.name{
font-weight: 600;
font-size: 12px;
margin: 0 0 4px;
color: #3498db;
}
.bubble-arrow {
position: absolute;
width: 0;
bottom:42px;
left: -16px;
height: 0;
&.alt{
right: -2px;
bottom: 40px;
left: auto;
}
}
.bubble-arrow:after {
content: "";
position: absolute;
border: 0 solid transparent;
border-top: 9px solid #c7edfc;
border-radius: 0 20px 0;
width: 15px;
height: 30px;
transform: rotate(145deg);
}
.bubble-arrow.alt:after {
transform: rotate(45deg) scaleY(-1);
}
但对我来说,箭头总是丢失,它总是带有一个盒子。
我是 HTML 和 CSS 的初学者,如有任何帮助,我们将不胜感激。 我在绘制矩形时做错了吗?
编辑:
我可以在 chrome 和所有最近的浏览器上看到聊天气泡,但是当我尝试使用非常旧的浏览器时,以下语句无法正确解码。所以聊天三角形不在合适的位置。
transform: rotate(145deg);
}
.bubble-arrow.alt:after {
transform: rotate(45deg) scaleY(-1);
}
HTML 代码:
<div class="speech-wrapper"><div class="chatbox"><div class="txt"><p class="name">TestUser1</p>Hi<span class="timestamp">10:20 pm</span></div><div class="bubble-arrow alt"></div></div>
除了transform
,我还有什么可以使用的吗?【问题讨论】:
-
你也可以分享你的HTML代码吗?
-
@TemaniAfif 谢谢,但我可以使用除了转换之外的任何东西,因为转换与旧的浏览器有一些问题
-
即使使用旧浏览器也支持转换:caniuse.com/#feat=transforms2d