简体   繁体   English

您可以使边框透明吗?

[英]Can you make the border transparent?

In CSS is there a way to make the border transparent, but the box (inside) with the border the same? 在CSS中,有一种方法可以使边框透明,但是带有边框的框(内部)相同吗?

Please see this link: http://jsfiddle.net/xiiJaMiiE/LfWBn/14/ 请查看此链接: http : //jsfiddle.net/xiiJaMiiE/LfWBn/14/

#white_box {
position:absolute;
min-width:90%;
max-width:90%;
margin:0 auto;
height:92%;
top:0%;
left:5%;
right:5%;
background:white;
z-index:1;
width:80%;
border:5px #0F0 solid;
}

I would like to know if I can make the green border 0.6 opacity and keep the white inside normal. 我想知道是否可以使绿色边框0.6不透明并将白色保持在正常范围内。

Is that possible or would I have to make 2 divs on top each other? 那是可能的还是我必须彼此叠加2个div?

Thanks in advance! 提前致谢!

You could just use: border: 5px rgba(0, 255, 0, 0.6) solid; 您可以使用以下命令: border: 5px rgba(0, 255, 0, 0.6) solid;

UPDATED EXAMPLE 更新示例

#white_box {
    position: absolute;
    min-width: 90%;
    max-width: 90%;
    margin: 0 auto;
    height: 92%;
    top: 0%;
    left: 5%;
    right: 5%;
    background: white;
    z-index: 1;
    width: 80%;
    border: 5px rgba(0, 255, 0, 0.6) solid;
}

Alternatively, you could use outline too; 另外,您也可以使用outline both have different results. 两者都有不同的结果。

outline: 10px solid rgba(0, 255, 0, 0.6);

EXAMPLE HERE 这里的例子

Here if you want fully transparent than, you can use border-color: transparent - 在这里,如果您想要完全透明,则可以使用border-color: transparent

border: 5px solid transparent;

Try in fiddel 尝试菲德尔

Unfortunately, in Explorer, border-color: transparent is rendered as black.

Or if you you only want partially-transparent border, than you can use rgb with alpha transparency - 或者,如果您只希望部分透明的边框,则可以将rgb with alpha transparency使用-

border: 5px solid rgba(255, 255, 255, 0.5); // 0.5 means 50% of opacity

The alpha transparency variate between 0 (0% opacity = 100% transparent) and 1 (100 opacity = 0% transparent) Alpha透明度变量介于0(不透明度0%= 100%透明)和1(100不透明度= 0%透明)之间

Try in fiddle 尝试摆弄

this answer to add some info only. 此答案仅添加一些信息。 (3 ways : box-shadow:outset xxx ; or box-shadow: inset xxx; , or background-clip ) (3种方式: box-shadow:outset xxx ; box-shadow: inset xxx;background-clip

if you want opacity on borders and see through background of parent container, and not mixe with the background of the element itself, you can draw the background-color with inset shadow. 如果要在边界上不透明并可以透视父容器的背景 ,而不是与元素本身的背景混合,则可以绘制带有嵌入式阴影的background-color。 http://jsfiddle.net/Y78Ap/1/ (increased voluntary border-width and added a gradient to body to have it more 'telling') http://jsfiddle.net/Y78Ap/1/ (增加了自愿边框宽度,并为身体增加了渐变,使其更具“说服力”)

html,body {
 Background-color:rgba(255,165,0,0.5);
    background-image:linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(255,255,255,0.3));
 }

#white_box {
    position:absolute;
    min-width:90%;
    max-width:90%;
    margin:0 auto;
    height:92%;
    top:0%;
    left:5%;
    right:5%;
    box-shadow:inset 0 0 0 2000px white;
    z-index:1;
    width:80%;
    border: 15px rgba(0, 255, 0, 0.6) solid;
}

You can as well just draw borders with box-shadow: 0 0 5px rgba(0,255,0,0.6); 您也可以使用box-shadow: 0 0 5px rgba(0,255,0,0.6);绘制边框box-shadow: 0 0 5px rgba(0,255,0,0.6); instead border 代替边框

The easiest way suppose to be, nowdays, is background-clip : http://css-tricks.com/transparent-borders-with-background-clip/ 如今,最简单的方法应该是background-clip: http : //css-tricks.com/transparent-borders-with-background-clip/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM