Skip to main content

CSS TRANSFORMATION, and introduction to 3 dimensional approach

CSS3 is awesome, having its own great importance, it is the field which I love more than canvas and webgl.
Before we get started let us see an example which I have written for this tutorial.



Note : If examples don't run 3D transforms, please visit Here

 

It is assumed that you know the basics of css animations, if not then go through CSS2D animations in which we will be covering the basic usage of @keyframes.
To create 3D animation we need to first specify a 3D space, to do that we set property perspective to some value.
The property perspective is set for the parent element so that child elements can enjoy 3D space ;)
perspective:2000px;
The value of perspective tells how far is the object from user or how much is the depth of the 3D space. Think of it as a distance from the viewer to the object. The greater the value, more the distance. perspective: 2000px; yields a subtle 3D effect, as if we are viewing an object from far away through binoculars. perspective: 100px; produces a tremendous 3D effect, like a tiny insect viewing a massive object.
By default, the vanishing point for a 3D space is positioned at the center. You can change the position of the vanishing point with perspective-originproperty.
perspective-origin: 75% 25%;

Getting started


Firstly giving perspective to parent element child can be transformed in 3D. The difference is


Now see the following code 
HTML
<div class="parent">
 <div class="child">
 <h2>Hello world!<h2>
 </div>
</div>
CSS
.parent{
perspective:2000px;
}
.child{
width:200px;
height:200px;
background-color:green;
transform:rotateX(45deg);
}

Hello world!


The transform property is the key to 3d
It consists several functions which are : 
Another point to remember is that when you rotate an element 180deg it shows backface to disable it using backface-visibility:hidden;

In each example below we will use following code by default.
CSS
.ele {
 background: #191919;
 width: 200px;
 height: 200px;
 margin: 0 auto;
}

“rotate()” function

HTML
<div class="ele r"></div>
CSS
.r {
 transform: rotate(30deg);
}




“rotate3d()” function

The first three parameters give the dorection of the vector and the last parameter tells the direction of rotation. A positive value means clockwise and negative value means anticlockwise

HTML
<div class="ele r3d"></div>
CSS
.r3d {
 transform: rotate3d(1,1,1,50deg);
}




“rotateX()” function

HTML
<div class="ele rx"></div>
CSS
.rx {
 transform: rotateX(15deg);
}


“rotateY()” function

HTML
<div class="ele ry"></div>
CSS
.ry {
 transform: rotateY(35deg);
}





“rotateZ()” function

HTML
<div class="ele rz"></div>
CSS
.rz {
 transform: rotateZ(25deg);
}




“scale()” function

HTML
<div class="ele s"></div>
CSS
.s {
 transform: scale(0.8);
}

“scaleX|Y()” function

HTML
<div class="ele sxy"></div>
CSS
.sxy {
 transform: scaleX(1.3);
}

“scaleZ()” function


”scale3d()” function

Visit mdn for better example. Read this stackoverflow answer to understand why to use scaleZ.
HTML
<div class="ele s3d"></div>
CSS
.s3d {
 transform: scale3d(1,1.3,0.8);
}




“translate()” function

HTML
<div class="ele t"></div>
CSS
.t {
 transform: translate(20px,10px);
}


“translateX|Y|Z()” function

HTML
<div class="ele txyz"></div>
CSS
.txyz {
 transform: translateX(30px);
}


“translate3d()” function

View better example at mdn
HTML
<div class="ele t3d"></div>
CSS
.t3d {
 transform: translate3d(-20px,20px,20px);
}



“skew()” function

HTML
<div class="ele skew"></div>
CSS
.skew {
 transform: skew(20deg,15deg);
}




“skewX()” function

HTML
<div class="ele skewx"></div>
CSS
.skewx {
 transform: skewX(10deg);
}




“skewY()” function

HTML
<div class="ele skewy"></div>
CSS
.skewy {
 transform: skewY(15deg);
}




On the way to create animation?
Creating Cube | Creating flying rocket animation

Comments

Popular posts from this blog

CSS animations , flying rocket and rotating cube.

Learning CSS ANIMATIONS CSS animations are great and always been attractive for everyone. Today here I am gonna teach you the animation in which a font-awesome rocket is flying between the clouds and also a 3D rotating cube with perspective. The rocket animation is 2D and made with the help of font-awesome and css transform property. You can download the source file of flying rocket by Here  . For the full tutorial Go to  Rocket animation css tutorial  . Download the source file of rotating cube by  Here  . For full tutorial go to  to this link  .

AJAX - Asynchronous JavaScript and XML

AJAX tutorial AJAX is a developer's dream, because you can:  Update a web page without reloading the page Request data from a server - after the page has loaded Receive data from a server - after the page has loaded Send data to a server - in the background What is AJAX? AJAX = Asynchronous JavaScript And XML.  AJAX is not a programming language.  AJAX just uses a combination of:   A browser built-in XMLHttpRequest object (to request data from a web server) JavaScript and HTML DOM (to display or use the data)  AJAX applications might use XML, plain text or JSON text to transport data. AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. How ajax works 1. An event occurs in a web page (the page is loaded, a button is clicked) 2. An XMLHttpRequest object is created by JavaScript 3. The XMLHttpRequest object sends

Basic CSS , Introduction to properties

CSS is a stylesheet language which runs in users browser to give a rich and decorative user-experience.Currently the latest version available of CSS is 3 and CSS4 is going to arrive with many new features. CSS3 brought many new features like Animations , transforms etc. Today here we are gonna cover all the basic properties used in CSS , which you are gonna use most of the time. The colors supported in CSS can be written in the form of hsba() or hsb() or rgb() or rgba() or hexadecimal or in color names. Color Opacity Background Border Box-shadow Height and Width Position Margins and paddings Display Text-Align Font Properties : Color The color property sets color of the text inside the selector. CSS p { color : red ; } //produces Hello world! CSS p { color : rgb ( 38 , 98 , 67 ) ; } //produces Hello world! Opacity The color property sets opacity of any selected element. It varies from 0 (invisbile) to 1(fully visbile) CSS p {