css如何实现颜色的过渡效果

html-css0233

css如何实现颜色的过渡效果,第1张

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

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

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

button {width: 100pxheight: 50pxborder: 0color: whitebackground: -webkit-radial-gradient(#72787f, #545c64)}

3、浏览器运行index.html页面,此时用CSS实现了按钮中间白、四周黑,上方白、下方灰的效果。

方法有很多种,下面我介绍一种纯CSS的实现的方式:

<!DOCTYPE html>

<html lang="zh-cn">

<head>

<meta charset="utf-8" />

<title></title>

<style>

html,

body {

margin: 0

padding: 0

}

.main {

width: 460px/*每个box的宽度为150px,间隔为5*2*/

margin: 0 auto

}

.demo {

float: left

display: inline-block

}

.box {

height: 150px

width: 150px

background: #3695d5

position: relative

overflow: hidden

}

.inbox {

height: 50px

line-height: 50px

text-align: center

color: #FFF

width: 100%

position: absolute

bottom: -50px

background: rgba(0, 0, 0, 0.3)

transition: 1s/*过渡效果*/

}

.box:hover>.inbox {

bottom: 0

}

</style>

</head>

<body>

<div class="main">

<div class="demo">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

<div class="demo" style="margin: 0 5px 0 5px">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

<div class="demo">

<div class="box">

图片

<div class="inbox">

文字

</div>

</div>

</div>

</div>

</body>

</script>

</html>