html - 在css中创建具有特定形状的对话气泡时,在后面设置透明度
问题描述
我正在尝试用 css 实现上述语音气泡形状。正文背景为渐变色时如何设置透明度?
after的背景设置为透明时,指定为before的背景。如果是这样,我应该改变之前和之前的顺序来实施它吗?帮助!
.body {
padding: 30px 0 20px 0 !important;
background: linear-gradient(to right, #E51D38,#C90E97);
}
.speech-bubble {
text-align: center;
width: 50%;
position: relative;
padding: 50px;
margin: 1em auto 50px;
text-align: center;
color: black;
background: white;
border-radius: 30px;
}
.speech-bubble:before {
content: "";
position: absolute;
z-index: 3;
left: -22px;
top: 0;
width: 40px;
border-bottom: 35px solid white;
border-top-right-radius: 25px;
}
.speech-bubble:after {
content: "";
position: absolute;
z-index:3;
left: -28px;
top: -3px;
height: 38px;
width: 28px;
background: lightgray;
border-top-right-radius: 20px;
}
<div class="speech-bubble">Hello, world.</div>
解决方案
使用渐变着色,然后简单地控制元素的宽度/高度:
body {
padding: 30px 0 20px 0 !important;
background: linear-gradient(to right, #E51D38, #C90E97);
}
.speech-bubble {
text-align: center;
width: 50%;
position: relative;
padding: 50px;
margin: 1em auto 50px;
text-align: center;
color: black;
background: white;
border-radius: 30px;
}
.speech-bubble:before {
content: "";
position: absolute;
width:50px;
height:40px;
top:0;
left:-25px;
background: radial-gradient(50% 100% at bottom left,#0000 98%,white);
border-top-right-radius: 100%;
}
<div class="speech-bubble">Hello, world.</div>
推荐阅读
- c++ - 如何检查里面有多少个 int 数字并将其重置为零?
- java - 如何在地图上创建线程
一直有效并从地图中删除密钥? - reactjs - 在条件下从组件中删除属性,reactjs
- vba - 扫描 VBA 中的列表并将每个命中添加到同一单元格中
- c# - 从数据库中删除所有数据后获取 DbUpdateConcurrencyException
- python - 如何重新排列一些复杂的 Excel 数据集?
- python - 防止滚动文本占用整个父窗口,从而禁止其他小部件出现
- mongodb - 如何在 Kafka 中运行 mongodb 连接器?
- python - pygatt 通知超时:无
- python - 带有莳萝的 Pathos p_tqdm 多进程错误