Well, I have this question and I see that someone already asked something similar but this I don't understand yet.
What I want to do is to set a opacity of 0.7 to an element but just to the content and not to the border, I want the border to stay full color. Some example code here:
input#element{
width: 382px;
height: 26px;
border: 2px solid #FFF;
border-radius: 3px;
opacity: 0.8;
}
The result is that my input element has the opacity but even the border, Can someone tell me how to set the opacity just in the content but not the border?
Thank's.
Don't think you can change the opacity of a border. however you could use css or jquery to set the opacity of a div then center another div inside that one.
Answer: Use the CSS RGBA colors There is no CSS property like "background-opacity" that you can use only for changing the opacity or transparency of an element's background without affecting its child elements.
Basically, you can't override the opacity of a child. The answer you might be looking for will depend on what it is you are actually trying to do. Paulie is right, opacity effects the entire element (including children) and can't be reversed by a child element.
Use rgba
syntax both for color and background and not use opacity for whole element
demo dabblet
input {
width: 382px;
height: 26px;
border: 2px solid #FFF;
border-radius: 3px;
background: rgba(255, 255, 255, .8);
color: rgba(0, 0, 0, .8);
}
I didn't see that the question was about an input element, but maybe my answer will help somebody else, so here we go.
As other posters have said, you can use the rgba
syntax to define your background color.
If there are nested elements in the one you want to change, you also can apply the opacity
to them with this css:
#element > * {
opacity:0.8;
}
Here is an example: JsFiddle
If you want a background-image for your element, I think the best way is still to wrap it in a container with the border.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With