纯 CSS 三角形,带有半透明边框。可能的?

发布于 2024-12-26 22:42:15 字数 785 浏览 2 评论 0原文

是否可以仅使用 css 绘制一个周围有半透明边框的箭头? 在此处输入图像描述

这是我迄今为止所做的努力: http://jsfiddle.net/calebo/fBW4u/

CSS:

.ui-overlay {
  padding-bottom: 10px;   
  position: relative;
}
.ui-overlay-content { 
  background: #999;
  color: #000;
  padding: 8px;
  border-radius: 4px; 
  border: 5px solid rgba(0, 0, 0, 0.2); 
  background-clip: padding-box; 
  height: 100px;
  width: 200px;
}
.arrow {
  border-color: #999 transparent transparent; 
  border-style: solid; 
  border-width: 10px 10px 0; 
  bottom: 5px; 
  left: 15px; 
  width: 0;
  height: 0;
  position: absolute;
  overflow: hidden; 
}

Is it possible to draw an arrow that has semi-transparent border around it just using css?
enter image description here

Heres a fiddle of my effort so far:
http://jsfiddle.net/calebo/fBW4u/

CSS:

.ui-overlay {
  padding-bottom: 10px;   
  position: relative;
}
.ui-overlay-content { 
  background: #999;
  color: #000;
  padding: 8px;
  border-radius: 4px; 
  border: 5px solid rgba(0, 0, 0, 0.2); 
  background-clip: padding-box; 
  height: 100px;
  width: 200px;
}
.arrow {
  border-color: #999 transparent transparent; 
  border-style: solid; 
  border-width: 10px 10px 0; 
  bottom: 5px; 
  left: 15px; 
  width: 0;
  height: 0;
  position: absolute;
  overflow: hidden; 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许一世地老天荒 2025-01-02 22:42:15

这仍然需要一些工作,但总体思路如下:

使用伪元素,将其旋转 45 度并对其应用样式:

.arrow {
    bottom: -25px; 
    left: 30px; 
    width: 40px;
    height: 40px;
    position: absolute;
    overflow: hidden;
}
.arrow:after {
    content: ' ';
    display: block;
    background: red;
    width: 20px;
    height: 20px;
    transform: rotate(45deg);
    position: absolute;
    top: -19px;
    left: 3px;
    background: #999;
    border: 5px solid rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
}

这是小提琴: http ://jsfiddle.net/yZ3vB/


这样做的问题是边框重叠,导致边缘变暗。

不过,这可能可以通过添加另一个元素来解决。

更新:是的!给你: http://jsfiddle.net/sJFTT/


更新 2: 你甚至不知道需要那个额外的元素。您可以使用主框中的伪元素:

.ui-overlay-content:after {
    content: ' ';
    border-width: 13px;
    border-color: #999 transparent transparent;
    border-style: solid;
    bottom: -10px;
    left: 30px;
    width: 0;
    height: 0;
    position: absolute;
}

这是小提琴: http://jsfiddle.net/6v9nV/


更新3:实际上,您可以通过使用两个伪元素 - before仅使用单个元素来完成所有这些操作,并且无需进行任何转换之后

.speech-bubble {
    background: #999;
    background: linear-gradient(top, #444 0%,#999 100%);
    background-clip: padding-box;
    border: 5px solid rgba(0, 0, 0, 0.2);
    padding: 20px;
    width: 200px;
    height: 100px;
    position: relative;
}
.speech-bubble:before{
    content: ' ';
    border-color: rgba(0, 0, 0, 0.2) transparent transparent;
    border-style: solid;
    border-width: 17px;
    position: absolute;
    bottom: -39px;
    left: 16px;
}
.speech-bubble:after{
    content: ' ';
    border-color: #999 transparent transparent;
    border-style: solid;
    border-width: 13px;
    position: absolute;
    bottom: -26px;
    left: 20px;
}

这是fiddle: http://jsfiddle.net/95vvr/


PS 不要忘记生产中的供应商前缀!

This still needs some work, but here's the general idea:

Use a pseudo-element, rotate it 45deg and apply the styling to that:

.arrow {
    bottom: -25px; 
    left: 30px; 
    width: 40px;
    height: 40px;
    position: absolute;
    overflow: hidden;
}
.arrow:after {
    content: ' ';
    display: block;
    background: red;
    width: 20px;
    height: 20px;
    transform: rotate(45deg);
    position: absolute;
    top: -19px;
    left: 3px;
    background: #999;
    border: 5px solid rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
}

Here's the fiddle: http://jsfiddle.net/yZ3vB/


The problem with this is that the borders overlap, making it darker by the edges.

This could probably be remedied by adding another element though.

Update: Yes! Here you go: http://jsfiddle.net/sJFTT/


Update 2: You don't even need that additional element. You can use the pseudo element from the main box:

.ui-overlay-content:after {
    content: ' ';
    border-width: 13px;
    border-color: #999 transparent transparent;
    border-style: solid;
    bottom: -10px;
    left: 30px;
    width: 0;
    height: 0;
    position: absolute;
}

Here's the fiddle: http://jsfiddle.net/6v9nV/


Update 3: Actually, you can do all this with just a single element and no transform, by using both pseudo-elements - the before and the after:

.speech-bubble {
    background: #999;
    background: linear-gradient(top, #444 0%,#999 100%);
    background-clip: padding-box;
    border: 5px solid rgba(0, 0, 0, 0.2);
    padding: 20px;
    width: 200px;
    height: 100px;
    position: relative;
}
.speech-bubble:before{
    content: ' ';
    border-color: rgba(0, 0, 0, 0.2) transparent transparent;
    border-style: solid;
    border-width: 17px;
    position: absolute;
    bottom: -39px;
    left: 16px;
}
.speech-bubble:after{
    content: ' ';
    border-color: #999 transparent transparent;
    border-style: solid;
    border-width: 13px;
    position: absolute;
    bottom: -26px;
    left: 20px;
}

Here's the fiddle: http://jsfiddle.net/95vvr/


P.S. Don't forget the vendor prefixes in production!

柠檬色的秋千 2025-01-02 22:42:15

您需要对图像进行凹口并将该图像绝对放置在右下角。在此处输入图像描述

You need notch image and place that image absolutely at bottom right corner.enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文