CSS Interview Questions and Answers

What is a Style Sheet?

Its also called Cascading Style Sheets or CSS. Style sheets are used to maintain standards in web pages. It give you a lot of power to define how your pages will look and allow easy to update your pages when you want to make a new design via load new style sheet onto your pages. 
With style sheets, a designer can define many aspects of a Web page: 
* fonts
* colors
* layout
* positioning
* image
* accessibility

Explain inline, embedded and external style sheets?

There are three ways of inserting a style sheet:
1. External style sheet 
2. Internal / embedded style sheet 
3. Inline style 

External Style Sheet: 
An external style sheet is good when the style is applied to many pages.With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: 

<head> 
<link rel='stylesheet' type='text/css' href='mystyle.css' /> 
</head> 

Internal/ Embedded Style Sheet: 
An internal style sheet should be used when a single document has a unique style. It needs to put in the head section of an HTML page, by using the <style> tag, like this:

<head> 
<style type='text/css'> 
hr {color:sienna} 
p {margin-left:20px} 
body {background-image:url('images/back40.gif')} 
</style> 
</head> 

Inline Styles : 
If only a small piece of code has to be styled then inline style sheets can be used. Inline style is the style attached to one specific element. The style is specified directly in the start tag as a value of the STYLE attribute. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

<p style='color: sienna; margin-left: 20px'>this is a paragraph. </p>
What are the advantages/disadvantages of the various style methods?

External Style Sheets

Advantages

Can control styles for multiple documents at once. Classes can be created for use on multiple HTML element types in many documents. Selector and grouping methods can be used to apply styles under complex contexts.

Disadvantages

An extra download is required to import style information for each document.The rendering of the document may be delayed until the external style sheet is loaded.Becomes slightly unwieldy for small quantities of style definitions.

Internal /Embedded Style Sheets

Advantages

Classes can be created for use on multiple tag types in the document.Selector and grouping methods can be used to apply styles under complex contexts.No additional downloads necessary to receive style information.

Disadvantages

This method can not control styles for multiple documents at once.

Inline Styles

Advantages

Useful for small quantities of style definitions.Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods.

Disadvantages

Does not distance style information from content (a main goal of SGML/HTML).Can not control styles for multiple documents at once.Author can not create or control classes of elements to control multiple element types within the document.Selector grouping methods can not be used to create complex element addressing scenarios.

Can you specify more than one css class for any HTML element?

Yes, you can. Just provide a space between both the class names. 
like. 
<div class='class1 class2'> ......... </div>

What is ID selector?

ID selector is an individually identified (named) selector. Using the ID attribute the declared style can be associated with one and only one HTML element per document as to differentiate it from all other elements. ID selectors are created by a character # followed by the selector's name. The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, Unicode characters 161-255, as well as any Unicode character as a numeric code, however, they cannot start with a dash or a digit. 
#ABC {color: red; background: black}
This and only this element can be identified as ABC 

<p id="ABC">Hello World!</p>

What is contextual selector?

Contextual selector is a selector that addresses specific occurrence of an element. It is a string of individual selectors separated by white space, a search pattern, where only the last element in the pattern is addressed providing it matches the specified context. 
TD P CODE {color: red}
The element CODE will be displayed in red but only if it occurs in the context of the element P which must occur in the context of the element TD. 
TD P CODE, H1 EM {color: red}
The element CODE will be displayed in red as described above AND the element EM will also be red but only if it occurs in the context of H1
P .footnote {color: red}
Any element with CLASS footnote will be red but only if it occurs in the context of P
P .footnote [lang]{color: red}
Any element with attribute LANG will be red but only if it is classed as 'footnote' and occurs in the context of P

What is Group Selectors?

By combining the grouping of selectors that share the same declaration and declarations that share the same selector you can apply multiple declarations to multiple selectors. This technique allows you to create compact yet powerful CSS rules. This tip combines Group Selectors with Group Declarations into one powerful technique. 
So this: 
body {font-size: 12px; }
body {font-family: arial, helvetica, sans-serif;} 
th {font-size: 12px; font-family: arial, helvetica, sans-serif;} 
td {font-size: 12px; font-family: arial, helvetica, sans-serif;} 


