All CSS Interview Questions & Answers

All Interview Questions & Answers

What is CSS class selector?

A CSS class is used to group similar HTML elements. This helps us to apply same style to those elements by placing them in the same class.

Class methods can be called by inserting a ‘class’ property and name within an HTML element

Then, we can call class name with a ‘.’ in the CSS file. For example:


What is grouping in CSS and what is it used for?

Grouping allows you to apply the same style to multiple elements(classes/tag/id) with a single declaration. This is done by listing all the selectors, separated by commas.


Explain the various ways to apply CSS styles to a Web page?

There are Four methods of adding CSS to HTML.

  1. Inline: by inserting a style attribute inside an <head> element.
  2. Embedded/Internal: by putting all css inside head using <style> tags
  3. Linked/External: CSS is placed in an external .css file, and linked to the HTML document using a <link> tag.
  4. Imported: Importing a CSS file using @import

What are child selectors?

Child selectors are written using a greater-than symbol (>), and it must appear between two other selectors. This is used to match elements that are direct children of other elements, which is a little more precise than the traditional selectors.

Example:


What is the use of float property in CSS?

The float property determines whether or not a box (an element) should float. Floats allow an element to be positioned horizontally, by pushing a block-level element to the right or left.


Why we use shorthand properties in CSS?

CSS shorthand properties helps to improve page load times and reduce file size. For an example: All CSS border Properties can be set in a single line in a specific order.
Example: