Home > Article > Web Front-end > How to achieve translucent effect of images in css
Css method to achieve image translucency: You can set it through the opacity attribute, such as [style="-moz-opacity:0.5";]. The opacity attribute is used to set the opacity level of an element, and the syntax is [opacity:value|inherit;].
Environment of this article:
windows10, css3
Applicable to All brands of computers
Attribute introduction:
The opacity attribute sets the opacity level of the element.
(Learning video sharing: css video tutorial)
Grammar:
opacity: value|inherit;
Attribute value:
value Specifies opacity. From 0.0 (fully transparent) to 1.0 (fully opaque).
inherit The value of the opacity attribute should be inherited from the parent element.
The implementation code is as follows:
This effect can work on both IE and Mozilla browsers, the code is as follows
<img alt="powerbookg4.jpg" src="archives/images/powerbookg4.jpg" width="250" height="60" style="-moz-opacity:0.5; filter:alpha(opacity=50);cursor:hand;" onmouseover="this.style.MozOpacity=1; this.filters.alpha.opacity=100" onmouseout="this.style.MozOpacity=0.5; this.filters.alpha.opacity=50">
In IE The transparency "opacity" needs to be defined through "filter", and "opacity" can be parsed directly in Mozilla, so if you want this effect to be supported in both browsers, you need to add both settings.
Settings for IE: this.filters.alpha.opacity=50; settings for Mozilla: this.style.MozOpacity=0.5.
Related recommendations: CSS tutorial
The above is the detailed content of How to achieve translucent effect of images in css. For more information, please follow other related articles on the PHP Chinese website!