📜  CSS3 - CSS (1)

📅  最后修改于: 2023-12-03 15:30:12.710000             🧑  作者: Mango

CSS3 - CSS

CSS3 is the latest version of CSS, which stands for Cascading Style Sheets. CSS is a stylesheet language used to describe the presentation of an HTML or XML document. CSS3 includes new features and improvements over CSS, such as animations, transitions, and transforms.

Animations

CSS3 animations allow elements to smoothly transition from one state to another. This can be achieved using the @keyframes rule to define the animation, and the animation property to apply it to an element.

Here is an example of a CSS3 animation:

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.element {
  animation: spin 2s linear infinite;
}

This code will create an animation that rotates an element 360 degrees over the course of two seconds, and then repeats infinitely.

Transitions

CSS3 transitions allow elements to smoothly transition from one style to another. This can be achieved using the transition property to specify which properties should be transitioned, and the transition-duration property to specify the duration of the transition.

Here is an example of a CSS3 transition:

.element {
  background-color: red;
  transition: background-color 1s ease;
}

.element:hover {
  background-color: blue;
}

This code will create an element with a red background color that transitions to blue when hovered over. The transition will last for one second and will use an ease timing function to create a smooth transition.

Transforms

CSS3 transforms allow elements to be transformed in different ways, such as scaling, rotating, and skewing. This can be achieved using the transform property to specify the type of transformation to apply.

Here is an example of a CSS3 transform:

.element {
  transform: scale(1);
}

.element:hover {
  transform: scale(1.5);
}

This code will create an element that scales up by a factor of 1.5 when hovered over.

In conclusion, CSS3 provides powerful tools for creating engaging and dynamic web pages. Animations, transitions, and transforms can add a sense of interactivity to your website and enhance the user experience.