Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Choosing the Right Transition Properties | Creating Smooth Transitions in CSS
Advanced CSS Techniques

book
Choosing the Right Transition Properties

We can specify any CSS property as a value for the transition-property property. It means that we can apply transition effect to any property.

css
transition-property: ... /* any property */

Let's work with a couple of typical properties which are transitioned. The properties transition-duration, transition-timing-function, and transition-delay will always stay the same. All transitions will react on the cursor hover.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="container">
<div class="item">
<h3>background transition</h3>
<div class="box first-example">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet
maiores molestias, tempora laboriosam quibusdam voluptatem!
</div>
</div>
<div class="item">
<h3>font size transition</h3>
<div class="box second-example">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quo saepe
numquam iure non. Quia, labore!
</div>
</div>
<div class="item">
<h3>border transition</h3>
<div class="box third-example">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Placeat
asperiores facilis doloribus rerum possimus suscipit.
</div>
</div>
<div class="item">
<h3>width transition</h3>
<div class="box forth-example">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis nemo
at repellendus fugit aliquam magni.
</div>
</div>
<div class="item">

Multiple transition properties

We can also use the value all for the transition-property property, which means that all properties will be transitioned.

css
transition-property: all;

In the following example we would like to transition the change of background-color, color, font-weight and font-size properties. Let's check the index.css file:

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil repellat
voluptatum, maxime minus quas neque ipsa odio ad laboriosam earum. Animi,
sed fuga doloremque minima quam quibusdam voluptatem deserunt id.
</div>
</body>
</html>

Also, if we need to add a transition to multiple properties but not to all, we can set them as a value for the transition-property property, separating them with the help of space. For example:

css
transition-property: color border height;

It means that transition will be applied for the color, border, and height properties.

question mark

What does the transition-property property determine?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 2

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

We use cookies to make your experience better!
some-alt