WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Image Opacity / Transparency


Creating transparent images with CSS is easy.

The CSS opacity property is a part of the CSS3 recommendation.


Example 1 - Creating a Transparent Image

The CSS3 property for straightforwardness is opacity.

First we will tell you the best way to make a straightforward picture with CSS.

Regular image:

klematis

The same picture with transparency:

honeyeater-winged creature

Look at the accompanying CSS:

Example

img {
    murkiness: 0.4;
    channel: alpha(opacity=40);/* For IE8 and prior */
}
Try it yourself »

The opacity property can take an incentive from 0.0 - 1.0. The lower esteem, the more transparent.

IE8 and prior use filter:alpha(opacity=x). The x can take an incentive from 0 - 100. A lower esteem makes the component more transparent.


Example 2 - Image Transparency - Hover Effect

Mouse over the images:

klematis klematis

The CSS looks like this:

Example

img {
    darkness: 0.4;
    channel: alpha(opacity=40);/* For IE8 and prior */
}

img:hover {
    darkness: 1.0;
    channel: alpha(opacity=100);/* For IE8 and prior */
}
Try it yourself »

The first CSS square is like the code in Example 1. Moreover, we have included what ought to happen when a client drifts more than one of the pictures. For this situation we need the picture to NOT be straightforward when the client drifts over it. The CSS for this is opacity:1;.

When the mouse pointer moves from the picture, the picture will be straightforward again.


Example 3 - Text in Transparent Box

This is some content that is set in the straightforward box.


The source code looks like this:

Example

<html>
<head>
<style>
div.background {
    foundation: url(wild-flowers.jpeg) repeat;
    outskirt: 2px strong black;
}

div.transbox {
    edge: 30px;
    foundation shading: #ffffff;
    outskirt: 1px strong black;
    obscurity: 0.6;
    channel: alpha(opacity=60); /* For IE8 and prior */
}

div.transbox p {
    edge: 5%;
    text style weight: bold;
    shading: #000000;
}

</style>
</head>
<body>

<div class="background">
  <div class="transbox">
    <p>This is some content that is set in the straightforward box.</p>
  </div>
</div>

</body>
</html>
Try it yourself »