简体   繁体   English

CSS中的半透明边框-Tumblr主题编码

[英]A Semi-Transparent Border in CSS - Tumblr Theme Coding

I'm trying to make the sidebar for my theme match the main content, in that there's a solid background with a transparent border. 我试图使主题的侧边栏与主要内容匹配,因为有一个带有透明边框的纯色背景。 I can make them work individually, but when I try to do both it doesn't work right. 我可以使它们单独工作,但是当我尝试两者都不能正常工作时。 Here's the snipet of code that's been causing the problem: 这是导致问题的代码片段:

#sidebar {
     width: 300px; 
    background-color: #A3A3CC;
    /*border-style: solid; border-width: 15px; border-color: rgba(255, 255, 255, 0.4);*/
    position: fixed;
    left: 60px;
    top: 90px; 
    height: 490px;
    margin-left: 30px;
    }

I am aware that the border code is noted out, and that's because the border code and the background color code work fine individually, but when I have both at the same time, I get this . 我知道边界代码已被标注出来,这是因为边界代码和背景颜色代码可以分别正常工作,但是当我同时使用边界代码和背景颜色代码时,我会得到这个

Does anyone know how I can fix this? 有谁知道我该如何解决? I just want to have a semi-transparent background under a solid one to make a nice border effect. 我只想在坚实的背景下设置一个半透明的背景,以产生漂亮的边框效果。

You can use a box-shadow instead of a border. 您可以使用盒子阴影而不是边框​​。

JSfiddle Demo JSfiddle演示

CSS 的CSS

#sidebar {
    width: 300px;
    background-color: #A3A3CC;
    box-shadow: 0 0 0 15px rgba(255, 255, 255, 0.4);
    position: fixed;
    left: 60px;
    top: 90px;
    height: 490px;
    margin-left: 30px;
}

Since the border is rendered on top of the background of the div, they are stacking and not giving you what you want. 由于边框是在div的背景上渲染的,因此边框在堆叠,没有给您想要的东西。 You could wrap another div around it, and use that as your border: 您可以在其周围包裹另一个div,并将其用作边界:

JSFiddle JSFiddle

HTML 的HTML

<div id="outer"><div id="sidebar"> </div></div>

CSS 的CSS

#sidebar {
    background-color: #A3A3CC;
    width: 300px; 
    height: 490px;
}
#outer{
    padding:15px;
    background: rgba(255, 255, 255, 0.4);
    position: fixed;
    left: 60px;
    top: 90px; 
}

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

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