CSS interview questions and answers | AsgarTech


Here are some short CSS interview questions and answers:


What is CSS and what is it used for?


CSS stands for Cascading Style Sheets, and it is used to style and format the layout of web pages.

What are the three ways to include CSS in a web page?


Inline styles, internal styles, and external stylesheets.

What is the box model in CSS?


The box model is a way to describe how the layout of an element is constructed, including its content, padding, border, and margin.

What is the difference between padding and margin in CSS?


Padding is the space between an element's content and its border, while margin is the space outside of an element's border.

What is the difference between a class and an ID in CSS?


A class can be applied to multiple elements, while an ID can only be applied to one element.

What is a pseudo-class in CSS?


A pseudo-class is a keyword that is added to a selector to specify a special state of the selected element(s), such as :hover or :active.

What is the difference between absolute and relative positioning in CSS?


Relative positioning positions an element relative to its normal position, while absolute positioning positions an element relative to its nearest positioned ancestor.

What is a CSS selector?


A CSS selector is a pattern used to select elements to apply styles to. Examples include element selectors, class selectors, ID selectors, and attribute selectors.

What is the difference between a block-level element and an inline element in CSS?


Block-level elements take up the full width of their parent container and are stacked vertically, while inline elements only take up as much space as necessary and are stacked horizontally.

What is the difference between em and rem units in CSS?


Em units are relative to the font size of the parent element, while rem units are relative to the font size of the root element (i.e., the html element).


Sure, here are some objective questions related to CSS:


Which of the following CSS selectors applies to all elements on a web page?

a) *

b) #

c) .

d) :

Answer: a) *


Which CSS property can you use to change the color of text?

a) font-size

b) background-color

c) color

d) padding

Answer: c) color


Which CSS property can you use to add a background image to an element?

a) background-image

b) background-color

c) border-image

d) image-background

Answer: a) background-image


Which of the following is a valid way to include an external CSS file in a web page?

a) <link href="styles.css">

b) <script src="styles.css">

c) <style src="styles.css">

d) <head href="styles.css">

Answer: a) <link href="styles.css">


Which CSS property can you use to create a border around an element?

a) margin

b) padding

c) border

d) outline

Answer: c) border


Which of the following CSS selectors applies to elements with a specific class?

a) *

b) #

c) .

d) :

Answer: c) .


Which CSS property can you use to change the font style of text?

a) font-family

b) font-style

c) font-size

d) font-weight

Answer: b) font-style


Which of the following CSS properties can you use to adjust the spacing between lines of text?

a) letter-spacing

b) line-height

c) text-align

d) word-spacing

Answer: b) line-height


Which CSS property can you use to make text bold?

a) font-family

b) font-style

c) font-size

d) font-weight

Answer: d) font-weight


Which of the following CSS selectors applies to elements with a specific ID?

a) *

b) #

c) .

d) :

Answer: b) #

check these all Courses blog👇👇







No comments: