Sizing Items in CSS Flashcards

1
Q

What property is used to set the width of an element in CSS?

A

The width property.

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

True or False: The height property can take values in pixels, percentages, and em units.

A

True.

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

Fill in the blank: The CSS property that controls the size of text is called ___ .

A

font-size.

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

What is the default value of the box-sizing property?

A

content-box.

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

Which CSS unit is relative to the viewport width?

A

vw (viewport width).

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

What does the term ‘responsive design’ refer to?

A

Designing web pages that look good on all devices by using fluid grids and flexible images.

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

Multiple Choice: Which unit is NOT a length unit in CSS? A) px B) em C) bg

A

C) bg.

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

What CSS property is used to set the maximum width of an element?

A

max-width.

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

True or False: The value ‘auto’ for width allows the browser to calculate the width of an element.

A

True.

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

What does the ‘min-height’ property do?

A

It sets the minimum height of an element.

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

Which CSS unit is relative to the font size of the parent element?

A

em.

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

Fill in the blank: The ___ property controls the vertical space an element occupies.

A

height.

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

What is the purpose of the ‘overflow’ property?

A

It controls what happens to content that is too big to fit in an area.

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

Multiple Choice: Which unit is best for defining a responsive layout? A) px B) % C) cm

A

B) %.

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

True or False: ‘vh’ units are based on the height of the viewport.

A

True.

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

What is the effect of setting ‘box-sizing: border-box;’?

A

Padding and borders are included in the element’s total width and height.

17
Q

What do ‘rem’ units represent?

A

Root em units, which are relative to the font size of the root element.

18
Q

Fill in the blank: To make an element take the full width of its container, set its width to ___ .

19
Q

What is the difference between ‘width’ and ‘max-width’?

A

‘width’ sets a fixed width, while ‘max-width’ restricts the maximum width an element can grow to.

20
Q

Multiple Choice: Which property would you use to prevent content overflow? A) width B) overflow C) display

A

B) overflow.

21
Q

True or False: CSS Grid can be used to create complex layouts without using floats.

22
Q

What is a fluid layout?

A

A layout that uses percentage-based widths to adapt to the screen size.

23
Q

Fill in the blank: The ___ property defines how an element behaves when it is resized.

24
Q

What does setting ‘display: inline-block;’ do to an element?

A

It allows the element to have width and height while still flowing inline.

25
Q

True or False: CSS Flexbox is used for aligning items in a one-dimensional space.

26
Q

What happens if you only set the width of an element and not the height?

A

The height remains auto, meaning it adjusts based on the content inside the element.

27
Q

How do you ensure an image never exceeds its parent container’s width?

A
img {
  max-width: 100%;
}

This prevents the image from overflowing.

28
Q

How do you create a div that is at least 300px wide but does not exceed 80% of the screen width?

A
.box {
  width: min(80vw, 300px);
}

This ensures the width is at most 80vw but not smaller than 300px.

29
Q

How do you make a div exactly 50% of its parent’s height?

A
.box {
  height: 50%;
}

The height will be half of the parent container’s height.

30
Q

How do you set a box to be square with a width of 200px?

A
.box {
  width: 200px;
  height: 200px;
}

This makes a fixed square.

31
Q

How do you maintain a 16:9 aspect ratio for a div?

A
.box {
  aspect-ratio: 16 / 9;
  width: 100%;
}

This ensures the height is calculated automatically to maintain 16:9.

32
Q

How can you make an element’s width always be at least 300px but also take up 70% of the screen if possible?

A
.box {
  width: clamp(300px, 70vw, 1000px);
}

This ensures the width is at least 300px but scales up to 70% of the vie

33
Q

How do you create a responsive square that resizes with the viewport width?

A
.box {
  width: 30vw;
  aspect-ratio: 1 / 1;
}

This ensures the box always stays square while adapting to the viewport