Files
freeCodeCamp/guide/chinese/css/image-opacity-and-transparency/index.md
2018-10-16 21:32:40 +05:30

51 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Image Opacity and Transparency
localeTitle: 图像不透明度和透明度
---
## 图像不透明度和透明度
`opacity`属性允许您通过降低图像的`opacity`来使图像透明。
`Opacity`的值介于0.0和1.0之间。
1.0是任何图像的默认值。它是完全不透明的。
```css
img {
opacity: 0.3;
}
```
Include ```filter: alpha(opacity=x)``` for IE8 and earlier. The x takes a value from 0-100.
```
CSS img { 不透明度0.3; filteralphaopacity = 30; }
```
Here's an example of an image set to the parameters in the example above.
![image at 30% opacity](https://github.com/lvcoulter/images/blob/master/Opacity30percent.jpg?raw=true)
You can pair ```opacity``` with ```:hover``` to create a dynamic mouse-over effect.
Example:
```
CSS img { 不透明度0.3; filteralphaopacity = 30; } imghover { 不透明度1.0; filteralphaopacity = 100; }
```
[A codepen example to show a transparent image turning opaque on hover](https://codepen.io/lvcoulter/full/JrzxXa/)
<!--I cannot figure out how to embed a Codepen. I would really like to know-->
You can create the opposite effect with less code since the image is 1.0 opacity by default
Example:
```
CSS imghover { 不透明度0.3; filteralphaopacity = 30; } \`\`\` [用于显示鼠标悬停透明度的codepen示例](https://codepen.io/lvcoulter/full/xXBQoR/)
#### 更多信息:
\-w3schools.com [CSS不透明度/透明度](https://www.w3schools.com/css/css_image_transparency.asp)
\-MDN web docs [Opacity](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity)