Interview Questions CSS

CSS


1. What is CSS?
CSS stands for Cascading Style Sheets. Basically, CSS is a language that manages the design and presentation of web pages -- the way things look. It works together with HTML, or HyperText Markup Language, which handles the content of web pages.
With CSS you can create rules to tell your website how you want it to display information. And you can keep the commands for the style stuff -- fonts, colors, and so on -- separate from the commands for the content.
They?re called ?cascading? because you can have multiple style sheets, with one style sheet inheriting properties (or ?cascading?) from others.

2. What are different types of style sheet ?
There are three kinds of CSS style sheets: external, internal, and inline.
External styles control how things look across many pages on a website.
Internal styles control the look of just one page.
Inline styles control just one element of a single page, even just a single word.

3. What is a Style Sheet?
Style sheets are the way that standards-compliant Web designers define the layout, look-and-feel, and design of their pages. They are called Cascading Style Sheets or CSS. With style sheets, a designer can define many aspects of a Web page:
fonts
colors
layout
positioning
imagery
accessibility
Style sheets give you a lot of power to define how your pages will look. And another great thing about them is that style sheets make it really easy to update your pages when you want to make a new design. Simply load in a new style sheet onto your pages and you're done.

4. Is CSS case sensitive?
Cascading Style Sheets (CSS) is not case sensitve. However, font families, URLs to images, and other direct references with the style sheet may be.
The trick is that if you write a document using an XML declaration and an XHTML doctype, then the CSS class names will be case sensitive for some browsers.
It is a good idea to avoid naming classes where the only difference is the case, for example:
div.myclass { ...}
div.myClass { ... }
If the DOCTYPE or XML declaration is ever removed from your pages, even by mistake, the last instance of the style will be used, regardless of case.

5. How do you comment a CSS document?
Comments are easy to add in CSS, and it's a good idea to include them so that you remember what your styles apply to in the future. To comment code in CSS:

/* comment text */
Everything that is between the /* and the final */ will be ignored by the Web browser

6. What is external Style Sheet? How to link?
External Style Sheet is a template/document/file containing style information which can be linked with any number of HTML documents. This is a very convenient way of formatting the entire site as well as restyling it by editing just one file.

The file is linked with HTML documents via the LINK element inside the HEAD element. Files containing style information must have extension .css, e.g. style.css.

<HEAD>
<LINK REL=STYLESHEET HREF="style.css" TYPE="text/css">
</HEAD>

7. What is embedded style? How to link?
Embedded style is the style attached to one specific document. The style information is specified as a content of the STYLE element inside the HEAD element and will apply to the entire document.

<head>
<style type="text/css">
<!-- p {text-indent: 10pt} -->
</style>
</head>

Note: The styling rules are written as a HTML comment, that is, between <!-- and --> to hide the content in browsers without CSS support which would otherwise be displayed.

8. What is inline style? How to link?
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 and will apply  exclusively to this specific element occurance.

9. What is imported Style Sheet? How to link?
Imported Style Sheet is a sheet that can be imported to (combined with) another sheet. This allows creating one main sheet containing declarations that apply to the whole site and partial sheets containing declarations that apply to specific elements (or documents) that may require additional styling. By importing partial sheets to the main sheet a number of sources can be combined into one.

To import a style sheet or style sheets include the @import notation or notations in the STYLE element. The @import notations must come before any other declaration. If more than one sheet is imported they will cascade in order they are imported - the last imported sheet will override the next last; the next last will override the second last, and so on. If the imported style is in conflict with the rules declared in the main sheet then it will be overridden.

<link rel=?stylesheet? href="style.css" type="text/css">
<style type="text=css">
<!--
@import url(http://www.and.so.on.partial1.css);
@import url(http://www.and.so.on.partial2.css);
.... other statements
-->
</STYLE>

10. What is alternate Style Sheet? How to link?
Alternate Style Sheet is a sheet defining an alternate style to be used in place of style(s) declared as persistent and/or preferred .

Persistent style is a default style that applies when style sheets are enabled but can disabled in favor of an alternatestyle, e.g.:

<link rel=?Stylesheet? href="style.css" type="text/css">

Preferred style is a default style that applies automatically and is declared by setting the TITLE attribute to the LINK element. There can only be one preferred style, e.g.:

<link rel=?Stylesheet? href="style2.css" type="text/css" title="appropriate style description">

Alternate style gives an user the choice of selecting an alternative style - a very convenient way of specifying a media dependent style. Note: Each group of alternate styles must have unique TITLE, e.g.:

<link rel="Alternate Stylesheet" href="style3.css" type="text/css" title="appropriate style description" media=screen>
<link rel="Alternate Stylesheet" href="style4.css" type="text/css" title="appropriate style description" media=print>
Alternate stylesheets are not yet supported.