Home  >  Article  >  Web Front-end  >  What are the attributes used to achieve rotation effects in css3

What are the attributes used to achieve rotation effects in css3

青灯夜游
青灯夜游Original
2021-12-14 17:38:282398browse

The attribute that achieves rotation effect in css3 is "transform". The transform attribute is used to apply a 2D or 3D transformation to an element. Rotation can be achieved when this attribute is used with the rotate(), rotate3d(), rotateX(), rotateY() or rotateZ() functions.

What are the attributes used to achieve rotation effects in css3

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

The attribute that implements the rotation effect in css3 is "transform".

The transform attribute is used to apply 2D or 3D transformation to the element. When this attribute is used with the following function, the element rotation can be achieved:

  • rotate(angle ) Define 2D rotation and specify the angle in the parameters.

  • rotate3d(x,y,z,angle) Define 3D rotation.

  • rotateX(angle) Defines a 3D rotation along the X-axis.

  • rotateY(angle) Defines 3D rotation along the Y axis.

  • rotateZ(angle) Defines 3D rotation along the Z axis.

Example 1:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
div
{
	width:200px;
	height:100px;
	background-color:yellow;
	/* Rotate div */
	transform:rotate(7deg);
	-ms-transform:rotate(7deg); /* IE 9 */
	-webkit-transform:rotate(7deg); /* Safari and Chrome */
}
</style>
</head>
<body>

<div>Hello</div>

</body>
</html>

What are the attributes used to achieve rotation effects in css3

Example 2:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			*,
			*:after,
			*:before {
				box-sizing: border-box;
			}

			body {
				background: #F5F3F4;
				margin: 0;
				padding: 10px;
				font-family: &#39;Open Sans&#39;, sans-serif;
				text-align: center;
			}

			h1 {
				color: #4c4c4c;
				font-weight: 600;
				border-bottom: 1px solid #ccc;
			}

			h2,
			h4 {
				font-weight: 400;
				color: #4d4d4d;
			}

			.card {
				display: inline-block;
				margin: 10px;
				background: #fff;
				padding: 15px;
				min-width: 200px;
				box-shadow: 0 3px 5px #ddd;
				color: #555;
			}

			.card .box {
				width: 100px;
				height: 100px;
				margin: auto;
				background: #ddd;
				cursor: pointer;
				box-shadow: 0 0 5px #ccc inset;
			}

			.card .box .fill {
				width: 100px;
				height: 100px;
				position: relative;
				background: #03A9F4;
				opacity: .5;
				box-shadow: 0 0 5px #ccc;
				-webkit-transition: 0.3s;
				transition: 0.3s;
			}

			.card p {
				margin: 25px 0 0;
			}

			.rotate:hover .fill {
				-webkit-transform: rotate(45deg);
				transform: rotate(45deg);
			}

			.rotateX:hover .fill {
				-webkit-transform: rotateX(45deg);
				transform: rotateX(45deg);
			}

			.rotateY:hover .fill {
				-webkit-transform: rotateY(45deg);
				transform: rotateY(45deg);
			}

			.rotateZ:hover .fill {
				-webkit-transform: rotate(45deg);
				transform: rotate(45deg);
			}

			.scale:hover .fill {
				-webkit-transform: scale(2, 2);
				transform: scale(2, 2);
			}

			.scaleX:hover .fill {
				-webkit-transform: scaleX(2);
				transform: scaleX(2);
			}

			.scaleY:hover .fill {
				-webkit-transform: scaleY(2);
				transform: scaleY(2);
			}
		</style>
	</head>
	<body>
		<h1>CSS3 元素旋转</h1>
		<!-- Rotate-->
		<div class="card">
			<div class="box rotate">
				<div class="fill"></div>
			</div>
			<p>rotate(45deg) </p>
		</div>
		<div class="card">
			<div class="box rotateX">
				<div class="fill"></div>
			</div>
			<p>rotateX(45deg)</p>
		</div>
		<div class="card">
			<div class="box rotateY">
				<div class="fill"></div>
			</div>
			<p>rotateY(45deg)</p>
		</div>
		<div class="card">
			<div class="box rotateZ">
				<div class="fill"></div>
			</div>
			<p>rotateZ(45deg) </p>
		</div>
	</body>
</html>

What are the attributes used to achieve rotation effects in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of What are the attributes used to achieve rotation effects in css3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn