Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make text in div lower opacity in HTML [closed]

How do I lower the opacity of text in div, like so:

like image 614
Jonathan Ivgi Avatar asked Apr 14 '16 22:04

Jonathan Ivgi


People also ask

How do I reduce text opacity in HTML?

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).

How do I make part of a div transparent?

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.

How do I make text translucent in HTML?

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.

How can I change background opacity without affecting text?

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.


2 Answers

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>
like image 149
Maximillian Laumeister Avatar answered Oct 06 '22 19:10

Maximillian Laumeister


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>
like image 20
Maihan Nijat Avatar answered Oct 06 '22 17:10

Maihan Nijat