Crazy 3D Rotation Effect Using CSS Only

Lun Dev
4 Jul 202407:39

Summary

TLDRThis tutorial video demonstrates how to create a 3D rotating soda bottle effect using only CSS. The presenter guides viewers through the process of selecting an image, manipulating it with CSS properties like 'aspect ratio', 'background blend mode', and 'mask image', to achieve a realistic soda mockup. The video also covers creating hover effects for rotation and layering soda bottles to transform one into another, showcasing advanced CSS techniques for web design.

Takeaways

  • 🎨 The video demonstrates creating a 3D rotating soda effect using only CSS.
  • πŸ–ΌοΈ It begins by selecting a suitable soda mockup image from a free image source.
  • βœ‚οΈ The selected image is edited to remove the background and cropped to fit the design.
  • 🌐 The HTML structure includes a 'banner' class containing 'product' classes for each soda image.
  • 🎨 CSS is used to style the banner, set the height, and manage overflow and positioning.
  • πŸ”„ The 'soda' class utilizes the mockup image with specific width and height settings and an aspect ratio for responsiveness.
  • πŸ–ΌοΈ The 'background-blend-mode' property with 'multiply' value is used to blend the product cover image with the mockup.
  • 🎭 The 'mask-image' property is introduced to crop the content of an element according to the shape of the inserted image.
  • πŸ”„ A hover effect is created on the product to make the soda appear as if it's rotating by changing the 'background-position'.
  • πŸ”§ CSS variables are used in HTML to store image paths, simplifying the process of creating multiple soda bottles.
  • πŸ“ The design includes additional decorative elements like 'rock' images positioned absolutely within the banner.
  • πŸ”„ Interactive hover effects are applied to the decorative elements to move them when the user hovers over the product.

Q & A

  • What is the main topic of the video?

    -The video demonstrates how to create a 3D rotating soda effect using only CSS, without the need for JavaScript.

  • What are the primary elements needed to create the soda bottle effect?

    -The primary elements are the soda bottle image and its cover photo, which are manipulated using CSS properties.

  • Why is the aspect-ratio property important in this tutorial?

    -The aspect-ratio property ensures that the height of the soda bottle image automatically adjusts based on its width, which is crucial for maintaining proper proportions when the design is responsive.

  • How does the background-blend-mode property contribute to the effect?

    -The background-blend-mode property with the 'multiply' value is used to merge the cover image with the soda mockup image, making it appear as though the cover is pasted onto the soda bottle.

  • What is the purpose of the mask-image property in this context?

    -The mask-image property is used to crop the soda bottle image to fit within the boundaries of the mockup, ensuring that only the desired parts of the image are visible.

  • How is the rotation effect of the soda bottle achieved using CSS?

    -The rotation effect is created by changing the left position of the background image within the element using the CSS transition property. This simulates the appearance of the soda bottle rotating.

  • Why does the author recommend against manually adjusting the height value of the soda image?

    -Manually adjusting the height value can cause issues when the design is responsive. Instead, using the aspect-ratio property ensures that the image's height adjusts automatically based on its width.

  • What additional decorations are added to the banner, and how are they positioned?

    -The banner includes decorative rock images, which are positioned using the position absolute property and the inset zero shorthand, making them the same size as the banner and overlaying it.

  • How does the video ensure that the second soda bottle appears only when the user hovers over the product?

    -The second soda bottle is initially hidden using CSS. When the user hovers over the product, the second soda bottle is shown, creating the effect of the soda rotating and turning into another bottle.

  • What CSS properties are highlighted as being new or less commonly known in this video?

    -The video highlights the aspect-ratio, background-blend-mode, and mask-image properties as newer or less commonly known CSS features that are useful for creating advanced visual effects.

Outlines

00:00

πŸ§ͺ Creating a 3D Rotating Soda Effect with CSS

In this paragraph, the speaker introduces a video tutorial about creating a 3D rotating soda bottle effect using only CSS. They mention that a viewer asked if the effect could be done without JavaScript, and they confirm it can. The speaker explains that the tutorial will guide the audience through making the soda bottle rotate and transition into another using CSS. They also emphasize the importance of subscribing to the channel for more programming and web design content. The process begins by selecting a suitable soda bottle image from Freepik, editing it to remove the background, and then implementing the effect with HTML and CSS.

