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!

Q61

Q61 How do you position an element at the bottom right corner of its positioned ancestor?

A

position: absolute; bottom: 0; right: 0;

B

position: fixed; bottom: 0; right: 0;

C

position: relative; bottom: 0; right: 0;

D

position: sticky; bottom: 0; right: 0;

Q62

Q62 What does setting position: sticky; on an element do?

A

Keeps the element fixed at the top of the viewport

B

Allows the element to scroll away with the page

C

Positions the element based on the user's scroll position, toggling between relative and fixed

D

Makes the element unresponsive to scroll events

Q63

Q63 How do you make an element with position: fixed; cover the entire viewport?

A

top: 0; right: 0; bottom: 0; left: 0;

B

width: 100%; height: 100%;

C

top: 0; bottom: 0;

D

right: 0; left: 0;

Q64

Q64 Why might an element with position: absolute; not appear where expected?

A

It's outside the viewport

B

Its containing block is not positioned

C

It has a z-index of -1

D

Both B and C are correct

Q65

Q65 What could cause a position: fixed; element to behave like position: absolute;?

A

The document is in quirks mode

B

The element is inside a transformed ancestor

C

The viewport is not defined

D

The browser does not support position: fixed;

Q66

Q66 How can you solve an issue where a sticky positioned element isn't sticking?

A

Ensure the element has a defined top, right, bottom, or left value

B

Remove any overflow properties on ancestors

C

Increase the z-index

D

Both A and B are correct

Q67

Q67 Why might elements with different z-index values not stack as expected?

A

They are in different stacking contexts

B

There's a CSS error

C

The z-index is not supported

D

They have different position values

Q68

Q68 What is the purpose of responsive web design?

A

To make web pages render well on a variety of devices and window or screen sizes

B

To improve the speed of web pages

C

To enhance the security of web pages

D

To create a single design for all devices

Q69

Q69 Which HTML element is used to set the viewport to the device's width?

A

<meta name="viewport" content="width=device-width">

B

<meta name="device" content="width=viewport">

C

<viewport width="device-width">

D

<device width="viewport">

Q70

Q70 What does a media query allow you to do in CSS?

A

Change the layout based on the device's orientation

B

Apply different styles for different devices based on criteria like width, height, or orientation

C

Increase the loading speed of web pages

D

Encrypt web page data for security

Q71

Q71 Which CSS unit is recommended for responsive typography?

A

px

B

em

C

rem

D

pt

Q72

Q72 How do you apply a CSS style only for screens smaller than 600px?

A

@media only screen and (max-width: 599px) { ... }

B

@media screen and (max-width: 600px) { ... }

C

@media (min-width: 600px) { ... }

D

@media (width < 600px) { ... }

Q73

Q73 What is the difference between min-width and max-width in media queries?

A

min-width applies styles for widths greater than or equal to the specified value, while max-width applies styles for widths less than or equal to the specified value

B

min-width applies styles for heights, while max-width applies styles for widths

C

min-width is used for mobile devices, while max-width is used for desktops

D

There is no difference, they are interchangeable

Q74

Q74 Why is it important to use relative units like %, vw, vh, em, or rem in responsive design?

A

They allow for more precise control over layout dimensions

B

They enable the layout to adjust based on the parent element's size

C

They help the layout adapt to different screen sizes and resolutions

D

They make it easier to calculate dimensions

Q75

Q75 How do you ensure that a video embedded in a web page is responsive?

A

Set the video's width and height attributes to 100%

B

Use a container with a fixed aspect ratio and set the video to fill it

C

Use the <video> element with the responsive attribute

D

Apply a media query to the video based on the viewport width

Q76

Q76 Which media query is correct for applying styles to devices with a width of at least 768px?

A

@media (min-width: 768px) { ... }

B

@media only screen (width >= 768px) { ... }

C

@media screen and (width: 768px) { ... }

D

@media (width > 768px) { ... }

Q77

Q77 How can you create a flexible grid layout that uses available space but limits column width to 200px?

A

Use display: grid; grid-template-columns: repeat(auto-fill, minmax(auto, 200px));

B

Use display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

C

Use display: flex; flex-wrap: wrap; and set children's flex-basis: 200px;

D

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

Q78

Q78 What is the best practice for serving high-resolution images to devices with high-density displays?

A

Use the srcset attribute in the <img> element

B

Specify different images for different resolutions using CSS

C

Use JavaScript to detect the screen resolution and load images accordingly

D

All of the above

Q79

Q79 How do you apply styles for landscape and portrait orientations of a device?

A

@media (orientation: landscape) { ... } and @media (orientation: portrait) { ... }

B

@media screen and (orientation: landscape) { ... }

C

@media only screen and (orientation: portrait) { ... }

D

Both A and B are correct

Q80

Q80 Why might a media query not apply its styles as expected?

A

The media query is incorrectly formatted

B

The viewport meta tag is missing from the HTML document

C

There is a more specific style overriding the media query

D

All of the above

Q81

Q81 How can you fix a layout that breaks at certain viewport sizes?

A

Use additional media queries to adjust styles at those sizes

B

Increase the base font size

C

Remove all media queries and use fixed sizes

D

Decrease the overall page width

Q82

Q82 What could be the reason for a background image not resizing with its container?

A

The background-size property is set to cover

B

The background-size property is set to contain

C

The container's size is not defined

D

The background-size property is set to auto

Q83

Q83 Why might changes in a media query not reflect in a browser?

A

The browser cache is outdated

B

The media query syntax is incorrect

C

The stylesheet link is broken

D

All of the above

Q84

Q84 Which property is used to change the font size of text in CSS?

A

font-style

B

font-weight

C

font-size

D

text-transform

Q85

Q85 What does the font-weight property do?

A

It changes the font style to italic or normal

B

It adjusts the thickness or boldness of the font

C

It alters the spacing between characters

D

It sets the height of a line of text

Q86

Q86 Which property is used to set the text color?

A

color

B

text-color

C

font-color

D

text-style

Q87

Q87 How do you make text uppercase using CSS?

A

text-transform: uppercase;

B

text-style: uppercase;

C

font-case: uppercase;

D

text-case: uppercase;

Q88

Q88 What is the purpose of the line-height property?

A

To set the vertical spacing between lines of text

B

To define the height of a line box

C

Both A and B are correct

D

To adjust the horizontal spacing between characters

Q89

Q89 Which property adds shadow to text?

A

text-shadow

B

font-shadow

C

box-shadow

D

shadow

Q90

Q90 How do you apply a font family of "Arial" to an element?

A

font-family: "Arial";

B

font-type: "Arial";

C

font: "Arial";

D

typeface: "Arial";

ad verticalad vertical
ad