css如何给图片加一个蒙版遮罩

html-css08

css如何给图片加一个蒙版遮罩,第1张

1.首先,看一下HTML,一个img图像控件和一个带有样式的div,其中包含文本。这个就是蒙版遮罩层。

2.然后,查看样式定义。先检查图像容器和图像样式,如图所示。其中要注意的是img_container样式里定义了position:relative,这个主要是为了遮罩层做绝对定位做准备的。

3.接着,查看遮罩层的样式定义。该代码如图所示。

背景:rgba(0,0,0,0.7);

可以通过修改以下数字0.7来更改透明度。 1是完全不透明的,0是完全透明的。

4.随后,添加用于鼠标移动的脚本代码以显示遮罩层。该js代码是用jquery编写的,既方便又简单,因此首先介绍jquery脚本库。

5.然后,添加mouseover和mouseout事件,主要是当鼠标移到图像容器时显示遮罩层,并在鼠标移出时隐藏遮罩层。

6.刷新页面,可以看到页面上显示的普通图片。

7.最后,可以看到当鼠标放在图片上时,将显示遮罩层。

<!--遮罩层输入密码-->

<div class="dongjie" style="width: 100%height: 100%background-color: rgba(0,0,0,0.6)z-index: 11111position: fixedleft: 0top:0">

    <div class="jiedon_box" style="width: 92%background: #eeeeeeheight: 4.8remposition: fixedleft: 4%top:36%z-index: 1111">

        <input style="width: 80%height: 0.66remdisplay: blockmargin: automargin-top: 1rempadding-left: 0.2rem" type="password" placeholder="请输入交易密码" name="">

        <div style="margin-top:0.6remmargin-left:10%overflow: hidden">

            <button style="width: 2remheight: 0.66remfloat: leftbackground: #0093DDcolor: #ffffff">确定</button>

            <button style="width: 2remheight: 0.66remfloat:rightmargin-right:11% ">取消</button>

        </div>

    </div>

</div>

嘿嘿,你的分,我吃了!我不明白你说那遮罩的位置在哪?不知道我这么放可对?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot>

<html xmlns="http://www.w3.org/1999/xhtml&quot>

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

.box{ width:400px background:#eeeeee}

.box:after{ content:"" clear:both display:block}

.box1,.box2,.box3,.box4{float:left width:200pxheight:40px}

.box4{ position:relative}

.box4 .son{ position:absolute width:200px height:30px background:#ccc}

</style>

</head>

<body>

<div class="box">

<div class="box1" style=""><input type="text" value="1" /></div>

<div class="box2"><input type="text" value="2" /></div>

<div class="box3"><input type="text" value="3" /></div>

<div class="box4">

<div class="son">遮罩放这里?</div>

<input type="text" value="4" />

</div>

</div>

</body>

</html>