These days technology is growing and improving simultaneously without waiting for us. UI is being improved day by day. So, normal HTML designing is not enough for a frontend developer, he or she needs more to make a UI more interactive; i.e., switch to 3D designing. So in that way "perspective" view is the property that can help us and others.
What is the Perspective?
It's a way through which we can make or draw 3d objects into a 2d surface by adjusting their color pattern, shadow, depth and shapes with respect to other objects. Now, these days some websites have started using Perspective and it's mobile-friendly too. Perspective is used in drawing, photography, video making, and game design. Perspective originally meant to look through or to look at an object. The meaning of Perspective in art involves the creation of depth. So, we convey a sense of reality with space and depth on something which has none.
So, in reality, Perspective already exists where no kind of surface is involved.
What is ViewPoint?
Viewpoint is the position we are seeing things from; with that in mind, perspective refers to viewpoint and position.
The faraway objects are small and nearby objects are large and overlap the far away objects. So, in that way, the meaning of Perspective is to set the viewpoint that best communicates a subject to the audience.
So what is the use of Perspective in design?
Using Perspective, we create space and a sense of depth in our UI development. Keeping that in mind we create a better UI. Even the things that don't really look like real to some degree. So, regardless if you are a UX-UI developer or not you need to understand how the audience sees it and this is something all professionals in visual arts deal with.
Parent has CSS properties
- "transform-style: preserve-3d",
- "transform: perspective(n px);
- where 0 < n < infinity
The greater the value of n , the greater the distance from object
Output
The more you change the values of rotate and perspective, the more effect you see.
Here is code for a simple block animation with Simple Perspective properties,
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>Page Title</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <style>
- html, body{
- font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
- box-sizing: border-box;
- margin: 0;
- padding: 0;
- }
-
- .flex-pc{
- display: flex;
- justify-content: center;
- align-items: center;
- }
-
- .grand-parent{
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- }
-
- .parent{
- position: relative;
- height: calc( 100vh - 94px );
- transform: rotateX(0deg) rotateY(0deg);
- transform-style: preserve-3d;
- transition: 0.3s all ease-in-out;
- }
-
- .child{
- background-color: #00808080;
- width: 400px;
- height: 400px;
- display: flex;
- justify-content: center;
- align-items: center;
- position: absolute;
- font-size: 84px;
- color: white;
- box-shadow: inset 0px 0px 143px 0px black;
- }
-
- .child.front{
- transform: translateZ(200px) ;
- }
-
- .child.back{
- transform: rotateX(-180deg) translateZ(200px) ;
- }
-
- .child.left{
- transform: rotateY(90deg) translateZ(200px) ;
- }
-
- .child.right{
- transform: rotateY(-90deg) translateZ(200px) ;
- }
-
- .child.up{
- transform: rotateX(90deg) translateZ(200px) ;
- }
-
- .child.down{
- transform: rotateX(-90deg) translateZ(200px) ;
- }
- </style>
- </head>
- <body>
- <h1>Prespective Styling <strong>3D</strong></h1>
- <hr>
- <div class="grand-parent">
- <div class="parent flex-pc">
- <div class="child down">6</div>
- <div class="child up">5</div>
- <div class="child right">4</div>
- <div class="child left">3</div>
- <div class="child back">2</div>
- <div class="child front">1</div>
- </div>
- </div>
- <script>
- cube = document.querySelector(".grand-parent .parent");
- let valX = 0;
- let valY = 0;
-
- setInterval(()=>{
- cube.style.transform=`rotateX(${valX}deg) rotateY(${valY}deg)`;
- valX+=5;
- valY+=5;
- }, 50);
- </script>
- </body>
- </html>
Output
The more you learn, the more you become an expert. It depends on the developer what the user's point of view for the UI is.