Background and Borders Flashcards

1
Q

What are backgrounds in web development?

A

Backgrounds are the areas behind the content of an element, which can be styled with colors, images, gradients, and more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you set a background color in CSS?

A

You can set a background color using the ‘background-color’ property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of borders in web development?

A

Borders are used to define the edges of an element and can enhance the visual structure of a webpage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you set a border in CSS?

A

You can set a border using the ‘border’ property, which can specify width, style, and color.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a background image?

A

A background image is an image that is displayed behind the content of an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you set a background image in CSS?

A

You can set a background image using the ‘background-image’ property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the ‘background-repeat’ property?

A

The ‘background-repeat’ property determines how a background image is repeated within an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the ‘background-position’ property do?

A

The ‘background-position’ property specifies the position of a background image within an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the ‘border-radius’ property?

A

The ‘border-radius’ property is used to create rounded corners for an element’s border.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What CSS property is used to set the background color of an element?

A

The background-color property is used to define an element’s background color.
Example:

div {
  background-color: lightblue;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you set an image as the background of an element?

A

Use the background-image property.
Example:

div {
  background-image: url('image.jpg');
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What values can the background-repeat property take?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you make a background image cover the entire element without stretching?

A

Use background-size: cover;

div {
  background-size: cover;
}

Ensures the image covers the element while maintaining its aspect ratio.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between background-size: contain; and background-size: cover;?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you set a background image to be fixed while scrolling?

A

Use background-attachment: fixed;

div {
  background-attachment: fixed;
}

This makes the background stay in place while the content scrolls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you make a semi-transparent background color in CSS?

A

Use rgba() or opacity.
Example using rgba():

div {
  background-color: rgba(0, 0, 0, 0.5);
}

This sets a black background at 50% opacity.

17
Q

What are the different border styles available in CSS?

A

solid – A single solid line
dashed – A dashed line
dotted – A dotted line
double – Two solid lines
groove – A 3D grooved effect
ridge – A 3D ridged effect
inset – A 3D inset effect
outset – A 3D outset effect
none – No border

18
Q

How do you round the corners of a border?

A

Use border-radius.
Example:

div {
  border-radius: 10px;
}

This makes the corners rounded with a 10px radius.

19
Q

How do you create a circular element using border-radius?

A

Set border-radius to 50% and ensure the width and height are equal.

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}
20
Q

What is the difference between border and outline?

A

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;
}
21
Q

How do you create a border with different colors on each side?

A

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;
}
22
Q

How do you apply multiple background images to an element?

A

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.

23
Q

How do you create a radial gradient background?

A

Use background: radial-gradient().

div {
  background: radial-gradient(circle, red, yellow, green);
}
24
Q

How do you add space between a border and the content inside an element?

A

Use padding.

div {
  border: 2px solid black;
  padding: 20px;
}
25
Q

How do you create a box with a shadow effect?

A

Use box-shadow.

div {
  box-shadow: 5px 5px 10px gray;
}

This adds a gray shadow to the bottom-right.