CSS Fundamentals: Beginner’s Guide to Web Styling
Sobre a Aula

Styling Images

 

Hello, everyone! Welcome to the Styling Images lesson.

In this lesson, we will learn how to style images on a web page using CSS.

What is image styling?

Image styling is the process of altering the appearance of images on a web page.

This can include things like the size, position, border, background, and effects of the image.

CSS Properties for Styling Images

There are many CSS properties that can be used to style images. Some of the most common CSS properties for styling images include:

  • Size: Defines the size of the image.
  • Position: Defines the position of the image on the page.
  • Border: Defines a border around the image.
  • Background: Defines a background for the image.
  • Effect: Applies an effect to the image.

Examples

Let’s see some examples of how to use CSS properties to style images.

Example 1:

The following CSS code sets the size of the image with the id image1 to 100px width and 100px height:

#image1 {
  width: 100px;
  height: 100px;
}

Example 2:

The following CSS code sets the position of the image with the id image2 to be centered on the page:

#image2 {
  position: center;
}

Example 3:

The following CSS code sets a border around the image with the id image3 with a width of 1px and red color:

#image3 {
  border: 1px solid red;
}

Example 4:

The following CSS code sets a background for the image with the id image4 with the color green:

#image4 {
  background-color: green;
}

Example 5:

The following CSS code applies a shadow effect to the image with the id image5:

#image5 {
  box-shadow: 0 0 10px 10px black;
}

Note

It’s important to use CSS selectors to control which CSS rules are applied to which images. This will help keep your CSS organized and easy to maintain.

Summary

In this lesson, we learned how to style images on a web page using CSS. We explored some of the most common CSS properties for styling images and saw some examples of how to use these properties.

In the next lesson, we will learn how to style lists.

Want to know more about styling images?

If you want to know more about styling images, here are some additional tips:

  • You can use the width property to define the width of the image, the height property to define the height of the image, and the float property to define whether the image should float to the left or right of the page.
  • You can use the margin property to define the margin around the image, the padding property to define the padding around the image, and the border-radius property to define the rounded corners of the image.
  • You can use the transition property to define an animation that will occur when the image is loaded or when the mouse hovers over it.
Entrar na conversa
Rolar para cima