如何用 js 实现 css 透明渐变效果 如:百度首页随心听的歌词效果

html-css064

如何用 js 实现 css 透明渐变效果 如:百度首页随心听的歌词效果,第1张

你可以用png透明图片做一个渐变的透明然后用css相对定位到和z-index属性调整div层设置div的背景。

<style type="text/css">

.lrcBox{position:relativeheight:400pxwidth:400pxdisplay:blockoverflow:hiddenborder:1px solid #60Ffont-size:12px}

.lrcBox .top{display:blockposition:absoluteheight:30pxwidth:100%top:0pxz-index:2background:url(lrc_cover_big_04640cde.png) no-repeat left top}

.lrcBox .warp{display:blockpadding:10pxbackground-color:#fffheight:100%}

.lrcBox .body{display:bolockwidth:100%height:100%background-color:#39F}

.lrcBox .body ul,.lrcBox .body li{display:blocklist-style:nonepadding:0margin:0text-align:center}

.lrcBox .body ul{ width:100%}

.lrcBox .body li{ padding-top:3pxpadding-bottom:3px}

.lrcBox .bottom{display:blockposition:absoluteheight:30pxwidth:100%bottom:0pxz-index:2background:url(lrc_cover_big_04640cde.png) no-repeat left bottom}

</style>

<div class="lrcBox">

<!--上边的渐变背景层-->

<div class="top"></div>

<!--歌词层-->

<div class="warp">

<div class="body">

<ul>

<li>这里是一行歌词</li>

<li>这里是一行歌词</li>

<li>这里是一行歌词</li>

</ul>

</div>

</div>

<!--下边的渐变背景层-->

<div class="bottom"></div>

</div>

至于lrc_cover_big_04640cde.png这张图片你可以自己做,也可以到百度首页随心听的图片资源中找到,下载就可以。

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:

div {width: 200pxheight: 150pxbackground: linear-gradient(red, white)}

3、浏览器运行index.html页面,此时td中的div的背景颜色从红色到白色渐变。