How do I lower the opacity of text in div, like so:
To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).
Example explained First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.
Just use the rgba tag as your text color. You could use opacity , but that would affect the whole element, not just the text. Say you have a border, it would make that transparent as well.
One approach you can use is to put the background-image styles in a pseudo-element of the parent element. Since the pseudo-element is a sort of child of the parent, you can change the opacity of it without affecting the text content.
The CSS mix-blend-mode
property will give you the effect you're looking for (it can't be achieved using only opacity
). SVG is not required if you don't need Internet Explorer support. This solution is compatible with Chrome, Firefox, Safari, Opera, and others (see the compatibility table here).
Live Demo:
html, body {
margin: 0;
}
.mix {
position: absolute;
top: 0;
left: 0;
width: 140px;
height: 100px;
font-size: 80px;
color: white;
padding: 20px;
margin: 10px;
background-color: black;
mix-blend-mode: multiply;
opacity: 0.8;
}
<img src="http://i.imgur.com/5LGqY2p.jpg?1">
<div class="mix">
Text
</div>
Add opacity for parent div and the text inside the div will also carry the opacity. In your example the parent container has background and then then another container inside it with the text with different color, different from div background.
.main {
width: 350px;
height: 250px;
background-image: url(http://i.stack.imgur.com/GgQ5e.jpg);
}
.container {
opacity: 0.5;
background-color: black;
width: 300px;
height: 200px;
}
p {
font-size: 100px;
color: white;
opacity: .3;
}
<div class="main">
<div class="container">
<p>
TEXT
</p>
</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