css動畫 卡片翻轉顯示不同內容

做法:
	兩個div重疊,元素設置背面不可見屬性,剛開始將第二個div繞y軸翻轉180度不可見
	當鼠標放上父元素時,讓兩個子元素都旋轉,設置第一個子元素繞y軸翻轉180度不可見,讓第二個子元素繞y軸翻轉回0度可見

代碼示例:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	<link rel="stylesheet" href="./index.css">
	<style>
		.box{
			width: 400px;
			height: 400px;
			border: solid 1px blueviolet;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 100px auto;
			perspective: 900px;
		}
		.box>div{
			width: 200px;
			height: 200px;
			position: absolute;
			background-color: red;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 4em;
			transition: 2s;
			backface-visibility: hidden;
		}
		
		.box>div:nth-child(1){
			background-color: blue;
			transform: rotateY(0deg);
		}
		.box>div:nth-child(2){
			transform: rotateY(180deg);
			background-color: cadetblue;
		}
		.box:hover div:nth-child(1)
		{
			transform: rotateY(180deg);
			background-color: blue;
		}
		.box:hover div:nth-child(2)
		{
			transform: rotateY(0deg);
			background-color: cadetblue;
		}

		
		 
	</style>
	</head>
	<body class='me'>
		<div class='box'>
			<div>1</div>
			<div>2</div>
	

		</div>
		
	</body>
</html>

效果圖:
在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章