[英]Make element transparent except border?
Is it possible to make an entire element invisible except for its border or outline using pure CSS?是否可以使用纯 CSS 使整个元素不可见,除了其边框或轮廓? By "invisible", I mean entirely transparent (ie visibility: hidden;
or opacity: 0;
) with a visible surrounding border.通过“不可见”,我的意思是完全透明(即可见visibility: hidden;
或opacity: 0;
)具有可见的周围边框。 All text, children, background, et al., would be hidden.所有文本、子项、背景等都将被隐藏。
I know this could be accomplished by creating a parent div
around the invisible element, but I am curious as to whether or not it would be possible to achieve the same effect without changing the HTML.我知道这可以通过在不可见元素周围创建父div
来完成,但我很好奇是否可以在不更改 HTML 的情况下实现相同的效果。
Can this be done?这能做到吗?
Hmm, I think it is:嗯,我觉得是:
HTML HTML
<div id="element">
...
</div>
CSS CSS
#element {
width: 100px;
height: 100px;
border: 1px solid #000;
}
#element * {
opacity: 0;
}
You can use RGBA as color to achieve that, have a look at this:您可以使用 RGBA 作为颜色来实现这一点,看看这个:
THE STYLE:样式:
body {
background: red;
}
div {
width: 100px;
height: 60px;
border: 4px solid black;
background: rgba(255, 255, 255, 0.2);
}
div * {
opacity: 0;
}
THE MARKUP:标记:
<div>
<span>Guten Morgen</span>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.