Becomes this: 
body, th, td {font-size: 12px; font-family: arial, helvetica, sans-serif;} 

What is css class?

Class is a group of 
1) instances of the same element to which an unique style can be attached 
2) instances of different elements to which the same style can be attached. 

Is CSS case sensitive?
Cascading Style Sheets (CSS) is not case sensitive. However, font families, URLs to images, and other direct references with the style sheet may be.

Which set of definitions, HTML attributes or CSS properties, take precedence?

CSS properties take precedence over HTML attributes. If both are specified, HTML attributes will be displayed in browsers without CSS support but won't have any effect in browsers with CSS support.

Can I include comments in my Style Sheet?

Yes. Comments can be written anywhere where whitespace is allowed and are treated as white space them. Anything written between /* and */ is treated as a comment (white space).

NOTE: Comments cannot be nested. /* this is a CSS-comment */

What is the difference between ID and CLASS?

ID identifies and sets style to one and only one occurrence of an element while class can be attached to any number of elements. 

ID started by hash(#)

Each element can have only one ID.
Each page can have only one element with that ID.

#eva1 {background: red; color: white}

<div id="eva1">

CLASS started by dot(.)

You can use the same class on multiple elements.
You can use multiple classes on the same element.

<div id="eva2">

Latest Updates

General Knowledge of India

Which of the following dance forms was introduced by the great Vaishnava saint and reformer Mahapurusha Sankaradeva ?

Which of the following is the only classical dance of india having links with Muslim culture and represents a unique synthesis of Hindu and Muslim genius in art ?

Time and Distance

Starting from the same point at the same time, Ruhan and Yuvan had to reach the same destination. While Ruhan drove at 45 km/hr, Yuvan was slower by 5 km/hr. If Yuvan arrived at the destination an hour after Ruhan did, the distance covered by each, in Kilometres, was ?

Simple Interest

A sum of money was invested at a certain rate of simple interest for 4 years. Had the sum been invested at a rate 3% higher than the actual rate, the interest earned would have been 720 Rs more. Find the sum initially invested?

Ratio and Proportion

A bag contains red, blue and black balls. The ratio of red to blue balls is 3 : 5. The ratio of black to red balls is 3 : 4. What is the ratio of blue to black balls?

Profit and Loss

Selling a pack of incense sticks for 136 Rs resulted in a loss of 15%. To make a profit of 10%, the selling price should be ?

Percentage

23% of a bucket full of diluted milk was water. If the quantity of pure milk in the bucket was 15.4 liter, then the capacity of the bucket was ?

Average

The average of the marks obtained by three girls in a test was twice the average of the marks obtained by eight boys in that test. If the total marks obtained by all these examinees was 168, find the average marks each of the girls obtained ?

Pipes and Cistern

44 pipes can fill a large water tank in 27 hours. How many hours it take for 66 pipes to fill four such tanks ?

HCF and LCM

A natural number, when divided by 3, 4, 5, 6, and 7 respectively, leaves corresponding remainder of 2, 3, 4, 5 and 6. What is the smallest of all such numbers fulfilling the above condition ?

Coding-Decoding

If in a certain code language, PRINT is written as 34825 and TRUE is written as 5479. Then, how will TENURE be written in that language?

Order Sequence

Arrange the given words from smallest to biggest-
1.Jug
2.Mug
3.Bucket
4.Drum
5.Cup

Statement and Conclusion

Statements
All socks are shoes
Some shoes are black

Conclusions
I. Some shoes are socks.
II. No scoks is black

Numbers

The difference between the place value of 4 and 2 in the number 833749502 is ?

Analogy

GIKM : HJLN :: PRTV : .........?

Order Sequence

In a row of girls, Nanda is eighth from the left and Chanda is nineteenth from right. When Nanda and Chanda interchange their positions, Chanda becomes twnty-third form right. How many girls are there in the row?

Analogy

Summer: Day :: Winter : ........?

Bird:Winges :: Fish:........?