Is there a straight forward CSS way to make the border of an element semi-transparent with something like :
border-opacity:0.7;
?
If not, does anyone have an idea how I could do so without using images?
Is there a straight forward CSS way to make the border of an element semi-transparent with something like :
border-opacity:0.7;
?
If not, does anyone have an idea how I could do so without using images?
As others have mentioned: CSS-3 says that you can use the
rgba(...)
syntax to specify a border color with an opacity (alpha) value.here's a quick example if you'd like to check it.
It works in Safari and Chrome (probably works in all webkit browsers).
It works in Firefox
I doubt that it works at all in IE, but I suspect that there is some filter or behavior that will make it work.
There's also this stackoverflow post, which suggests some other issues--namely, that the border renders on-top-of any background color (or background image) that you've specified; thus limiting the usefulness of border alpha in many cases.
It's easy, use a solid shadow with 0 offset:
Also, if you set a border-radius to the element, it gives you pretty rounded borders
jsFiddle Demo
try this:
And here comes our magical CSS..
Check out the Demo here.
If you check your CSS coding with W3C validator, you will see if your CSS code is acceptable, even if it worked in the major browsers.
Creating a transparent border via CSS, as written above,
is not accepted by W3C standards, not even for CSS3. I used the direct input validator with the following CSS code,
The results were,
Unfortunate that the alpha value (the letter "a" at the end of "rgb") is not accepted by W3C as part of the border color values as yet. I do wonder why it is not standardized, since it works in all browsers. The only hitch is whether you want to stick to W3C standards or step aside from it to create something in CSS.
To use W3C online CSS validator / Direct Input.
Always a good idea to use a validator to check your work, it really helps finding small or even large errors in coding when your going cross-eyed after hours of coding work.
*Not as far as i know there isn't what i do normally in this kind of circumstances is create a block beneath with a bigger size((bordersize*2)+originalsize) and make it transparent using
here is an example
Update:
This answer is outdated, since after all this question is more than 8 years old. Today all up to date browsers support rgba, box shadows and so on. But this is a decent example how it was 8+ years ago.
Unfortunately the
opacity
element makes the whole element (including any text) semi-transparent. The best way to make the border semi-transparent is with the rgba color format. For example, this would give a red border with 50% opacity:The problem with this approach is that some browsers do not understand the
rgba
format and will not display any border at all if this is the entire declaration. The solution is to provide two border declarations. The first with a fake opacity, and the second with the actual. If a browser is capable, it will use the second, if not, it will use the first.The first border declaration will be the equivalent color to a 50% opaque red border over a white background (although any graphics under the border will not bleed through).
UPDATE: I've added "background-clip: padding-box;" to this answer (per SooDesuNe's suggestion in the comments) to ensure the border remains transparent even if a solid background color is applied.