search
HomeWeb Front-endCSS TutorialCSS3 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.

CSS3 achieves dynamic card flip effect

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/imghwm/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/imghwm/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/imghwm/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/imghwm/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(&#39;../images/bg.jpg&#39;) 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!

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
The Lost CSS Tricks of Cohost.orgThe Lost CSS Tricks of Cohost.orgApr 25, 2025 am 09:51 AM

In this post, Blackle Mori shows you a few of the hacks found while trying to push the limits of Cohost’s HTML support. Use these if you dare, lest you too get labelled a CSS criminal.

Next Level CSS Styling for CursorsNext Level CSS Styling for CursorsApr 23, 2025 am 11:04 AM

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Worlds Collide: Keyframe Collision Detection Using Style QueriesWorlds Collide: Keyframe Collision Detection Using Style QueriesApr 23, 2025 am 10:42 AM

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Using CSS backdrop-filter for UI EffectsUsing CSS backdrop-filter for UI EffectsApr 23, 2025 am 10:20 AM

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

SMIL on?SMIL on?Apr 23, 2025 am 09:57 AM

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

'Pretty' is in the eye of the beholder'Pretty' is in the eye of the beholderApr 23, 2025 am 09:40 AM

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

CSS-Tricks Chronicles XLIIICSS-Tricks Chronicles XLIIIApr 23, 2025 am 09:35 AM

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Tailwind's @apply Feature is Better Than it SoundsTailwind's @apply Feature is Better Than it SoundsApr 23, 2025 am 09:23 AM

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment