Background and blend modes Flashcards
What does background-image
CSS property do?
The background-image
property in CSS is used to set one or more background images for an element. It allows you to specify an image file (usually in formats like JPEG, PNG, GIF, or SVG) to be displayed as the background of the specified element. The images are layered on top of each other, with the first image in the list displayed on top and the last image at the bottom.
“background-image - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What is the syntax of the background-image
CSS property?
Each background image is specified either as the keyword none
or as an <image>
value.
To specify multiple background images, supply multiple values, separated by a comma
:
background-image: linear-gradient( to bottom, rgba(255, 255, 0, 0.5), rgba(0, 0, 255, 0.5) ), url("catfront.png"); /* Global values */ background-image: inherit; background-image: initial; background-image: revert; background-image: revert-layer; background-image: unset;
Valuesnone
- Is a keyword denoting the absence of images.
<image>
- Is an <image>
denoting the image to display. There can be several of them, separated by commas
, as multiple backgrounds are supported.
“background-image - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What does background-position
CSS property do?
The background-position
CSS property is used to specify the initial position of a background image within an element. It determines how the image is aligned within the element, either using keywords, percentages, or length values to define the position.
“background-position - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What is the syntax of the background-position
CSS property?
The background-position
property can accept one or two values:
-
One value: This value sets the horizontal position (
left
,center
, orright
) or the vertical position (top
,center
, orbottom
) of the background image. If only one value is provided, the other axis defaults tocenter
. -
Two values: The first value sets the horizontal position (
left
,center
,right
, or a specific length/percentage), and the second value sets the vertical position (top
,center
,bottom
, or a specific length/percentage).
Here’s the syntax for the background-position property:
background-position: value1 value2;
Examples:
1.- Using keywords:
/* Position the background image at the center horizontally and top vertically */ div { background-position: center top; }
2.- Using percentages:
/* Position the background image 50% from the left edge and 25% from the top edge */ div { background-position: 50% 25%; }
3.- Using length values:
/* Position the background image 20px from the left edge and 10px from the top edge */ div { background-position: 20px 10px; }
“background-position - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What does the background-size
CSS property do?
The background-size
CSS property is used to specify the size of a background image within an element. It allows you to control how the image is scaled and stretched to fit the element, either using keywords, percentages, or length values to define the dimensions.
Spaces not covered by a background image are filled with the background-color
property, and the background color will be visible behind background images that have transparency/translucency
To specify the size of multiple background images, separate the value for each one with a comma.
“background-size - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What is the syntax of the background-size
CSS property do?
The background-size
property can accept one or two values:
- One value: This value sets the width of the background image. The height is then automatically calculated to maintain the image’s aspect ratio. If the value is a keyword, it applies to both width and height.
- Two values: The first value sets the width, and the second value sets the height of the background image. Providing specific dimensions can distort the image if the aspect ratio is not maintained.
Keywords available for background-size
:
-
auto
: The image maintains its original size (default). -
cover
: Scales the image, maintaining its aspect ratio, to cover the entire element. One dimension may be cropped if the aspect ratios of the element and the image differ. -
contain
: Scales the image, maintaining its aspect ratio, to fit within the element. Empty space may be visible if the aspect ratios of the element and the image differ.
Here’s the syntax for the background-size
property:
background-size: value1 value2;
Examples:
1.- Using keywords:
/* Scale the background image to cover the entire element */ background-size: cover;
2.- Using percentages:
/* Scale the background image to be 50% of the element's width and 100% of its height */ background-size: 50% 100%;
3.- Using length values:
/* Set the background image width to 200px and height to 100px */ background-size: 200px 100px;
4.- Using one-value syntax
/* Set the background image width to 50% (height becomes 'auto') */ background-size: 50%;
5.- Setting the size of multiple backgrounds (comma separated)
/* Multiple backgrounds */ background-size: auto, auto; /* Not to be confused with `auto auto` */ background-size: 50%, 25%, 25%; background-size: 6px, auto, contain;
“background-size - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 4, 2023.
What does background-repeat
CSS property do?
The background-repeat
property in CSS is used to control the repeating behavior of a background image within an element. By default, background images are tiled (repeated) both horizontally and vertically to fill the entire element.
“background-repeat - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What is the syntax of the background-repeat
CSS property?
The background-repea
t property allows you to modify this behavior by specifying whether the image should be repeated, and in which direction(s).
The property accepts the following values:
-
repeat
: The default value. The background image is repeated both horizontally and vertically. -
repeat-x
: The background image is repeated only horizontally. -
repeat-y
: The background image is repeated only vertically. -
no-repeat
: The background image is not repeated, and it will be displayed only once, covering the area according to thebackground-size
property.
Example:
div { background-image: url('path/to/your/image.png'); background-repeat: no-repeat; }
In this example, the background image will be displayed once, without repeating, within the specified div element.
“background-repeat - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What does the background-origin
CSS property do?
The background-origin
CSS property is used to determine the background positioning area, which is the area within an element where the background image is positioned and/or clipped. This property works together with other background-related properties such as background-position
, background-clip
, and background-size
.
“background-origin - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What is the syntax of the background-origin
CSS property do?
The background-origin
property accepts the following values:
-
padding-box
(default): The background position is relative to the element’s padding box. The background image will be placed within the padding box, and it will be clipped if it extends beyond the padding. -
border-box
: The background position is relative to the element’s border box. The background image will be placed within the border box, and it will be clipped if it extends beyond the border. -
content-box
: The background position is relative to the element’s content box. The background image will be placed within the content box, and it will be clipped if it extends beyond the content.
Example:
div { background-image: url('path/to/your/image.png'); background-origin: content-box; }
In this example, the background image will be positioned within the content box of the specified div element, and it will be clipped if it extends beyond the content box.
“background-origin - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What does the background-clip
CSS property do?
The background-clip
CSS property is used to determine the area within an element where the background image, color, or both, will be clipped or trimmed. In other words, it defines the area beyond which the background will not be visible. This property works in conjunction with other background-related properties, such as background-origin
and background-position
.
“background-clip - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What is the syntax of the background-clip
CSS property do?
The background-clip
property accepts the following values:
-
border-box
(default): The background is clipped to the element’s border box. The background image and/or color will be visible up to the border edges. -
padding-box
: The background is clipped to the element’s padding box. The background image and/or color will be visible up to the padding edges but won’t be visible in the border area. -
content-box
: The background is clipped to the element’s content box. The background image and/or color will be visible only within the content area, not extending to the padding or border areas.
Example:
div { background-image: url('path/to/your/image.png'); background-color: lightblue; background-clip: padding-box; }
In this example, both the background image and the light blue background color will be clipped to the padding box of the specified div element. They will not extend to the border area.
“background-clip - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What does the background-attachment
CSS property do?
The background-attachment
CSS property is used to determine whether a background image should scroll along with the content or remain fixed in the viewport when the user scrolls the page. This property only affects background images and not background colors.
“background-attachment - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What is the syntax of the background-attachment
CSS property do?
The background-attachment
property accepts the following values:
-
scroll
(default): The background is fixed relative to the element itself and does not scroll with its contents. (It is effectively attached to the element’s border.) -
fixed
: The background image remains fixed in the viewport and does not scroll with the content. -
local
: The background is fixed relative to the element’s contents. If the element has a scrolling mechanism, the background scrolls with the element’s contents, and the background painting area and background positioning area are relative to the scrollable area of the element rather than to the border framing them.
Example:
div { background-image: url('path/to/your/image.png'); background-attachment: fixed; }
In this example, the background image in the specified div element will remain fixed in the viewport and will not scroll along with the content of the element.
“background-attachment - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.
What does the background-color
CSS property do?
The background-colo
r CSS property is used to set the background color of an HTML element. This property defines the color that will be displayed behind the content, padding, and border of the element. The background color can be specified using predefined color names, RGB, RGBA, HSL, HSLA, or hexadecimal color codes.
It’s worth noting that if an element has both a background color and a background image, the background color will be displayed underneath the background image. If the background image is partially or fully transparent, the background color will be visible through the transparent areas of the image.
“background-color - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 5, 2023.