国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

CSSオンラインマニュアル / CSS 圖像透明/不透明

CSS 圖像透明/不透明

CSS 圖像透明/不透明


使用CSS很容易創(chuàng)建透明的圖像。

注意:CSS Opacity屬性是W3C的CSS3建議的一部分。


更多實(shí)例

創(chuàng)建透明圖像 - 懸停效果

實(shí)例

<!DOCTYPE html>
<html>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title>  
<head>
<style>
img
{
	opacity:0.4;
	filter:alpha(opacity=40); /* 適用 IE8 及其更早版本 */
}
img:hover
{
	opacity:1.0;
	filter:alpha(opacity=100); /* 適用 IE8 及其更早版本 */
}
</style>
</head>
<body>

<h1>圖片透明度</h1>
<p>opacity 屬性通常與 :hover 選擇器一起使用,在鼠標(biāo)移動(dòng)到圖片上后改變圖片的透明度:</p>
<img src="https://img.php.cn/upload/article/000/000/015/5c6a756568f26867.jpg" width="150" height="113" alt="klematis">
<img src="https://img.php.cn/upload/article/000/000/015/5c6a757f738b2492.jpg" width="150" height="113" alt="klematis">

<p><b>注意:</b>在 IE 中必須聲明 <!DOCTYPE> 才能保證 :hover 選擇器能夠有效。</p>
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線(xiàn)實(shí)例

創(chuàng)建一個(gè)具有文本的擁有背景圖像的透明框

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title>  
<style>
div.background
{
  width: 500px;
  height: 250px;
  background: url(https://img.php.cn/upload/article/000/000/015/5c6a756568f26867.jpg) repeat;
  border: 2px solid black;
}
div.transbox
{
  width: 400px;
  height: 180px;
  margin: 30px 50px;
  background-color: #ffffff;
  border: 1px solid black;
  opacity:0.6;
  filter:alpha(opacity=60); /* For IE8 and earlier */
}
div.transbox p
{
  margin: 30px 40px;
  font-weight: bold;
  color: #000000;
}
</style>
</head>
<body><div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p>
</div>
</div>
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線(xiàn)實(shí)例


實(shí)例1 - 創(chuàng)建一個(gè)透明圖像

CSS3中屬性的透明度是 opacity.

首先,我們將向您展示如何用CSS創(chuàng)建一個(gè)透明圖像。

正常的圖像:

1.jpg

相同的圖像帶有透明度:

2.jpg

看看下面的CSS:

img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}

IE9,F(xiàn)irefox,Chrome,Opera,和Safari瀏覽器使用透明度屬性可以將圖像變的不透明。 Opacity屬性值從0.0 - 1.0。值越小,使得元素更加透明。

IE8和早期版本使用濾鏡:alpha(opacity= x)。 x可以采取的值是從0 - 100。較低的值,使得元素更加透明。


實(shí)例2 - 圖像的透明度 - 懸停效果

將鼠標(biāo)移到圖像上:

2.gif

CSS樣式:

img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}

第一個(gè)CSS塊是和例1中的代碼類(lèi)似。此外,我們還增加了當(dāng)用戶(hù)將鼠標(biāo)懸停在其中一個(gè)圖像上時(shí)發(fā)生什么。在這種情況下,當(dāng)用戶(hù)將鼠標(biāo)懸停在圖像上時(shí),我們希望圖片是清晰的。

此CSS是:opacity=1.

IE8和更早版本使用: filter:alpha(opacity=100).

當(dāng)鼠標(biāo)指針遠(yuǎn)離圖像時(shí),圖像將重新具有透明度。


實(shí)例3 - 透明的盒子中的文字

源代碼如下:

<html>
<head>
<style>
div.background
    {
    width:500px;
    height:250px;
    background:url(../style/images/klematis.jpg) repeat;
    border:2px solid black;
    }
div.transbox
    {
    width:400px;
    height:180px;
    margin:30px 50px;
    background-color:#ffffff;
    border:1px solid black;
    opacity:0.6;
    filter:alpha(opacity=60); /* For IE8 and earlier */
    }
div.transbox p
    {
    margin:30px 40px;
    font-weight:bold;
    color:#000000;
    }
</style>
</head>

<body>

<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p>
</div>
</div>

</body>
</html>

首先,我們創(chuàng)建一個(gè)固定的高度和寬度的div元素,帶有一個(gè)背景圖片和邊框。然后我們?cè)诘谝粋€(gè)div內(nèi)部創(chuàng)建一個(gè)較小的div元素。 這個(gè)div也有一個(gè)固定的寬度,背景顏色,邊框 - 而且它是透明的。透明的div里面,我們?cè)赑元素內(nèi)部添加一些文本。