有没有可能用css来实现这样的事情?我的意思是渐变边界与底部的伪元素(勾号)相结合.

I want to create something like this

当时我只做了一个渐变...

.white-grad {
  background: 
    linear-gradient(#ccc 0 0) padding-box, /*this is your grey background*/
    linear-gradient(to right, #9c20aa, #fb3570) border-box;
  color: #313149;
  padding: 10px;
  border: 5px solid transparent;
  border-radius: 15px;
  display: inline-block;
  margin: 75px 0;
}
<div class="white-grad"> Some text here</div>

<div class="white-grad"> Some long long long text here</div>

<div class="white-grad"> Some long long <br>long text here</div>

不幸的是,我不知道如何在突出的元素上做到这一点

推荐答案

你可以像下面这样做.我知道代码看起来很疯狂,但我很快就会有一篇关于它的详细文章.在此之前,您只需调整几个变量即可控制形状:

.tooltip {
  --r: 30px; /* border radius*/
  --b: 5px;  /* border length */
  --s: 30px; /* arrow size */
  --c: linear-gradient(60deg,#E84A5F,#355C7D);
  
  max-width: 410px;
  font-size: 20px;
  padding: calc(var(--r) + var(--b));
  position: relative;
  font-weight: bold;
  font-family: sans-serif;
}
.tooltip::before {
  content: "";
  position: absolute;
  inset: calc(-1*var(--s));
  border-radius: calc(var(--r) + var(--s));
  border: var(--s) solid #0000;
  padding: var(--b);
  background: var(--c) border-box;
  -webkit-mask: 
    conic-gradient(from -60deg at calc(80% - var(--b)) calc(100% - var(--b)/1.4), #000 60deg,#0000 0)
     50% calc(100% - var(--b)) /100% var(--s) no-repeat,
    linear-gradient(#000 0 0) content-box,
    conic-gradient(from -60deg at 80% 100%, #000 60deg,#0000 0)
     bottom/100% var(--s) no-repeat,
    linear-gradient(#000 0 0) padding-box;
  -webkit-mask-composite: xor;
          mask-composite: exclude;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-content: center;
  background: #b7e3f1;
}
<p class="tooltip">
  Sugar plum ice cream icing apple pie cotton candy gummi bears chupa chups cheesecake apple pie. Biscuit macaroon biscuit chocolate cake tiramisu. Wafer cupcake gummi bears tiramisu gingerbread icing lemon drops. Chocolate chocolate bar bonbon cake wafer oat cake. Lemon drops wafer cookie cake tiramisu
</p>

Html相关问答推荐

如何在css中将包含多行文本的多个p-tag放在一起(并排)?

为什么在CSS中字段是一个有效的 colored颜色 名称?

具有可展开行的棱角material 表(垫子表),折叠时行之间仍有间隙

我希望创建一个对角手风琴与不同的内容(文本和图像)在其正常状态和其他元素悬停

将导航项目底部边框与导航栏对齐

try 更新我的Node.js应用程序中的用户,但我收到错误.然而,当我使用postman 时,更新工作正常

如何在CSS中延迟触发2个转换?

Tailwind CSS 忽略我的元素的填充

添加带有悬停动画的喜欢图标

将箭头图标添加到工具提示包装器时遇到问题

为什么
标签在 Edge 和 Firefox 中的编号会有两种不同的结果?

用于表行组标题的正确 HTML 标记是什么?

如何并排放置
的定义列表,但如果
变长,
会向下移动?

弹出窗口溢出溢出:自动,我不明白为什么

如何使具有两个元素的 div 行在移动设备中响应

svg 内容超过元素

Bootstrap 5 网格问题,div 向下转义

所有幻灯片上的 Quarto RevealJS 标题

在 EJS 中将元素放置在彼此下方的列中

如何阻止网格项目拉伸?