(42) CSS Interview Questions and Answers

ans.

Cascading Style Sheet is an open standard developed and maintained by the W3C. It is a Look and Feel formatting scripts used along with HTML Tags.

Presentation: It uses how to control things like the color of text, the fonts you want to use and the size of those fonts, how to add background colors to pages (or parts of a page), and how to add background images.

Layout: How to control where the different elements are positioned on the screen.

ans.

We can’t apply any CSS.

ans.

ID

Class

The id attribute is used for assigning a unique identifier to a specific element on the page.  Accessed using CSS or JavaScript for styling or scripting purposes

The class attribute is used in a similar fashion; however, unlike the id attribute, the same class value may be  applied to multiple elements on the page for the purposes of specifying that they have something in

common (such as a particular CSS style).

The id attribute may also be used as the target of hyperlinks.

Cannot use

The value may appear once and only once per page so as to identify a single

element.

The value may appear multiple times per page.

One element contains only one unique ID and doesn’t include space.

A particular class attribute value may contain multiple class names, each separated by a space.

 

ans.

Yes, a single element can have one ID and more than one Class elements.

ans.

A CSS rule contains two parts: a selector and a declaration.

Style Sheet Rules

  • This rule indicates that all elements should be shown in the Arial typeface.
  • Selectors indicate which element the rule applies to. The same rule can apply to more than one element if you separate the element names with commas like p, #main{}
  • Declarations indicate how the elements referred to in the selector should be styled.

 

 

ans.

Applies to all elements in the document.

*{} Targets all elements on the page

ans.

There are 8 selectors in CSS. That are:

Universal Selector
Type Selector
Class Selector
D Selector
Child Selector
Descendant Selector
Adjacent Sibling Selector
 General Sibling Selector

ans.

Matches element names.

h1, h2, h3 {} Targets the <h1>, <h2> and <h3> elements

ans.

Matches an element whose class attribute has a value that matches the one specified after the period (or full stop) symbol

.container {} Targets any element whose class attribute has a value of container
p.container {} Targets only <p> elements whose class attribute has a value of container

 

ans.

If we add !important after any property value to indicate that it should be considered more important than other rules that apply to the same element.

p{color:red !important}