The opacity property sets the opacity level for an element, opacity allows to change the transparency of an element.

- Syntax:
opacity: X;
- X - represents a value between 0 (completely transparent) and 1.0 (no transparency).

CSS opacity examples

1) Example, a <div> with a css transparency of 40%:
<style>
#dv {
 background-color:#babafe;
 width:200px;
 height:100px;
 opacity:0.4;
}
</style>

<h4>Example opacity 40%</h4>

<div id='dv'>Some content ...</div>
2) Example, sets opacity 50% to an image:
<style>
#im {
 opacity:0.5;
}
</style>

<h4>Example opacity 50% on image</h4>

<img src='css/html_course.jpg' alt='HTML and CSS Course' width='155' height='160' id='im' />
3) Example, effect image transparency 50%, to 100% on the hover state:
<style>
#im2 {
 opacity:0.5;
}
#im2:hover {
 opacity:1;
}
</style>

<h4>Example changing transparency on hover</h4>
<p>Place the mouse over the image below.</p>

<img src='css/html_course.jpg' alt='HTML and CSS Course' width='155' height='160' id='im2' />
4) DIV content that is covered with a transparent box on mouseover (the transparent box [a <div>] must be empty and set with   position:absolute;):
<style>
#trans {
 display:none;
 position:absolute;
 top:2%;
 left:2%;
 width:96%;
 height:95%;
 background-color:#07fe08;
 opacity:0.5;
}
#cnt {
 position:relative;
 background:#e7e8fe;
 width:300px;
 height:200px;
 border:1px solid blue;
 padding:20px;
}
#cnt:hover #trans { display:block; }
</style>

<h4>Example content hovered with transparency element on hover</h4>

<div id='cnt'>
 <div id='trans'></div>
 Place the mouse over this box to see the opacity effect.
<img src='css/css3.jpg' alt='CSS3 opacity' width='160' height='98' />
</div>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas>
<embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line
#id:first-line {
  font-weight: bold;
  color: blue;
}
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.status
var url = window.location;
alert(url);
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()
$homepage = file_get_contents("http://coursesweb.net/");
echo $homepage;
CSS3 opacity

Last accessed pages

  1. Get and Modify content of an Iframe (19335)
  2. PHP MySQL - WHERE and LIKE (21411)
  3. PHP getElementById and getElementsByTagName (32807)
  4. Node.js Move and Copy file (13787)
  5. insertAdjacentHTML - Insert content at a specified position (2422)

Popular pages this month

  1. Making DIV Contents Scroll Horizontally, with multiple Div`s inside (1321)
  2. Contact page - CoursesWeb (1292)
  3. Tabs effect with CSS (1289)
  4. PHP getElementById and getElementsByTagName (589)
  5. Get Attribute (ID, Class, Name, Title, Src) with jQuery (488)