05:00

🎨 Designing and Animating Multiple Soda Bottles with CSS

This paragraph delves into the next steps of the tutorial, where the speaker explains how to create and animate multiple soda bottles using CSS. Instead of hardcoding the image directly into the CSS, they suggest using a variable in HTML to manage the image path, allowing for easier updates and multiple products. The speaker continues by explaining how to align and overlap the soda bottles using CSS Flexbox and absolute positioning. Additional decorative elements, such as rocks, are also added to the design. Finally, they discuss how to create the illusion of one soda bottle transforming into another using hover effects, new CSS properties like aspect-ratio, background-blend-mode, and mask-image. The paragraph concludes with a reminder to like and subscribe for more content.

Mindmap

Keywords

πŸ’‘3D Slider

A 3D Slider is a web design element that allows for interactive, three-dimensional navigation or display of content. In the video, the 3D Slider is used to create a rotating soda effect, simulating the motion of a soda bottle turning into another, which is a central theme of the tutorial.

πŸ’‘CSS

CSS, or Cascading Style Sheets, is a style sheet language used for describing the presentation of a document written in HTML or XML. The video focuses on demonstrating how to achieve a 3D rotating effect using only CSS, showcasing its capabilities for creating visually dynamic web elements.

πŸ’‘Soda Bottle

The 'soda bottle' is the primary object in the video's demonstration. It represents the subject of the 3D rotating effect. The script describes how to use CSS to create the illusion of a soda bottle turning into another, which is the main visual effect being taught.

πŸ’‘Rotating Effect

The rotating effect is a visual technique used in the video to simulate the motion of a soda bottle spinning. It is achieved through CSS properties that manipulate the background image of the soda bottle, creating a dynamic and engaging user experience.

πŸ’‘Background Image

In web design, a background image is a graphic that is placed behind other content on a webpage. The script explains how to use a soda mockup as a background image and manipulate it to create the rotating effect, which is a key part of the 3D Slider demonstration.

πŸ’‘Aspect Ratio

The aspect ratio is the proportional relationship between the width and height of an image or screen. The video mentions using the aspect ratio property in CSS to ensure that the mockup image maintains its proportions, which is crucial for responsive design.

πŸ’‘Background Blend Mode

The background blend mode is a CSS property that allows elements to have a composite effect when layered. In the script, it is used to blend the soda mockup with the product cover image, creating a more realistic and visually appealing effect.

πŸ’‘Mask Image

A mask image in CSS is used to hide or reveal parts of an element based on the shape of another image. The video script describes using a mask image to crop the product cover to the shape of the soda mockup, which is essential for achieving the final visual effect.

πŸ’‘Hover Effect

The hover effect is a common interaction in web design where elements change appearance when a user hovers over them with a cursor. The video demonstrates creating a hover effect that triggers the soda bottle to rotate, enhancing the interactivity of the 3D Slider.

πŸ’‘Responsive Design

Responsive design is an approach to web design that makes web pages render well on different devices and window or screen sizes. The video emphasizes the importance of using properties like aspect ratio to ensure the soda bottle's design is responsive and looks good on all devices.

πŸ’‘Variable

In the context of the video, a variable is used in CSS to store and reuse values, such as image paths. The script mentions declaring a variable in HTML for the image path and then using it in CSS, which simplifies the process of creating multiple soda products in the design.

Highlights

Creating a 3D slider with a rotating soda effect using only CSS is possible.

The video demonstrates how to create the soda bottle rotation effect with CSS.

A soda bottle consists of two main parts: the bottle and its cover.

Using a suitable image for the soda mockup from a free resource.

Editing the image to remove the background and crop excess space.

Downloading the image in PNG format for CSS manipulation.

Setting up the HTML structure with classes for the banner and products.

CSS styling includes positioning, sizing, and hiding overflow for the banner.

Using CSS variables for the soda mockup image to ensure visibility and responsiveness.

The importance of maintaining aspect ratio for responsive design.

Implementing the 'background-blend-mode' property to merge images.

