search
HomeWeb Front-endCSS TutorialUse CSS3 to achieve image flip effect

Use CSS3 to achieve image flip effect

Jun 14, 2018 pm 04:35 PM
css3flip

This article mainly introduces the method of creating flip effect with CSS3. CSS3 creates 3D card flip effect, which is suitable for poker flip and other games. It has certain reference value. Interested friends can refer to it

The flip effect produced by CSS3 is that when the mouse is moved over the element, it feels like you can see the information behind the element. If you make Lianliankan, poker-type games that test your memory, or even write some words to your girlfriend, you can try it after putting them in the photo album made using this example, ha~

Rendering:

Some new css3 properties used in the example:

a. -webkit-perspective: 800px;

Perspective (perspective, perspective): Attribute defines the distance of the 3D element from the view, in pixels. This property allows you to change the 3D element's view of the 3D element. Determines whether what you see is a 2D transform or a 3D transform.

b, -webkit-transform-style: preserve-3d;

The transform-style attribute specifies how to render nested elements in 3D space. The default is flat, we use 3D effect, and then select 3D.

c, -webkit-backface-visibility: hidden; Whether to display the selected element after it is rotated to the back.

d、-webkit-transform: rotateY(0); The element rotates around the Y axis.

The above attributes will give you a perceptual understanding first. After reading the examples, you can then taste these attributes carefully, or use Baidu or Google Shenma.

Example:

Html:

<body>


<p id="content">
    <ul>
        <li>
            <a href="#" 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="#" 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="#" 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="#" 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>

is quite simple:

ul is a set of pictures, and there is a in each li (because we I hope you can jump by clicking on the picture), a contains two p's, one is when it is displayed normally (that is, the picture is displayed), and the other is when the picture is rotated (that is, the introduction).

CSS:

 <link href="css/reset.css" rel="stylesheet" type="text/css">

    <style type="text/css">

        body
        {
            font-size: 14px;
            font-family: Microsoft YaHei, Tahoma, Geneva, sans-serif;
            background: #111;
        }

        #content ul
        {
            width: 960px;
            margin: 150px auto;
            padding: 60px 0;
        }

        #content ul li
        {
            margin-right: 20px;
            width: 225px;
            height: 180px;
            float: left;
        }

        #content ul li:last-child
        {
            margin-right: 0;
        }

        #content ul li a
        {
            position: relative;
            display: block;
            width: 100%;
            height: 100%;
            /*舞台(动画元素的父容器)perspective*/
            -webkit-perspective: 800px;
            -moz-perspective: 800px;

        }

        #content ul li a > p
        {
            position: absolute;
            left: 0;
            height: 0;
            width: 100%;
            height: 100%;
            color: #fff;
            /*动画元素transform-style*/
            -webkit-transform-style: preserve-3d;
            -webkit-transition: .8s ease-in-out ;
            /*动画元素背后设置为hidden*/
            -webkit-backface-visibility: hidden;
        }

        #content ul li a p:first-child
        {
            /*
            绕y轴旋转
            */
            -webkit-transform: rotateY(0);
            z-index: 2;
        }

        #content ul li a p:last-child
        {
            background: url("images/bg.jpg") no-repeat 0 0;
            -webkit-transform: rotateY(180deg);
            z-index: 1;
        }

        #content ul li a:hover p:first-child
        {
            -webkit-transform: rotateY(-180deg);
        }

        #content ul li a:hover p:last-child
        {
            -webkit-transform: rotateY(0);
        }

        #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;
        }


    </style>

Okay, in the above CSS you can find the CSS properties mentioned earlier in the article.

1. The most important thing is to understand rotateY, which rotates around the y-axis. Remember that I also used similar attributes transform: rotate(2520deg); in the exquisite case of HTML5 CSS3: realizing personalized slideshows in VCD packaging boxes. It's a 2D rotation.

rotateY literally rotates around the y-axis. Someone must ask where the y-axis is:

The default center point of the rotated element is the rotation center (you can pass transform-origin modification), the x and y axes are on the graph, and the z-axis is the arrow going out from the center (the arrow shooting towards your head from the screen).

In our example, the default image rotateY=0; the mouse pointer is rotateY=-180, a negative number means counterclockwise rotation around the y-axis, a positive number means clockwise rotation; the same applies to the other two axes;

The core of our example is that when the mouse points to: picture (p:first-child), it rotates 180 degrees counterclockwise around the y-axis from 0 degrees to -180 degrees; introduction (p:last-child) starts from 180 Rotate 180 degrees counterclockwise around the y-axis to reach 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.

Perspective, there is a trick for setting the stage (the parent element of the animation).

Transform-style’s 3D changes are of course 3D, there’s nothing much to say.

There are many more attributes related to the 3D effect of css3. If I have the opportunity, I will deliberately use unused ones in future examples~

The above is the entire content of this article. I hope it will be helpful to everyone's learning. Helpful, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

How to use css to stretch and fill the background image to avoid repeated display

How to implement a canvas circular countdown Component

The above is the detailed content of Use CSS3 to achieve image 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

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function