Home >Web Front-end >Front-end Q&A >html set image transparency
In HTML, you can use the filter attribute to set the image transparency effect. You only need to add the "filter:opacity(%);" style to the image element; the value of the opacity() function is between 0% and 100 %, a value of 0% means it is completely transparent, and a value of 100% means there is no change in the image.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
htmlSet image transparency
<!DOCTYPE html> <html> <head> <style> #img1 { -webkit-filter: opacity(30%); /* Chrome, Safari, Opera */ filter: opacity(30%); } #img2 { -webkit-filter: opacity(60%); /* Chrome, Safari, Opera */ filter: opacity(60%); } </style> </head> <body> <p>原图:</p> <img src="pineapple.jpg" alt="Pineapple" width="200" > <p>转化图像的透明程度:</p> <img id="img1" src="pineapple.jpg" alt="Pineapple" width="200"> <img id="img2" src="pineapple.jpg" alt="Pineapple" width="200""> </body> </html>
Rendering:
Description:
The filter attribute defines the visual effect (such as blur and saturation) of the element (usually ).
Values or functions that can be used in the filter attribute:
Filter | Description |
---|---|
none | Default value, no effect. |
blur(px) | Set Gaussian blur to the image. The "radius" value sets the standard deviation of the Gaussian function, or how many pixels are blended together on the screen, so the larger the value, the blurr it is; If no value is set, the default is 0; this parameter can Set css length value, but does not accept percentage value. |
brightness(%) | Applies a linear multiplication to the image, making it appear brighter or darker. If the value is 0%, the image will be completely black. If the value is 100%, there will be no change in the image. Other values correspond to linear multiplier effects. Values above 100% are okay and the image will be brighter than before. If no value is set, the default is 1. |
contrast(%) | Adjust the contrast of the image. If the value is 0%, the image will be completely black. The value is 100% and the image is unchanged. Values can exceed 100%, meaning a lower comparison will be used. If no value is set, the default is 1. |
drop-shadow(h-shadow v-shadow blur spread color) |
Sets a shadow effect to the image. Shadows are composited underneath the image and can be blurred, offset versions of the matte that can be painted in a specific color. The function accepts values of type 注意: Webkit, 以及一些其他浏览器 不支持第四个长度,如果加了也不会渲染。 |
grayscale(%) | 将图像转换为灰度图像。值定义转换的比例。值为100%则完全转为灰度图像,值为0%图像无变化。值在0%到100%之间,则是效果的线性乘子。若未设置,值默认是0; |
hue-rotate(deg) | 给图像应用色相旋转。"angle"一值设定图像会被调整的色环角度值。值为0deg,则图像无变化。若值未设置,默认值是0deg。该值虽然没有最大值,超过360deg的值相当于又绕一圈。 |
invert(%) | 反转输入图像。值定义转换的比例。100%的价值是完全反转。值为0%则图像无变化。值在0%和100%之间,则是效果的线性乘子。 若值未设置,值默认是0。 |
opacity(%) | 转化图像的透明程度。值定义转换的比例。值为0%则是完全透明,值为100%则图像无变化。值在0%和100%之间,则是效果的线性乘子,也相当于图像样本乘以数量。 若值未设置,值默认是1。该函数与已有的opacity属性很相似,不同之处在于通过filter,一些浏览器为了提升性能会提供硬件加速。 |
saturate(%) | 转换图像饱和度。值定义转换的比例。值为0%则是完全不饱和,值为100%则图像无变化。其他值,则是效果的线性乘子。超过100%的值是允许的,则有更高的饱和度。 若值未设置,值默认是1。 |
sepia(%) | 将图像转换为深褐色。值定义转换的比例。值为100%则完全是深褐色的,值为0%图像无变化。值在0%到100%之间,则是效果的线性乘子。若未设置,值默认是0; |
url() |
URL函数接受一个XML文件,该文件设置了 一个SVG滤镜,且可以包含一个锚点来指定一个具体的滤镜元素。 例如: filter: url(svg-url#element-id) |
The above is the detailed content of html set image transparency. For more information, please follow other related articles on the PHP Chinese website!