使用 CSS3 执行多个过渡
对于多个过渡,使用 CSS3 transition 属性,它是一个速记属性。它能在单行中设置过渡属性、持续时间、时序和延迟时间。我们假设我们更改了过渡的宽度和边框半径。
transition: width 2s, border-radius 2s;
设置容器 div
首先,设置一个父 div −
<div class="container"> <div></div> </div>
设置过渡
使用 transition 属性为 width 和 border-radius 属性设置过渡。设置的持续时间为 2 秒 −
.container div {
width: 300px;
height: 100px;
border-radius: 1px;
background: rgb(25, 0, 255);
border: 2px solid red;
transition: width 2s, border-radius 2s;
}
悬停时
悬停鼠标光标时,由于我们在上面设置了两个过渡,形状将发生改变 −
.container:hover div {
width: 100px;
border-radius: 50%;
}
以宽度和边框半径设置多个过渡
以下是使用 CSS3 执行多个过渡的代码 −
范例
以下为范例 −
<!DOCTYPE html>
<html>
<head>
<style>
.container div {
width: 300px;
height: 100px;
border-radius: 1px;
background: rgb(25, 0, 255);
border: 2px solid red;
transition: width 2s, border-radius 2s;
}
.container:hover div {
width: 100px;
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Multiple transitions example</h1>
<div class="container">
<div></div>
</div>
<h2>
Hover over the above div to reduce its width and to change it into circle
</h2>
</body>
</html>
以宽度和高度设置多个过渡
让我们看另一个有关多个过渡的范例。使用 transition 属性为 width、height 和 background-color 属性设置过渡。设置的持续时间为 2 秒 −
transition: width 3s, height, 3s, background-color 3s;
范例
以下为范例 −
<!DOCTYPE html>
<html>
<head>
<style>
.container div {
width: 300px;
height: 100px;
border-radius: 1px;
background: rgb(25, 0, 255);
border: 2px solid red;
transition: width 3s, height, 3s, background-color 3s;
}
.container:hover div {
width: 150px;
height: 150px;
background-color: orange;
}
</style>
</head>
<body>
<h1>Multiple transitions example</h1>
<div class="container">
<div></div>
</div>
<h2>
Hover over the above div to reduce its width, height and background color
</h2>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP