AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

CSS background image opacity without affecting child elements


<< Previous Page
HTML comment
Next Page >>
div class container

CSS Tutorial » CSS background image opacity without affecting child elements

Study in this chapter:
1. - explanations - How can you change the opacity of a background image in CSS?
2. - Transparent Hover Effect
3. - Transparency using RGBA

To improve the design of a web page, designers of web pages use the opacity property to specify the opacity / transparency of an itemwhen they need it.

We can add opacity property to an backgroundimage or color as:
Internal Style - by using a <style> element in the <head> section
External Style - by using an external CSS file as style.css
Inline - by using the style attribute in HTML elements

Syntax:

Syntax: Internal & External CSS.
selector { opacity: value; };

Inline CSS.
<tag style="opacity: value;;">Yor text here</tag>
Note: use external CSS instead.

Example:background image opacity without affecting text, color gradient

opacity 0.2
opacity 0.5
opacity 1 (default)
Note: "background-opacity" - CSS element's background without affecting the child elements it isn't

 

Browser Support

Element chrome browser
 Chrome
ie browser
 IE
firefox browser
 Firefox
opera browser
 Opera
safari browser
 Safari
opacity property Yes Yes Yes Yes Yes

 

Change background-image opacity in CSS without affecting text

How can you change the opacity of a background image in CSS? - simple, we use opacity: value;

The background-opacity CSS property you want to use only to change the opacity or transparency of a CSS element's background without affecting the child item, there is no.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
.main-box{
width:99%;
height:200px;
background:#E9E9E9;
}
.box1{
background-image: url('https://www.agernic.com/uploads/image-opacity.jpg');
opacity: 0.2;
margin: 10px;
padding: 2px;
font-size:30px;
height: 160px;
width:27%;
float: left;
}
.box2{
background-image: url('https://www.agernic.com/uploads/image-opacity.jpg');
opacity: 0.5;
margin: 10px;
padding: 2px;
font-size: 30px;
height:160px;
width:27%;
float: left;

}
.box3{
background-image: url('https://www.agernic.com/uploads/image-opacity.jpg');
margin: 10px;
padding: 2px;
font-size: 30px;
height: 160px;
width:27%;
float: left;
}
</style>
</head>

<body>
<div class="main-box">
<div class="box1">opacity 0.2</div>
<div class="box2">opacity 0.5</div>
<div class="box3">opacity 1 (default)</div>
</div>
</body>
</html>

Related subjects:
Background image size to fit screen Images size Rounded corners image

 

Transparent Hover Effect

Image Transparency

The opacity property is often used in conjunction with the :hover selector to change the opacity on mouseover.

<!DOCTYPE html>
<html>
<head>
<style>
img {
opacity: 0.5;
}

img:hover {
opacity: 1.0;
}
</style>
</head>
<body>

<h1>Image Transparency</h1>
<p>The opacity property is often used in conjunction with the :hover selector to change the opacity on mouseover.</p>
<img src="https://www.agernic.com/uploads/image-opacity.jpg" alt="mountin" width="30%">
<img src="https://www.agernic.com/uploads/landscape_beach.jpg" alt="landscape beach" width="30%">
<img src="https://www.agernic.com/uploads/espana-imagenes.jpg" alt="Italy" width="30%">

</body>
</html>

Tags: opacity without affecting text, only, gradient, black, color, darker, rgba, How to make background image lighter? Background image opacity without affecting child elements, text or content.

 

Transparency using RGBA

If you don't want to apply opacity to the items as in the example shown above, you can use RGBA color values. The next example sets the opacity/transparency for the background color.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
div {
background: rgb(0, 0, 255);
padding: 10px;
}

div.fi {
background: rgba(0, 0, 255, 0.2);
}

div.se {
background: rgba(0, 0, 255, 0.4);
}

div.th {
background: rgba(0, 0, 255, 0.6);
}
</style>
</head>
<body>

<p>Transparent Box With RGBA color values:</p>
<div class="fi"><p>20% opacity</p></div>
<div class="se"><p>40% opacity</p></div>
<div class="th">
<p>60% opacity</p></div>
<div><p>default</p></div>

</body>
</html>

The value of a color in the RGBA code is specified with: rgba (red, green, blue, beta). The beta parameter is a number between 0.0 (it is completely transparent) and 1.0 (it is completely opaque).

Summary of description

 

<< Previous Page
HTML Button Style
Next Page >>
HTML Button Action

 



only, gradient, black, color, darker, rgba, How to make background image lighter?
CSS background image opacity without affecting child elements, text, or content - css tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS Scrollbar Horizontal
CSS Scrollbar in Div
CSS Scrollbar Firefox
CSS Style Scrollbar
CSS Style Text
CSS background color
CSS Div Id Class
CSS Text Wrap
CSS text-align
CSS Text Decoration
CSS Text Shadow
CSS Text Color
CSS Text Bold
CSS Text Size
CSS background image full
CSS background opacity
CSS border radius
CSS rounded corners
CSS font color
CSS Class & ID
CSS align image center
CSS align content
CSS link color
CSS Text Style
CSS Text Font Size
CSS max width &height
CSS width and height
CSS Margin
CSS Padding
CSS Border Style
CSS background
CSS in HTML
Basic Syntax of CSS
CSS Introduction
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.