Is there a method in which I can change the opacity of a border which is being set to inherit it's color from currentColor
? i.e. inherit currentColor
in #inner2
and set it's opacity to 0.25
.
Searching for a pure css
solution please.
For example, something which resembles the following:
#outer{
color: rgba(255,0,0,1);
}
.inner{
display: block;
width: 100%;
height: 10px;
margin-bottom: 5px;
border: 2px solid currentColor;
}
#inner2{
/* This is where I want to inherit current color */
/* ... but still set it to 0.25 opacity */
border-color: rgba(255,0,0,0.25);
}
<div id='outer'>
<div id='inner1' class='inner'></div>
<div id='inner2' class='inner'></div>
</div>
The value of the opacity property ranges between 0 and 1. The lower the value of the opacity property, the more transparent an element will appear. So, a value of 0 would make an element fully opaque or fully transparent, and a value of 1 would make an element appear as normal.
The term opaque originated from the Latin, meaning 'dark' meaning 'not transparent' and opaque substance does not let any light pass through at all. A paint that is opaque will give a solid colour. Blacks and whites are always opaque and any colour mixed with them will become more opaque.
The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.
The currentcolor keyword represents the value of an element's color property. This lets you use the color value on properties that do not receive it by default. If currentcolor is used as the value of the color property, it instead takes its value from the inherited value of the color property.
You are confusing currentColor
value with inherit
which is the default. you don't use currentColor
for border properties because that it the default value for the border. you only use it for background
.
#inner1
and #inner2
both inherit from the closest parent which has a color set to it (red) and the border is using that color by default.
style
attribute, external CSS or distant ancestor inheritance):#outer{ color:red; }
#inner1, #inner2{
padding: 2em;
margin-top: 1em;
}
#inner1{ border:5px solid; }
#inner2{ position:relative; }
#inner2::before{
content:'';
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
border:5px solid;
opacity:.5;
}
<div id='outer'>
<div id='inner1'>inner 1</div>
<div id='inner2'>inner 2</div>
</div>
You can use css-variables to achieve similar behaviour:
#outer{
--border-r: 255;
--border-g: 0;
--border-b: 0;
color: rgba(var(--border-r),var(--border-g),var(--border-b),1);
}
.inner{
display: block;
width: 100%;
height: 10px;
margin-bottom: 5px;
border: 2px solid;
}
#inner2{
color: rgba(var(--border-r),var(--border-g),var(--border-b),0.25);
}
<div id='outer'>
<div id='inner1' class='inner'></div>
<div id='inner2' class='inner'></div>
</div>
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