search
HomeWeb Front-endCSS TutorialCSS3 three-dimensional deformation to realize three-dimensional square

CSS3 three-dimensional deformation to realize three-dimensional square

Jun 28, 2018 am 10:51 AM
css3three dimensionaldeformation

This article mainly introduces you to the CSS3 method of using three-dimensional deformation to realize three-dimensional blocks. The article gives a complete example code. Interested friends can run it themselves and see the effect. Only by doing it yourself can you get better. Let’s take a look at the learning below.

Preface

Three-dimensional transformations use the same properties based on two-dimensional transformations. If you are familiar with two-dimensional transformations, you will find that the functions of 3D transformations and 2D transforms function similarly. The biggest difference between 3D deformation and 2D deformation is that the reference coordinate axes are different. The coordinate axes of 2D deformation are planar, with only X and Y axes, while the coordinate axes of 3D deformation are composed of three axes: X, Y, and Z. In the three-dimensional space, the positive direction of the X-axis is toward the right, the positive direction of the Y-axis is downward, and the positive direction of the Z-axis is toward the outside of the screen.

The static rendering is as follows:

##Example code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <title>CSS3三维变形</title>
        <!--  -->
        <style type="text/css">
         * {
          margin: 0;
          padding: 0;
         }
         
         .box {
          position:relative;
          top: 100px;
          width:300px;
          height: 300px;
          margin: 0 auto;
          background-color: #ccc;
          /*
           透视效果
           越大透视距离越平面,反之亦然
          */
          perspective:800px;
         }
         .content {
          /*3d视图*/
          transform-style: preserve-3d;
          /*过度动画*/
          transition: all 3s linear;
          width:200px;
          height: 200px;
          position: absolute;
          top: 50px;
       left: 50px;
         }
         /*
          经过顺时针旋转
         */
         .content:hover {
          transform: rotateX(180deg) rotateY(180deg);
         }
         /*
          方块公共样式
         */
         .side {
          position: absolute;
       height: 200px;
       width: 200px;
       border: 2px solid #000;
       background: rgba(0,0,0,0.3);
       color: #fff;
       line-height: 200px;
       font-size: 30px;
       font-weight: bold;
       text-align: center;
       text-shadow: 0 -1px 0 rgba(0,0,0,0.2);
         }
         /*
          前
         */
         .side1 {
           transform: translateZ(100px);
         }
         /*
          后
         */
         .side2 {
          transform: rotateX(180deg) translateZ(100px);
         } 
         /*
          左
         */
         .side3 {
          transform: rotateY(-90deg) translateZ(100px);
         }
         /*
          右
         */
         .side4 {
          transform: rotateY(90deg) translateZ(100px);
         }
         /*
          上
         */
         .side5 {
          transform: rotateX(90deg) translateZ(100px);
         }
         /*
          下
         */
         .side6 {
          transform: rotateX(-90deg) translateZ(100px);
         }
        </style>
    </head>
    <body>
     <!-- begin -->
     <p class="box">
      <p class="content">
       <p class="side side1">1</p>
             <p class="side side2">2</p>
             <p class="side side3">3</p>
             <p class="side side4">4</p>
             <p class="side side5">5</p>
             <p class="side side6">6</p>
      </p>
     </p>
     <!-- end -->
    </body>
</html>

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

Related recommendations:

About the usage of css3 image border border-image

About 20 loading animations produced by CSS3 Effect

About the method of drawing hexagons in CSS3

The above is the detailed content of CSS3 three-dimensional deformation to realize three-dimensional square. 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
Two Images and an API: Everything We Need for Recoloring ProductsTwo Images and an API: Everything We Need for Recoloring ProductsApr 15, 2025 am 11:27 AM

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

Weekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsWeekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsApr 15, 2025 am 11:19 AM

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

Options for Hosting Your Own Non-JavaScript-Based AnalyticsOptions for Hosting Your Own Non-JavaScript-Based AnalyticsApr 15, 2025 am 11:09 AM

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

It's All In the Head: Managing the Document Head of a React Powered Site With React HelmetIt's All In the Head: Managing the Document Head of a React Powered Site With React HelmetApr 15, 2025 am 11:01 AM

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What is super() in JavaScript?What is super() in JavaScript?Apr 15, 2025 am 10:59 AM

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

Comparing the Different Types of Native JavaScript PopupsComparing the Different Types of Native JavaScript PopupsApr 15, 2025 am 10:48 AM

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

Why Are Accessible Websites so Hard to Build?Why Are Accessible Websites so Hard to Build?Apr 15, 2025 am 10:45 AM

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

The `hidden` Attribute is Visibly WeakThe `hidden` Attribute is Visibly WeakApr 15, 2025 am 10:43 AM

There is an HTML attribute that does exactly what you think it should do:

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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