TL;DR — When creating website layouts, you can manipulate the look and behavior of two-dimensional CSS images using various properties.
Using images in CSS
Images in CSS come in two types:
- Plain images added by defining a source (e.g., a URL)
- Dynamically generated images created by using CSS properties (e.g., gradients)
Properties to use with CSS images
In the table below, you can check the most popular properties that you can use to modify the look of your CSS images:
|Draw a border around the image in CSS
|Draw an outline around the image in CSS
|Add space around the image outside the borders
|Add space around the image inside the borders
|Manipulate the height of the image in CSS
|Manipulate the width of the image in CSS
|Manipulate the opacity of the image in CSS
Note: by using the resize property, you can specify whether the user can change the image size in CSS.
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
CSS image sprites explained
An image sprite is essentially a set of multiple images in a single image file. This saves time and bandwidth, as you don't need to issue multiple server requests to load multiple CSS images separately.
Sprites were created by the video game industry, as fast loading time is crucial for players. The main idea is to have one big image and use parts of it as needed. In the example below, you can see how to define a particular part of the sprite you wish to use:
background: url('https://cdn.bitdegree.org/learn/css-image-sprite-3.png?9dd3e0b4') 10px 20px;
CSS images: useful tips
- While using sprites saves time, it does make updating CSS images in your webpage more complicated. Try not to use them where you'll be needing constant graphics updates.
- Assistive technologies do not understand images, so make sure not to use background images for crucial info and include alternative texts for illustrations.