CSS3 achieves dynamic card flip effect
Imitating the special effects of Baidu Tieba’s 3D card flipping once animation, this article mainly shares a special effect that uses the new CSS3 feature transform to achieve 3D card flipping special effects. Friends in need can refer to it. Hope it helps everyone.
Today I will share a card flip effect made with CSS3. The effect is as shown in the picture below. If you apply this effect to the photo album, it will definitely be very dazzling. Haha, super cool.
1. HTML code:
Because it is implemented in CSS3, you can see that there is no JS code. ul is a set of pictures. Each li has an a (because we want to jump by clicking on the picture). a contains two p, one is for normal display (that is, the picture is displayed), and the other is for display after the picture is rotated. (i.e. introduction).
<!doctype html> <html> <head> <meta charset="gb2312"> <title>百度帖吧 CSS3 翻牌效果</title> <link rel="stylesheet" type="text/css" href="style/reset.css"> <link rel="stylesheet" type="text/css" href="style/tieba.brand.css"> </head> <body> <h1 id="百度帖吧-nbsp-CSS-nbsp-翻牌效果">百度帖吧 CSS3 翻牌效果</h1> <h2 id="powered-nbsp-by-nbsp-a-nbsp-href-http-blog-wangjunfeng-com-nbsp-target-blank-射雕天龙的博客-a">powered by <a href="http://blog.wangjunfeng.com" target="_blank">射雕天龙的博客</a></h2> <p id="content"> <ul> <li> <a href="http://blog.wangjunfeng.com" target="_blank"> <p><img src="/static/imghw/default1.png" data-src="images/1.jpg" class="lazy" alt="" /></p> <p> <h3 id="漩涡鸣人">漩涡鸣人</h3> <p>日本漫画家岸本齐史作品《火影忍者》中男主角。因为身上封印着邪恶的九尾妖狐,无父无母的他受尽了村人的冷眼与歧视,他下定决心要成为第六代火影,让所有人都认同他的存在。</p> </p> </a> </li> <li> <a href="http://blog.wangjunfeng.com" target="_blank"> <p> <img src="/static/imghw/default1.png" data-src="images/2.jpg" class="lazy" alt="" /> </p> <p> <h3 id="日向雏田">日向雏田</h3> <p>日本漫画家岸本齐史作品《火影忍者》中的3号女主角。木叶忍者村的女忍者,木叶名门日向一族宗家族长的长女。喜欢漩涡鸣人,原本是个性格柔弱的女孩,但是在鸣人的影响下逐渐变得坚强,并逐渐成长为一名优秀的忍者。</p> </p> </a> </li> <li> <a href="http://blog.wangjunfeng.com" target="_blank"> <p><img src="/static/imghw/default1.png" data-src="images/3.jpg" class="lazy" alt="" /></p> <p> <h3 id="蒙奇-D-路飞">蒙奇·D·路飞</h3> <p>蒙奇·D·路飞 是日本人气动漫 《海贼王》中的主人公。是日本人气动漫 《海贼王》中的主人公。草帽海贼团船长,梦想是找到传说中的宝藏 —— ONE PIECE,成为海贼王。</p> </p> </a> </li> <li> <a href="http://blog.wangjunfeng.com" target="_blank"> <p> <img src="/static/imghw/default1.png" data-src="images/4.jpg" class="lazy" alt="" /> </p> <p> <h3 id="盒子先生">盒子先生</h3> <p>Danbo是一只用废纸盒DIY出来的可爱玩偶,圆圆的眼睛和三角形的嘴巴,时刻露出无辜的表情,让人看到就心软,Danbo是个纯真善良的小家伙,在它单纯的幻想世界里,总是透露出最纯真可爱的动人气息。</p> </p> </a> </li> </ul> </p> </body> </html>
2. CSS3 code
I have made comments in some places, it should be easy to understand.
#content ul{ width:960px; padding:60px 0; margin:0 auto; } #content ul li{ width:225px; height:180px; margin-right:20px; float:left; } #content ul li:last-child{ margin-right: 0; } #content ul li a{ display:block; height:180px; /* 设置元素被查看位置的视图: perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。 当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本身。 */ -webkit-perspective:500px; -moz-perspective:500px; -ms-perspective:500px; perspective:500px; position: relative; } #content ul li a > p{ top:0; left:0; width:100%; height:180px; color:#fff; /* 指定嵌套元素如何在3D空间中呈现。 */ -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -ms-transform-style: preserve-3d; /* 隐藏被旋转的 p 元素的背面 */ -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; -ms-backface-visibility: hidden; -webkit-transition:0.8s ease-in-out ; -moz-transition:0.8s ease-in-out ; -ms-transition:0.8s ease-in-out ; position:absolute; } #content ul li a p:first-child{ -webkit-transform: rotateY(0); -moz-transform: rotateY(0); -ms-transform: rotateY(0); z-index: 2; } #content ul li a:hover p:first-child{ -webkit-transform: rotateY(-180deg); -moz-transform: rotateY(-180deg); -ms-transform: rotateY(-180deg); } #content ul li a p:last-child{ -webkit-transform: rotateY(180deg); -moz-transform: rotateY(180deg); -ms-transform: rotateY(180deg); z-index: 1; background:url('../images/bg.jpg') no-repeat; } #content ul li a:hover p:last-child{ -webkit-transform: rotateY(0); -moz-transform: rotateY(0); -ms-transform: rotateY(0); z-index: 1; } #content ul li a p h3{ margin:0 auto 15px; padding:15px 0; width:200px; height:16px; line-height:16px; font-size: 14px; text-align: center; border-bottom:1px #fff dashed; } #content ul li a p p{ padding:0 10px; font-size: 12px; text-indent: 2em; line-height:18px; }
3. Implementation Principle
The default image rotateY=0; the mouse pointer is rotateY=-180, a negative number, that is Rotate counterclockwise around the y-axis. If it is a positive number, it is clockwise. The same applies to the other two axes. When the mouse points to: picture (p:first-child), rotate counterclockwise around the y-axis from 0 degrees by 180 degrees to -180 degrees. ;Introduction (p:last-child) rotates 180 degrees counterclockwise around the y-axis from 180 degrees to 0 degrees. Creates the effect of two counterclockwise rotations together. Some people may ask why the default introduction is not 0 degrees. Note here that the introduction is in a frontal state after being rotated 180 degrees counterclockwise, so when the image is covered, it is equivalent to a 180-degree clockwise rotation from the normal state, because when the mouse points Need to return to normalcy.
4. Source code download
http://xiazai.jb51.net/201605/yuanma/CSS3_BaiduTieba_Flop%28jb51.net%29.rar
5. Summary
CSS3 provides many new features such as transform. When we use these features, they may only be compatible with new browsers. For IE6, 7, and 8 The compatibility of such old antiques is not very good, but it is enough. For example, in the above example, in browsers such as IE6, 7, and 8, no special effects are displayed, only pictures are displayed, and they are not ugly. In other browsers, they are compatible with HTML5 and CSS3. In better browsers, you can see the special effects. It avoids using too much JS and achieves a cool display effect in new browsers.
Related recommendations:
Detailed explanation of Angularjs filter to implement dynamic search and sorting functions
Steps to implement the effect of creating dynamic switches in Css3
Several ways to create dynamic effects in HTML 5
The above is the detailed content of CSS3 achieves dynamic card flip effect. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
