css banner

CSS Multiple Choice Questions (MCQs) and Answers

Master CSS with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of CSS. Begin your placement preparation journey now!

Q31

Q31 Why might an element with box-sizing: border-box; and width: 100%; still overflow its container?

A

Padding or border not accounted for

B

Container's width includes padding

C

Incorrect measurement of the container's width

D

A global style affecting box-sizing

Q32

Q32 What is the default flex-direction of a flex container?

A

row

B

column

C

row-reverse

D

column-reverse

Q33

Q33 Which CSS property makes an element a flex container?

A

display: flex

B

display: grid

C

display: block

D

display: inline-block

Q34

Q34 How do you align items in the center of a flex container along the cross axis?

A

align-items: center

B

justify-content: center

C

align-content: center

D

justify-items: center

Q35

Q35 In CSS Grid layout, what property defines the number and sizes of columns in the grid?

A

grid-template-columns

B

grid-template-rows

C

grid-column

D

grid-row

Q36

Q36 Which property aligns a flex item in the center of its container along the main axis?

A

align-self: center

B

justify-self: center

C

justify-content: center

D

align-items: center

Q37

Q37 What does flex-wrap: wrap; do in a flex container?

A

Forces items to stay in one line

B

Allows items to wrap onto multiple lines

C

Changes the direction of flex items

D

Applies a fixed width to flex items

Q38

Q38 How can you create a grid with equal-width columns using CSS Grid?

A

Use grid-template-columns: auto;

B

Use grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));

C

Use grid-template-columns: 1fr 1fr 1fr;

D

Use grid-template-columns: repeat(3, 1fr);

Q39

Q39 What is the difference between justify-content and align-items in a flex container?

A

justify-content aligns along the main axis, align-items along the cross axis

B

justify-content aligns along the cross axis, align-items along the main axis

C

They have the same function but apply to different elements

D

There is no difference, they are interchangeable

Q40

Q40 In a CSS Grid layout, how do you place an item to start on column line 2 and end on column line 4?

A

grid-column: 2 / 4;

B

grid-column-start: 2; grid-column-end: 4;

C

Both A and B are correct

D

grid-column: 2 / span 2;

Q41

Q41 Which property is used to define the space between Grid items?

A

grid-gap

B

grid-row-gap

C

grid-column-gap

D

gap

Q42

Q42 Given a container with display: flex; and justify-content: space-between;,
how are the flex items arranged?

A

Evenly spaced along the main axis, with the first item at the start and the last at the end

B

Stacked vertically

C

Overlapped

D

Evenly spaced with equal margins on all sides

Q43

Q43 How do you make a flex item take up the remaining space in a flex container?

A

flex-grow: 1;

B

flex-basis: auto;

C

flex: auto;

D

flex: 1;

Q44

Q44 In CSS Grid, what does fr unit stand for?

A

Fraction of the available space

B

Fixed ratio

C

Frame rate

D

Flexible resize

Q45

Q45 How can you create an asymmetrical grid layout with three rows where the first row is 200px tall, the second is auto-sized, and the third is 1fr tall?

A

grid-template-rows: 200px auto 1fr;

B

grid-template-rows: repeat(3, 200px auto 1fr);

C

grid-template-rows: 200px 1fr auto;

D

grid-template-rows: auto 200px 1fr;

Q46

Q46 Why might items in a flex container not be displaying in a single row as expected?

A

flex-wrap is set to wrap

B

The container is too narrow

C

There are too many items

D

All of the above

Q47

Q47 In a grid layout, why might an item not align as expected with justify-items: start;?

A

The item has an explicit position set

B

The grid container is using align-items instead

C

The property is not supported by the browser

D

The item is absolutely positioned

Q48

Q48 What could cause a flex item to not shrink as expected when the container size is reduced?

A

flex-shrink is set to 0

B

The item has a fixed width set

C

The container does not have display: flex;

D

Both A and B are correct

Q49

Q49 Why might a CSS Grid item overlap another grid item?

A

The items are placed in the same grid cell without grid-row-start or grid-column-start set

B

There's a negative margin applied

C

The grid container has grid-auto-flow: dense; set

D

Both A and C are correct

Q50

Q50 What does the position property do in CSS?

A

Defines the color of an element

B

Changes the size of an element

C

Specifies the element's position in the document

D

Alters the font of an element

Q51

Q51 Which value of the position property makes an element's position relative to its normal position?

A

static

B

relative

C

absolute

D

fixed

Q52

Q52 How does the absolute positioning value differ from fixed positioning?

A

absolute positions an element relative to its nearest positioned ancestor

B

absolute positions it relative to the viewport

C

fixed positions it relative to its nearest positioned ancestor

D

fixed positions it relative to the viewport

Q53

Q53 What is the purpose of the z-index property in CSS?

A

To adjust the zoom level of elements

B

To set the stacking order of positioned elements

C

To change the opacity of elements

D

To rotate elements

Q54

Q54 Which position values can z-index be applied to?

A

static only

B

relative, absolute, and fixed only

C

absolute and fixed only

D

relative, absolute, fixed, and sticky

Q55

Q55 What happens if an element with position: absolute; has no positioned ancestors?

A

It is positioned relative to the document body

B

It disappears from the document

C

It remains in its original position

D

It is positioned relative to the nearest block-level element

Q56

Q56 How can z-index affect elements with the same stacking context?

A

It moves elements horizontally across the page

B

It changes the vertical stacking order

C

It alters the opacity of elements

D

It rotates elements

Q57

Q57 What determines an element's stacking context?

A

Its position and z-index values

B

Its display value

C

Its float value

D

Its opacity value

Q58

Q58 Can an element with a lower z-index ever appear above an element with a higher z-index?

A

Yes, if it's positioned more closely

B

No, z-index values strictly determine stacking order

C

Yes, if it's in a different stacking context

D

Yes, if it uses a position: fixed; style

Q59

Q59 What is the default position value for HTML elements?

A

static

B

relative

C

absolute

D

fixed

Q60

Q60 Given two overlapping elements with position: absolute;, how do you ensure the first element appears on top?

A

Set a higher z-index value on the first element

B

Set a lower z-index value on the second element

C

Use position: relative; on the first element

D

Both A and B are correct

ad verticalad vertical
ad