边框不透明?

发布于 2024-10-18 00:22:24 字数 203 浏览 8 评论 0原文

在 CSS 中如何制作不透明的边框? RGBA 颜色对我不起作用...

JSFiddle 是自我解释的。

边框中有暗角,并且在其后面可见该元素的背景,而不是其后面的其他元素。

谢谢。

How would you do borders with opacity in CSS? RGBA colors aren't working for me...

A JSFiddle is self explaining.

There are dark corners in the border, and the background of the element is visible behind it instead of the other elements behind it.

Thank You.

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

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

发布评论

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

评论(2

给我一枪 2024-10-25 00:22:24

可能有更好的方法,但这可行:

现场演示

基本上,只需使用包装器 div 并将 rgba 设置为背景即可。

HTML:

<div id="boxOuter">
    <div id="box">THANK YOU!</div>
</div>

CSS:

#box{
    background-color:#ccc;font-weight:bold;
    text-align:center;
    line-height:100px;
    height:100px;
    vertical-align:middle;
    font-size:20px;
}
#boxOuter {
    background: rgba(0,0,0,0.5); width:300px; padding: 10px;
    margin-left:25px;
}

阅读此答案的注释,了解如何使此方法 (rgba) 在旧版浏览器中工作。


一种不使用包装器的方法:

使用 outline而不是 border,它看起来可以接受:

outline: 10px solid rgba(0,0,0,0.5)

现场演示(这是您的确切代码,更改了一个单词)

(我在这里丝毫不考虑 IE)


查看这篇文章:

http://css-tricks.com/transparent-borders-with-background-clip/

There might be a better way, but this works:

Live Demo

Basically, just use a wrapper div with the rgba set as a background.

HTML:

<div id="boxOuter">
    <div id="box">THANK YOU!</div>
</div>

CSS:

#box{
    background-color:#ccc;font-weight:bold;
    text-align:center;
    line-height:100px;
    height:100px;
    vertical-align:middle;
    font-size:20px;
}
#boxOuter {
    background: rgba(0,0,0,0.5); width:300px; padding: 10px;
    margin-left:25px;
}

Read the comments to this answer to see how to make this method (rgba) work with older browsers.


A way to do it without using a wrapper:

Use outline instead of border, it looks acceptable:

outline: 10px solid rgba(0,0,0,0.5)

Live Demo (it's your exact code, with the one word changed)

(I'm not considering IE here in the slightest)


Check out this article:

http://css-tricks.com/transparent-borders-with-background-clip/

我爱人 2024-10-25 00:22:24

我认为第一个答案是最好的,尽管您现在可以在边框中使用图像,尝试使用具有透明度的 png 图像(通过 Photoshop)使用 border-image 属性,有很多方法可以使用它,您可能会找到您喜欢的另一种样式研究。

http://www.css3.info/preview/border-image/

I think the 1st answer is the best though you can use images in borders now, try using a png image with transparency (via photoshop) use the border-image property, there's so many ways to use it you may find another style you prefer in the research.

http://www.css3.info/preview/border-image/

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