Utilizing 'mask-image' to crop content to the shape of the mockup.

Creating a hover effect to rotate the soda bottle using CSS transitions.

Using CSS variables to dynamically change images for different soda products.

Styling additional elements like decorative rocks with absolute positioning.

Creating interactive hover effects for decorative elements to enhance visual appeal.

Hiding and showing soda bottles on hover to create a rotation effect.

Introduction of new CSS properties like 'aspect-ratio', 'background-blend-mode', and 'mask-image'.

The video aims to be useful for learning advanced CSS techniques for web design.

Transcripts

play00:00

recently some of you have watched my old

play00:02

video on the topic of creating a 3D

play00:04

slider with a rotating soda effect using

play00:07

JavaScript he left a comment is it

play00:09

possible to create it with CSS only

play00:13

really but we

play00:16

can in this video I will show you how to

play00:19

create the effect of a soda bottle

play00:21

rotating and turning into another soda

play00:25

bottle using only CSS because you know I

play00:29

won't turn any questions it's just that

play00:31

I need some time to create a video to

play00:33

answer those questions if you find it

play00:35

interesting don't forget to like And

play00:36

subscribe to the channel to continuously

play00:38

update new interesting videos about

play00:40

programming and web design thank you

play00:43

very much everyone and now let's get

play00:47

started a bottle of soda is made from

play00:50

two ingredients the bottle and its cover

play00:52

photo for the cover photo you can use

play00:54

any photo but with martial arts we need

play00:56

to find a suitable image first I will go

play00:58

to free pick here you just need to enter

play01:01

the keyword soda mockup there will be

play01:03

many results for you please choose the

play01:05

appropriate image here click to select

play01:08

remove

play01:10

background then click on edit select

play01:13

crop feature cut out all excess space on

play01:15

the

play01:17

photo once completed we just need to

play01:20

download this image in PNG format after

play01:22

we have the image we will now proceed

play01:24

with the code in HTML I create a banner

play01:27

class in the banner I have a product

play01:29

class to contain products each soda

play01:30

class will represent a product image in

play01:33

CSS the banner will have a height equal

play01:35

to the height of the device screen with

play01:37

overflow hidden elements that fall out

play01:39

of the frame will be removed use

play01:41

position to position it for the product

play01:44

I will give the background a red color

play01:45

to help us see it more easily also

play01:48

declare width and height use position to

play01:50

easily move positions 170 pixels from

play01:54

bottom combine left and translate text

play01:56

to center it with c Index to ensure it

play01:59

is not overlapping by another element

play02:01

the transition attribute is used to

play02:03

specify the time to create the effect

play02:04

when the user hovers next is the focus

play02:07

of this article the soda class this

play02:10

class will use a background that is the

play02:12

soda mockup image that we searched for

play02:14

at the beginning of the video note that

play02:16

I only decare the background not the

play02:18

background image this background will

play02:20

have a size equal to 100% of the

play02:22

element's height width 280 pixels with

play02:26

this type of image we need to have width

play02:27

and height to ensure the mockup image is

play02:29

visible enough many people will try to

play02:32

change the value of height to find the

play02:33

right size I advise you not to do so

play02:37

because when we're sponsive the width

play02:38

value changes you will once again find a

play02:40

different height value instead use

play02:43

aspect ratio and find an appropriate

play02:45

ratio between width and height at this

play02:47

point the system will rely on the ratio

play02:49

declared in aspect ratio to find the

play02:51

height value for you that means when

play02:53

implementing responsiveness you don't

play02:55

need to waste time finding the height

play02:57

value anymore after completing the

play02:59

mockup creation step I continue to

play03:01

insert an image the product cover image

play03:03

in front of the mockup image it looks

play03:06

really fake do not worry in CSS we have

play03:10

a background blend mode property with

play03:12

the value multiply the mockup image will

play03:15

merge with the mockup image this makes

play03:17

it feel like this cover image is

play03:19

actually pasted onto the mockup image

play03:22

but not enough we will need to erase the

play03:24

areas where the image is outside the

play03:25

mockup don't worry because we have a new

play03:28

property from CSS which is mask image

