The opacity property specifies the opacity/transparency of an element.
The opacity property is often used together with the :hover selector to change the opacity on mouse-over:
The opacity
property is often used with the :hover
selector to change the opacity on mouse-over:
The first CSS block is similar to the code in Example 1.
In addition, we have added what should happen when a user hovers over one of the images. In this case, we want the image to NOT be transparent when the user hovers over it. The CSS for this is opacity: 1;
.
When the mouse pointer moves away from the image, the image will be transparent again.
When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read:
Text is fully visible
Text is slightly transparent
Text is harder to read
Text is very hard to read