Background and Borders Flashcards
What are backgrounds in web development?
Backgrounds are the areas behind the content of an element, which can be styled with colors, images, gradients, and more.
How can you set a background color in CSS?
You can set a background color using the ‘background-color’ property.
What is the purpose of borders in web development?
Borders are used to define the edges of an element and can enhance the visual structure of a webpage.
How can you set a border in CSS?
You can set a border using the ‘border’ property, which can specify width, style, and color.
What is a background image?
A background image is an image that is displayed behind the content of an element.
How can you set a background image in CSS?
You can set a background image using the ‘background-image’ property.
What is the ‘background-repeat’ property?
The ‘background-repeat’ property determines how a background image is repeated within an element.
What does the ‘background-position’ property do?
The ‘background-position’ property specifies the position of a background image within an element.
What is the ‘border-radius’ property?
The ‘border-radius’ property is used to create rounded corners for an element’s border.
What CSS property is used to set the background color of an element?
The background-color property is used to define an element’s background color.
Example:
div { background-color: lightblue; }
How do you set an image as the background of an element?
Use the background-image property.
Example:
div { background-image: url('image.jpg'); }
What values can the background-repeat property take?
-
repeat (default)
– Repeats the image both horizontally and vertically. -
no-repeat
– Displays the image once, no repeating. -
repeat-x
– Repeats horizontally. -
repeat-y
– Repeats vertically. -
round
– Adjusts image size to fit the element. -
space
– Distributes the image evenly without cropping.
How do you make a background image cover the entire element without stretching?
Use background-size: cover;
div { background-size: cover; }
Ensures the image covers the element while maintaining its aspect ratio.
What is the difference between background-size: contain;
and background-size: cover;
?
contain
– Ensures the entire image is visible, but may leave empty space.
cover
– Fills the entire element, but may crop parts of the image.
How do you set a background image to be fixed while scrolling?
Use background-attachment: fixed;
div { background-attachment: fixed; }
This makes the background stay in place while the content scrolls.
How do you make a semi-transparent background color in CSS?
Use rgba()
or opacity.
Example using rgba()
:
div { background-color: rgba(0, 0, 0, 0.5); }
This sets a black background at 50% opacity.
What are the different border styles available in CSS?
solid
– A single solid linedashed
– A dashed linedotted
– A dotted linedouble
– Two solid linesgroove
– A 3D grooved effectridge
– A 3D ridged effectinset
– A 3D inset effectoutset
– A 3D outset effectnone
– No border
How do you round the corners of a border?
Use border-radius
.
Example:
div { border-radius: 10px; }
This makes the corners rounded with a 10px radius.
How do you create a circular element using border-radius
?
Set border-radius
to 50% and ensure the width and height are equal.
.circle { width: 100px; height: 100px; border-radius: 50%; }
What is the difference between border
and outline
?
border
affects the element’s size and is part of the box model.
outline
does not affect the size and does not take up space.
div { border: 2px solid black; outline: 3px dashed red; }
How do you create a border with different colors on each side?
Use border-top
, border-right
, border-bottom
, and border-left
.
div { border-top: 2px solid red; border-right: 2px solid blue; border-bottom: 2px solid green; border-left: 2px solid yellow; }
How do you apply multiple background images to an element?
Use a comma-separated list in background-image
.
div { background-image: url('image1.png'), url('image2.png'); }
The first image is on top, and the second is underneath.
How do you create a radial gradient background?
Use background: radial-gradient()
.
div { background: radial-gradient(circle, red, yellow, green); }
How do you add space between a border and the content inside an element?
Use padding
.
div { border: 2px solid black; padding: 20px; }
How do you create a box with a shadow effect?
Use box-shadow
.
div { box-shadow: 5px 5px 10px gray; }
This adds a gray shadow to the bottom-right.