play03:31

when we insert any PNG image into the

play03:33

mask image then all content inside the

play03:35

element will be cropped according to the

play03:37

shape of the inserted image for example

play03:40

here I am inserting a star image so what

play03:43

happens if I insert into the mask image

play03:45

the soda mockup image specify the size

play03:48

to match the background size at this

play03:50

point all images outside the mockup area

play03:53

have been

play03:56

deleted the next thing is how to make

play03:58

this soda bottle rotate let's analyze

play04:00

together when we insert images into the

play04:02

mockup actually this image has been

play04:04

repeated infinitely we don't see it

play04:06

because it is outside the element size

play04:08

range so if I now want to see a

play04:10

different area of the image I just need

play04:12

to move it to the left a certain

play04:14

distance right we'll reproduce it in CSS

play04:17

in the background property in fact there

play04:19

are two values that represent the left

play04:21

and top distance of the image from the

play04:22

element the default value is zero so if

play04:25

you change this value the position of

play04:27

the image will also change now when I

play04:29

try to to create a hover effect on the

play04:31

product the soda will rotate as

play04:33

follows on the product I declare the

play04:35

variable left to store the left position

play04:37

value of the cover image and replace it

play04:39

here use the transition property to make

play04:42

the image rotate more

play04:44

smoothly when the user hovers over the

play04:46

product the left value changes causing

play04:48

the image position to change as well

play04:50

making the eye feel like it is rotating

play04:52

so that's how we can create a 3D

play04:54

rotating soda effect with just CSS now I

play04:58

will continue designing the remaining

play05:00

design the fact that I inserted the

play05:02

image directly into the CSS made it

play05:04

impossible for me to quickly create

play05:06

another bottle of soda so instead of

play05:08

directly inserting the image here I will

play05:10

declare a variable in HTML with the main

play05:13

value being the image path at this point

play05:16

on the CSS side I just need to call that

play05:18

variable to use back to HTML I created a

play05:22

second soda product and of course it

play05:24

will have a different cover art to keep

play05:26

it in the same row I will use display

play05:28

Flex

play05:30

to have these two elements overlap each

play05:32

other I will use position absolute

play05:35

combine left and translate text to

play05:37

Center the element when the user hovers

play05:39

over the product I use translady to move

play05:41

it up 120

play05:48

pixels for additional decoration in the

play05:50

banner I created a rock class inside

play05:52

there are three images of decorative

play05:54

rocks note that rock is not a child of

play05:57

the product class with rock I use

play06:00

position absolute and with inset zero it

play06:02

will be the same size as the banner and

play06:04

overlay the banner for each image inside

play06:07

I also use position absolute to easily

play06:09

move the position with the time to

play06:12

create the effect when the user hovers

play06:14

at 7 Seconds the first image will have a

play06:16

height of 170

play06:18

pixels left translate Tex minus

play06:23

50% - 30 pixels from bottom because rock

play06:27

is not a product so in catching the

play06:29

hover of on the product we must use

play06:33

has at this point I move it 50 pixels

play06:38

down the remaining two images are

play06:41

similar we set the height choose the

play06:43

position for it then catch the event

play06:45

when the user hovers to move the

play06:46

position finally do you remember that

play06:48

our product has two sodas lying on top

play06:50

of each other in the default State I

play06:52

will hide the second soda when the user

play06:55

hovers in the second soda will show up

play06:57

and create the effect of the soda

play06:59

rotating and turning into another

play07:02

soda and that's what I want to teach

play07:04

everyone in this video we've covered a

play07:06

lot of new CSS properties like aspect

play07:09

ratio background blend mode mask image

play07:12

hope this video will be useful if you

play07:15

find it interesting don't forget to like

play07:16

And subscribe to watch more interesting

play07:18

videos every day and if you have any

play07:20

questions or suggestions for the next

play07:22

topic don't hesitate to leave a comment

play07:25

thank you everyone so much for watching

play07:27

and supporting my channel see you

play07:29

everyone in the next video

play07:33

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
CSS Effects3D SliderSoda BottleWeb DesignTutorialResponsiveBackground BlendMask ImageHover EffectAspect Ratio