HCL – Web / UI Developer – interview questions and answer – HTML5 , CSS3 , JS & jQuery

1) Explain about HTML5 local storage ?

There are two ways to store data in HTML as objects locally :

  1. localStorage – store data  across session acess
  2. sessionStorage – storing data for current session only

Data will be stored in key/value pair format.

example:

localStorage.empid=”420″;

sessionStorage.companyname = “SHARAG INFOTECH”;

2)  explain CSS media queries ?

CSS media queries are used to develop responsive templates for different layout of screen, print, mobile , tablet or any other resolutions

CSS media queries can be added in 3 ways as like CSS style sheet :

  1. Internal stylesheet :  <style type=”text/css”>
    @media only screen and (max-width: 600px){
    /* rules apply to the device resolution is 480px or less  */
    }
    </style>
  2. Imported stylesheet :   @import “tablet.css”   (min-width: 800px) and (max-width: 1200px);
  3. External stylesheet:  <link rel=”stylesheet” type=”text/css” href=”deskto.css” media=”screen and (min-width: 1200px), print and (min-resolution: 300dpi)” />

3) explain css inheritance ?

Inheritance propagates property values from parent elements to their children. The inherited value of a property on an element is the computed value of the property on the element’s parent element. For the root element, which has no parent element, the inherited value is the initial value of the property.

A property can also be explicitly inherited by using the inherit keyword in property.

CSS inheritance example:
class inheritance for an HTML tag :
<div class=”firstClass secondClass thirdClass fourthClass ” > </div >
CSS property inheritance from parent :
p {
color: #000;
}
p a:link {
color: inherit;
}

and using LESS method for inheritance example:
//through variable
@color: #123456;
#emp {
color: @color;
}
div {
color: @color;
}

//through class name calling [MIXINS]

.rounded-corners (@radius: 2px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
-o-border-radius: @radius;
border-radius: @radius;
}

#navtable {
.rounded-corners;
}

#maintable {
.rounded-corners(5px);
}

4) what is javascript inheritance ?

In simple terms, inheritance is the concept of one thing gaining the properties or behaviours of something else.
Inherited children inherit their parent’s behaviour To say A inherits from B, is saying that A is a type of B.
In JavaScript You must use a special object called prototype.
function Animal() {}; // This is the Animal *Type*
Animal.prototype.eat = function () {
alert(“All animals can eat!”);
};

function Bird() {}; // Declaring a Bird *Type*
Bird.prototype = new Animal(); // Birds inherit from Animal
Bird.prototype.fly = function() {
alert(“Birds are special, they can fly!”);
};

The effect of this is that any Birds you create (called an instance of Bird) all have the properties of Animals
var aBird = new Bird(); // Create an instance of the Bird Type
aBird.eat(); // It should alert, so the inheritance worked
aBird.fly(); // Important part of inheritance, Bird is also different to Animal

var anAnimal = new Animal(); // Let’s check an instance of Animal now
anAnimal.eat(); // Alerts, no problem here
anAnimal.fly(); // Error will occur, since only Birds have fly() in its prototype

5) explain javascript associative array ?

Associative arrays are where we can associate a key string with a value string
JavaScript objects are also associative arrays.
i.e the property  emp.Name can also be read by calling emp['Name']
We can access each property by entering the name of the property as a string into the array
it refers to accessing the DOM elements of HTML also [as object or associative array]
6) explain JS Namespace ?

Namespacing is a technique employed to avoid collisions with other objects or variables in the global namespace
and also helps to organize blocks of functionality into easily manageable groups that can be uniquely identified.

JavaScript doesn’t  builtin support of namespacing but using objects and closures we can achieve a similar effect.
javascript Namespacing patterns :
1)    Single global variables :
var myApplication =  (function(){
function(){
/*…*/
},
return{
/*…*/
}
})();

2)    Object literal notation :

var myApplication = {
getInfo:function(){ /**/ },
// we can also populate our object literal to support
// further object literal namespaces containing anything
// really:
models : {},
views : {
pages : {}
},
collections : {}
};

3)    Nested namespacing :

var myApp =  myApp || {};
// perform a similar existence check when defining nested
// children
myApp.routers = myApp.routers || {};
myApp.model = myApp.model || {};
myApp.model.special = myApp.model.special || {};
// nested namespaces can be as complex as required

4)    Immediately-invoked Function Expressions :

// an (anonymous) immediately-invoked function expression
(function(){ /*…*/})();
// a named immediately-invoked function expression
(function foobar(){ /*..*/}());
// this is technically a self-executing function which is quite different
function foobar(){ foobar(); }
5)   Namespace injection :

// define a namespace we can use later
var ns = ns || {}, ns2 = ns2 || {};
// the module/namespace creator
var creator = function(val){
var val = val || 0;
this.next = function(){
return val++
};

this.reset = function(){
val = 0;
}
}
creator.call(ns);

// ns.next, ns.reset now exist
creator.call(ns2, 5000);
// ns2 contains the same methods
// but has an overridden value for val
// of 5000
for more details on namespace read http://addyosmani.com/blog/essential-js-namespacing/
7) explain Jquery live and bind methods ?
.bind() attacheds events to elements that exist or match the selector at the time the call is made.
Any elements created afterwards or that match going forward because the class was changed, will not fire the bound event.

$(‘img’).bind(‘click’, function(){…});

.live() works for existing and future matching elements.
Before jQuery 1.4 this was limited to the following events:
click, dblclick mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup
$(‘img’).live(‘click’, function(){…});

8) what is bootstrap ?

Bootstrap is an open-source Javascript framework developed by the team at Twitter.
It is a combination of HTML, CSS, and Javascript code designed to help build user interface components.
Bootstrap is Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
Bootstrap was also programmed to support both HTML5 and CSS3
Bootstrap is a CSS and Javascript framework that is used within your HTML. Bootstrap provides more advanced functionality to your web site.
More details http://getbootstrap.com
9) type of webservice ?

there are two types of web service….1. SOAP [Simple Object Access Protocol] Webservice and 2. RESTful [REpresentational State Transfer] Webservice.
SOAP is a messaging protocol , REST is a design philosophy , not a protocol.
SOAP:

you define your interface in a .wsdl file, which describes exactly which input parameters are expected and how the return values will look like
there are tools to generate the .wsdl files out of java class hirarchies. JAXB for example
there are also tools to generate java objects/classes as part of eclipse for example (don’t know the name in the moment).
SOAP is very strict. Every request is validatet against the wsdl before processing.

A good but not so easy to start with framework for SOAP WS is Apache CXF

REST (no hands on experience up to now, feel free to correct and improve ;) ):

a way to access a webserver or web application to retrieve data from or send to it.
it’s only negotiated, how it is accessed.
common is something like this http://server.domain.com/app/type/id=123 to retrieve object of type type with id=123
very intuitive, but no automatic validation of requests.

The main advantages of REST web services are:

Lightweight – not a lot of extra xml markup
Human Readable Results
Easy to build – no toolkits required

SOAP also has some advantages:

Easy to consume – sometimes
Rigid – type checking, adheres to a contract
Development tools

ALL CSS Interview question and answer

1. What is CSS?
CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. Every element type as well as every occurance of a specific element within that type can be declared an unique style, e.g. margins, positioning, color or size.

2. What are Cascading Style Sheets?
A Cascading Style Sheet (CSS) is a list of statements (also known as rules) that can assign various rendering properties to HTML elements. Style rules can be specified for a single element occurrence, multiple elements, an entire document, or even multiple documents at once. It is possible to specify many different rules for an element in different locations using different methods. All these rules are collected and merged (known as a “cascading” of styles) when the document is rendered to form a single style rule for each element.

3. How do I center block-elements with CSS1?
There are ways of centering block level elements:

By setting the properties margin-left and margin-right to auto and width to some explicit value:

BODY {width: 30em; background: cyan;}
P {width: 22em; margin-left: auto; margin-right: auto}

In this case, the left and right margins will each be four ems wide, since they equally split up the eight ems left over from (30em – 22em). Note that it was not necessary to set an explicit width for the BODY element; it was done here to keep the math clean.

4.If background and color should always be set together, why do they exist as separate properties?
There are serveral reasons for this. First, style sheets become more legible — both for humans and machines. The background property is already the most complex property in CSS1 and combining it with color would make it even more complex. Second, color inherits, but background doesn’t and this would be a source of confusion.

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

6. What is grouping?
Grouping is gathering into a comma separated list two or more selectors that share the same style or into a semicolon separated list two or more declarations that are attached to the same selector .

1. The selectors LI, P with class name .first and class .footnote share the same style, e.g.:
LI {font-style: italic}
P.first {font-style: italic}
.footnote {font-style: italic}

To reduce the size of style sheets and also save some typing time they can all be grouped in one list.
LI, P.first, .footnote {font-style: italic}

7. 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.c ss.

<LINK rel=stylesheet type=”text/css” href=”style.css“>

8. 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.

9. What is CSS rule ‘ruleset’?
There are two types of CSS rules: ruleset and at-rule. Ruleset identifies selector or selectors and declares style which is to be attached to that selector or selectors. For example P {text-indent: 10pt} is a CSS rule. CSS rulesets consist of two parts: selector [ e.g. P ] and declaration [ e.g. {text-indent: 10pt}] .

P {text-indent: 10pt} – CSS rule (ruleset)
{text-indent: 10pt} – CSS declaration
text-indent – CSS property
10pt – CSS value

10. ‘Fixed’ Background?
There is the possibility to use the HTML tag bgproperties=”fixed”, but that is IE proprietary, and dependent upon the ‘background’ attribute (deprecated in HTML4).

With CSS, you can declare the background like:

BODY {
font-family : “Trebuchet MS”, Verdana, Arial, Helvetica, sans-serif;
background-image: url(images/yourimage.gif);
background-repeat: no-repeat; /*no-tiling background*/
background-position: center;
background-attachment: fixed;
background-color: #hexcolor;
color : #hexcolor;
margin: 10px;
}

that shows a background-image in the center of the element, non-scrolling and non-repeating – in IE or NN6. NN 4.xx gets the non-repeat-part right, but stuffs the picture in the upper left corner and scrolls ..

11. 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.

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

12. What is ID selector?
ID selector is an individually identified (named) selector to which a specific style is declared. Using the ID attribute the declared style can then 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.

#abc123 {color: red; background: black}

This and only this element can be identified as abc123

13. 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.

14. How do I have a background image that isn’t tiled?
Specify the background-repeat property as no-repeat. You can also use the background property as a shortcut for specifying multiple background-* properties at once. Here’s an example:

BODY {background: #fff url(watermark.jpg) no-repeat;}

15. What does \ABCD (and \ABCDE) mean?
CSS allows Unicode characters to be entered by number. For example, if a CLASS value in some Russian document contains Cyrillic letters EL PE (Unicode numbers 041B and 041F) and you want to write a style rule for that class, you can put that letter into the style sheet by writing:

.41B41F {font-style: italic;}
This works on all keyboards, so you don’t need a Cyrillic keyboard to write CLASS names in Russian or another language that uses that script.

The digits and letters after the backslash (\) are a hexadecimal number. Hexadecimal numbers are made from ordinary digits and the letters A to F (or a to f). Unicode numbers consist of four such digits.

If the number starts with a 0, you may omit it. The above could also be written as:

.\41B\41F {font-style: italic;}
But be careful if the next letter after the three digits is also a digit or a letter a to f! This is OK: .\41B-\41F, since the dash (-) cannot be mistaken for a hexadecimal digit, but .\41B9\41F is only two letters, not three.

Four digits is the maximum, however, so if you write:
.41B941F {font-style: italic;}

16. 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

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

17. 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.

18. 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.

.
19. 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 alternate style, 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>

20. How can you set a minimum width for IE?
To set a minimum width, the CSS property is ‘min-width’. This can be very useful and works well in good browsers. IE doesn’t understand ‘min-width’. However, it has a proprietary property called ‘expression’ which allows us to feed it javascript via a stylesheet. Below is how to set a (780px) minimum width for IE…


body {
width:expression(documentElement.clientWidth < 780 ? (documentElement.clientWidth == 0 ? (body.clientWidth < 780 ? “780px” : “auto”) : “780px”) : “auto” );
}

As the property is non-standard, it won’t validate with the W3C validator, so if we put it in the head like this (above) – in an IE conditional comment – the validator will ignore it and the page will get a clean bill of health.

21. How do I place text over an image?
To place text or image over an image you use the position property. The below exemple is supported by IE 4.0. All you have to do is adapt the units to your need.

“<div style=”position: relative; width: 200px; height: 100px”>
<div style=”position: absolute; top: 0; left: 0; width: 200px”>
<image>
</div>
<div style=”position: absolute; top: 20%; left: 20%; width: 200px”>
Text that nicely wraps
</div>
</div> “

22. What is attribute selector?

Attribute selector is a selector defined by 1) the attribute set to element(s), 2) the attribute and value(s), 3) the attribute and value parts:

1a) A[title] {text-decoration: underline}
All A elements containing the TITLE attribute will be underlined

1b) A[class=name] {text-decoration: underline}
The A elements classed as ‘name’ will be underlined

2) A[title="attribute element"] {text-decoration: underline}
The A elements containing the TITLE attribute with a value that is an exact match of the specified value, which in this example is ‘attribute element’, will be underlined

3) A[title~="attribute"] {text-decoration: underline}
The A elements containing the TITLE attribute with a value containing the specified word, which in this example is ‘attribute’, will be underlined

23. What is parent-child selector?
Parent-child selector is a selector representing the direct descendent of a parent element. Parent-child selectors are created by listing two or more tilde (~) separated selectors.

“BODY ~ P {background: red; color: white}

The P element will be declared the specified style only if it directly descends from the BODY element:
<BODY> <P>Red and white paragraph </P> </BODY>

BODY ~ P ~ EM {background: red; color: white}
The EM element will be declared the specified style only if it directly descends from the P element which in its turn directly descends from the BODY element:

<P> <EM>Red and white EM </EM> </P> </BODY>”

24. What are inline, block, parent, children, replaced and floating elements?

Inline elements

which do not have line breaks. Can occur in block elements or other inline elements, cannot contain block elements.
Inline elements in HTML 3.2; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, TT, I, B, U, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, FONT, BASEFONT, BR, SCRIPT, MAP, INPUT, SELECT, TEXTAREA.

Inline elements in HTML 4.0; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, BIG, SMALL, SUB, SUP, A, IMG, OBJECT, BR, SCRIPT, MAP, Q, SPAN, BDO, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL).

Inline elements in HTML 4.0 Transitional; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, U, S, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, MAP, Q, SPAN, BDO, IFRAME, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL).

Block elements

which do have line breaks. May occur in other block elements, cannot occur in inline elements, may contain both block and inline elements.

Block elements in HTML 3.2; H1, H2, H3, H4, H5, H6, ADDRESS, P, DL, DT, DD, UL, OL, DIR, MENU, LI, DIV, CENTER, BLOCKQUOTE, PRE, HR, ISINDEX, TABLE, FORM.

Block elements in HTML 4.0; P, H1, H2, H3, H4, H5, H6, UL, OL, PRE, DL, DIV, NOSCRIPT, BLOCKQUOTE, FORM, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL).

Block elements in HTML 4.0 Transitional; P, H1, H2, H3, H4, H5, H6, UL, OL, DIR, MENU, PRE, DL, DIV, CENTER, NOSCRIPT, NOFRAMES, BLOCKQUOTE, FORM, ISINDEX, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL).

Parents and children elements

which either contain (parents) or are in the content of (children) other elements, e.g.

” e.g. <P>text<STRONG>text</STRONG>text</P>.”  P is a parent of STRONG. STRONG is a child of P. If not specified otherwise, children will inherit parent’s properties.

Replaced
elements which content is replaced. For example content of the IMG element is replaced with an image, content of the INPUT element is replace with a field.
Floating
elements which follow the flow of a parent – inline elements.

25. What are pseudo-classes?
Pseudo-classes are fictional element types that do not exist in HTML. In CSS1 there is only one element type which can be classed this way, namely the A element (anchor). By creating three fictional types of the A element individual style can be attached to each class. These three fictional element types are: A as unvisited link, A as active link and A as visited link. Pseudo-classes are created by a colon followed by pseudo-class’s name. They can also be combined with normal classes, e.g.:

A:link {background: black; color: white}
A:active {background: black; color: red}
A:visited {background: transparent; color: black}

This anchor (or rather these anchors) will be displayed as declared above

A.foot:link {background: black; color: white}
A.foft:active {background; black: color: red}
A.foot:visited {background: transparent; color: black}

This anchor and all other anchors with CLASS foot will be displayed as declared above

26. What is CSS rule ‘at-rule’?
There are two types of CSS rules: ruleset and at-rule. At-rule is a rule that applies to the whole style sheet and not to a specific selector only (like in ruleset). They all begin with the @ symbol followed by a keyword made up of letters a-z, A-Z, digits 0-9, dashes and escaped characters, e.g. @import or @font-face.

27. What is ‘important’ declaration?
Important declaration is a declaration with increased weight. Declaration with increased weight will override declarations with normal weight. If both reader’s and author’s style sheet contain statements with important declarations the author’s declaration will override the reader’s.

BODY {background: white ! important; color: black}

In the example above the background property has increased weight while the color property has normal.

27 To what are partial URLs relative?
Partial URLs are relative to the source of the style sheet. The style sheet source can either be linked or embedded. To which source partial URLs are relative to depends on their occurrence.
If a partial URL occurs in a linked style sheet then it is relative to the linked style sheet. The URL of the linked style sheet is the URL of the directory where the sheet is kept.
If a partial URL occurs in an embedded style sheet then it is relative to the embedded style sheet. The URL of the embedded style sheet is the URL of the HTML document in which the sheet is embedded.
Note that Navigator 4.x treats partial URLs as being relative to the HTML document, regardless of the place where the partial URL occurs. This is a serious bug which forces most authors to use absolute URLs in their CSS.

28 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. By singling out one occurrence of an element the unique value can be declared to said element.

CSS
#eva1 {background: red; color: white}
.eva2 {background: red; color: white}

“HTML – ID

<P ID=eva1>Paragraph 1 – ONLY THIS occurrence of the element P (or single occurrence of some other element) can be identified as eva1</P>
<P ID=eva1>Paragraph 2 – This occurrence of the element P CANNOT be identified as eva1</P>

HTML – CLASS
<P class=eva2>Paragraph 1 – This occurrence of the element P can be classified as eva2</P>
<P class=eva2>Paragraph 2 – And so can this, as well as occurrences of any other element, </P> “

29. What is shorthand property?
Shorthand property is a property made up of individual properties that have a common “addressee”. For example properties: font-weight, font-style, font-variant, font-size, font-family, refer to the font. To reduce the size of style sheets and also save some keystrokes as well as bandwidth they can all be specified as one shorthand property font, e.g.:

H1 {font-weight: bold;
font-style: italic;
font-variant: small-caps;
font-size: 160%;
font-family: serif}

can be all shorthanded to a space separated list:

H1 {font: bold italic small-caps 160% serif}

Note: To make things even simpler the line-height property can be specified together with the font-size property:

H1 {font: bold italic small-caps 160%/170% serif}

30. How does inheritance work?
HTML documents are structured hierarchically. There is an ancestor, the top level element, the HTML element, from which all other elements (children) are descended. As in any other family also children of the HTML family can inherit their parents, e.g. color or size.

By letting the children inherit their parents a default style can be created for top level elements and their children. (Note: not all properties can be inherited). The inheritance starts at the oldest ancestor and is passed on to its children and then their children and the children’s children and so on.

Inherited style can be overridden by declaring specific style to child element. For example if the EM element is not to inherit its parent P then own style must be declared to it. For example:

BODY {font-size: 10pt}
All text will be displayed in a 10 point font

BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}

All text except for the level 1 headings will be displayed in a 10 point font. H1 will be displayed in a 14 point font (or in a font that is 80% larger than the one set to BODY). If the element H1 contains other elements, e.g. EM then the EM element will also be displayed in a 14 point font (or 180%) it will inherit the property of the parent H1. If the EM element is to be displayed in some other font then own font properties must be declared to it, e.g:

BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
EM {font-size: 15pt} or EM {font-size: 110%}

The EM element will be displayed in a 15 point font or will be 10% larger than H1. NOTE: EM is, in this example, inside H1 therefore will inherit H1’s properties and not BODY’s.

The above declaration will display all EM elements in 15 point font or font that is 10% larger than font declared to the parent element. If this specific font is to apply to EM elements but only if they are inside H1 and not every occurrence of EM then EM must take a form of a contextual selector.

H1 EM {font-size: 15pt} or H1 EM {font-size: 110%}

In the example above EM is a contextual selector. It will be displayed in specified font only if it will be found in the context of H1.

Not all properties are inherited. One such property is background. However, since it’s initial value is transparent the background of the parent element will shine through by default unless it is explicitly set.

31. What is Extensible Stylesheet Language (XSL)?
XSL is a proposed styling language for formatting XML (eXtensible Markup Language) documents. The proposal was submitted to the W3C by Microsoft, Inso, and ArborText.

32. How do you make a tooltip that appears on hover?
The most simple way is to use the ‘title’ attribute like this…

“HTML

<span title=”Example of the title attribute in use”>like this</span>

CSS
a.tooltip {
position:relative;
cursor:help;
}
a.tooltip span {
display:none;
position:absolute;
top:1.5em;
left:0;
width:15em;
padding:0 2px;
}
a.tooltip:hover {
display:inline;
}
a.tooltip:hover span {
display:block;
border:1px solid gray;
background-color:white;
}

HTML

<a class=”tooltip” href=”#n”>Karl Marx<span>-info goes here-</span></a>

Without this part… a.tooltip:hover {
display:inline;
}

..it won’t work in IE.

The “#n” in the link is to prevent the page from jumping to the top if the link is clicked. The “href” part is necessary as it won’t work in IE without it.”

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.&#8221; : “http://www.&#8221;);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

try {
var pageTracker = _gat._getTracker(“UA-1855756-5″);
pageTracker._trackPageview();
} catch(err) {}

MNC php interview questions and answers

1) what is session_set_save_handler in PHP? session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

2) what is garbage collection? default time ? refresh time? Garbage Collection is an automated part of PHP , If the Garbage Collection process runs, it then analyzes any files in the /tmp for any session files that have not been accessed in a certain amount of time and physically deletes them. arbage Collection process only runs in the default session save directory, which is /tmp. If you opt to save your sessions in a different directory, the Garbage Collection process will ignore it. the Garbage Collection process does not differentiate between which sessions belong to whom when run. This is especially important note on shared web servers. If the process is run, it deletes ALL files that have not been accessed in the directory.

There are 3 PHP.ini variables, which deal with the garbage collector: PHP ini  value

name                                          default

session.gc_maxlifetime     1440 seconds or 24 minutes

session.gc_probability      1

session.gc_divisor              100

3) PHP how to know user has read the email? Using Disposition-Notification-To: in mailheader we can get read receipt.

Add the possibility to define a read receipt when sending an email.

It’s quite straightforward, just edit email.php, and add this at vars definitions:

var $readReceipt = null;

And then, at ‘createHeader’ function add:

if (!empty($this->readReceipt)) { $this->__header .= ‘Disposition-Notification-To: ‘ . $this->__formatAddress($this->readReceipt) . $this->_newLine; }

4) Runtime library loading ? without default mysql support, how to run mysql with php?

dl — Loads a PHP extension at runtime int dl ( string $library )

Loads the PHP extension given by the parameter library .

Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl()).

bool extension_loaded ( string $name ) — Find out whether an extension is loaded

Warning :This function has been removed from some SAPI’s in PHP 5.3.

5) what is XML-RPC ? XML-RPC is a remote procedure call protocol which uses XML to encode its calls and HTTP as a transport mechanism. An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.

6) default session time ? default session time in PHP is 1440 seconds or 24 minutes.

7) default session save path ? Default session save path id temporary folder /tmp

8) What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used) htmlentities() – Convert ALL special characters to HTML entities

9) how to do session using DB?

bool session_set_save_handler ( callback $open , callback $close , callback $read , callback $write , callback $destroy , callback $gc ) using this function we can store sessions in DB.

PHP has a built-in ability to override its default session handling. The function session_set_save_handler() lets the programmer specify which functions should actually be called when it is time to read or write session information. by overriding the default functions using session_set_save_handler handle we can store session in Db like below example

class SessionManager {

var $life_time;

function SessionManager() {

// Read the maxlifetime setting from PHP $this->life_time = get_cfg_var(“session.gc_maxlifetime”);

// Register this object as the session handler session_set_save_handler( array( &$this, “open” ), array( &$this, “close” ), array( &$this, “read” ), array( &$this, “write”), array( &$this, “destroy”), array( &$this, “gc” ) );

}

function open( $save_path, $session_name ) {

global $sess_save_path;

$sess_save_path = $save_path;

// Don’t need to do anything. Just return TRUE.

return true;

}

function close() {

return true;

}

function read( $id ) {

// Set empty result $data = ”;

// Fetch session data from the selected database

$time = time();

$newid = mysql_real_escape_string($id); $sql = “SELECT `session_data` FROM `sessions` WHERE `session_id` = ‘$newid’ AND `expires` > $time”;

$rs = db_query($sql); $a = db_num_rows($rs);

if($a > 0) { $row = db_fetch_assoc($rs); $data = $row['session_data'];

}

return $data;

}

function write( $id, $data ) {

// Build query $time = time() + $this->life_time;

$newid = mysql_real_escape_string($id); $newdata = mysql_real_escape_string($data);

$sql = “REPLACE `sessions` (`session_id`,`session_data`,`expires`) VALUES(‘$newid’, ‘$newdata’, $time)”;

$rs = db_query($sql);

return TRUE;

}

function destroy( $id ) {

// Build query $newid = mysql_real_escape_string($id); $sql = “DELETE FROM `sessions` WHERE `session_id` = ‘$newid'”;

db_query($sql);

return TRUE;

}

function gc() {

// Garbage Collection

// Build DELETE query. Delete all records who have passed the expiration time $sql = ‘DELETE FROM `sessions` WHERE `expires` < UNIX_TIMESTAMP();';

db_query($sql);

// Always return TRUE return true;

}

}

10) how to track user logged out or not? when user is idle ? By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes.

The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server.

11) how to track no of user logged in ? whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out or sesion expire make it inactive. At any time by counting the no: of active records we can get the no: of visitors.

12) in PHP for pdf which library used?

The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module.

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.

13) for image work which library?

You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

14) what is oops? encapsulation? abstract class? interface?

Object oriented programming language allows concepts such as modularity, encapsulation, polymorphism and inheritance.

Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned.

Abstract class is a template class that contains such things as variable declarations and methods, but cannot contain code for creating new instances. A class that contains one or more methods that are declared but not implemented and defined as abstract. Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

15) what is design pattern? singleton pattern?

A design pattern is a general reusable solution to a commonly occurring problem in software design.

The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves.

16) what are magic methods?

Magic methods are the members functions that is available to all the instance of class Magic methods always starts with “__”. Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()

17) what is magic quotes? Magic Quotes is a process that automagically escapes incoming data to the PHP script. It’s preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

18) diff b/w php4 & php5 ? In PHP5 1 Implementation of exceptions and exception handling

2. Type hinting which allows you to force the type of a specific argument as object, array or NULL

3. Overloading of methods through the __call function

4. Full constructors and destructors etc through a __constuctor and __destructor function

5. __autoload function for dynamically including certain include files depending on the class you are trying to create.

6 Finality : can now use the final keyword to indicate that a method cannot be overridden by a child. You can also declare an entire class as final which prevents it from having any children at all.

7 Interfaces & Abstract Classes

8 Passed by Reference : In PHP4, everything was passed by value, including objects. This has changed in PHP5 — all objects are now passed by reference.

9 An __clone method if you really want to duplicate an object

19) in php4 can you define a class? how to call class in php4? can you create object in php4?

yes you can define class and can call class by creating object of that class. but the diff b/w php4 & php5 is that in php4 everything was passed by value where as in php5 its by reference. And also any value change in reference object changes the actucal value of object also. And one more thing in introduction of __clone object in PHP5 for copying the object.

20) types of error? how to set error settings at run time?

here are three basic types of runtime errors in PHP:

1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script – for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all – although you can change this default behaviour.

2. Warnings: These are more serious errors – for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.

3. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP?s default behaviour is to display them to the user when they take place.

by using ini_set function.

21) what is cross site scripting? SQL injection?

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts.

SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed

22) what is outerjoin? inner join?

OUTER JOIN in SQL allows us to retrieve all values in a certain table regardless of whether these values are present in other tables

An inner join requires each record in the two joined tables to have a matching record. An inner join essentially combines the records from two tables (A and B) based on a given join-predicate.

23) what is URL rewriting?

Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better than Dynamic URLs because of a number of reasons 1. Static URLs typically Rank better in Search Engines. 2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages. 3. Static URLs are always more friendlier looking to the End Users.

along with this we can use URL rewriting in adding variables [cookies] to the URL to handle the sessions.

24) what is the major php security hole? how to avoid?

1. Never include, require, or otherwise open a file with a filename based on user input, without thoroughly checking it first. 2. Be careful with eval() Placing user-inputted values into the eval() function can be extremely dangerous. You essentially give the malicious user the ability to execute any command he or she wishes! 3. Be careful when using register_globals = ON It was originally designed to make programming in PHP easier (and that it did), but misuse of it often led to security holes 4. Never run unescaped queries 5. For protected areas, use sessions or validate the login every time. 6. If you don’t want the file contents to be seen, give the file a .php extension.

25) whether PHP supports Microsoft SQL server ? The SQL Server Driver for PHP v1.0 is designed to enable reliable, scalable integration with SQL Server for PHP applications deployed on the Windows platform. The Driver for PHP is a PHP 5 extension that allows the reading and writing of SQL Server data from within PHP scripts. using MSSQL or ODBC modules we can access Microsoft SQL server.

26) what is MVC? why its been used? Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.

WHY ITS NEEDED IS 1 Modular separation of function 2 Easier to maintain 3 View-Controller separation means:

A — Tweaking design (HTML) without altering code B — Web design staff can modify UI without understanding code

27) what is framework? how it works? what is advantage?

In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful. Advantages : Consistent Programming Model Direct Support for Security Simplified Development Efforts Easy Application Deployment and Maintenance

28) what is CURL?

CURL means Client URL Library

curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.

CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

29) HOW we can transfer files from one server to another server without web forms?

using CURL we can transfer files from one server to another server. ex:

Uploading file

<?php

/* http://localhost/upload.php: print_r($_POST); print_r($_FILES); */

$ch = curl_init();

$data = array(‘name’ => ‘Foo’, ‘file’ => ‘@/home/user/test.png’);

curl_setopt($ch, CURLOPT_URL, ‘http://localhost/upload.php&#8217;);

curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch); ?>

output:

Array ( [name] => Foo ) Array ( [file] => Array ( [name] => test.png
[type] => image/png [tmp_name] => /tmp/phpcpjNeQ [error] => 0 [size] => 279 )   )  

  30) using CSS can we have a scroll to table? 
No table won't support scrolling of its data. but we can do another workaround like placing a table
 in a DIV  layer and setting the DIV css property to overflow:auto will do the trick.  

  31) how to increase session time in PHP ? 
In php.ini by setting session.gc_maxlifetime and session.cookie_lifetime values
we can change the session time in PHP.   

 32) what is UI? What are the five primary user-interface components?  
 A user interface is a means for human beings to interact with computer-based "tools" and"messages".
One presumed goal is to make the user's experience productive, efficient, pleasing, and humane.
 The primary components of UIs are  a) metaphors (fundamental concepts communicated
 through words, images, sounds, etc.)
b) mental models (structure of data, functions, tasks, roles, jobs, and people in organizations of work
and/or play)
 c) navigation (the process of moving through the mental models)
d) interaction (all input-output sequences and means for conveying feedback)
 e) and appearance (visual, verbal, acoustic, etc.).
33) How can I set a cron and how can I execute it in Unix, Linux, and windows?

Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals.

In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.

The easiest way to use crontab is via the crontab command. # crontab This command ‘edits’ the crontab.

Upon employing this command, you will be able to enter the commands that you wish to run.

My version of Linux uses the text editor vi. You can find information on using vi here.

The syntax of this file is very important – if you get it wrong, your crontab will not function properly.

The syntax of the file should be as follows: minutes hours day_of_month month day_of_week command All the variables, with the exception of the command itself, are numerical constants.

In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows: Minutes: 0-59 Hours: 0-23 Day_of_month: 1-31 Month: 1-12 Weekday: 0-6 We can also include multiple values for each entry, simply by separating each value with a comma.

command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file. So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line: 15 8 * * 2 /path/to/scriptname This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module).

The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content.

For our purposes, I’ll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell.

If you’re using an RPM-based system (e.g. Redhat or Mandrake), type the following: # wget help If you are greeted with a wget package identification, it is installed in your system.

You could execute the PHP by invoking wget on the URL to the page, like so: # wget http://www.example.com/file.php Now, let’s go back to the mailstock.php file we created in the first part of this article.

We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I’m located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.

This is what my crontab will look like: 0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php

34)Difference b/w OOPS concept in php4 and PHP5 ?

version 4’s object-oriented functionality was rather hobbled. Although the very basic premises of objectoriented programming (OOP) were offered in version 4, several deficiencies existed, including: • An unorthodox object-referencing methodology • No means for setting the scope (public, private, protected, abstract) of fields and methods • No standard convention for naming constructors • Absence of object destructors • Lack of an object-cloning feature • Lack of support for interfaces

35) Difference b/w MyISAM and InnoDB in MySQL?

Ans:

  • The big difference between MySQL Table Type MyISAM and InnoDB is that InnoDB supports transaction
  • InnoDB supports some newer features: Transactions, row-level locking, foreign keys
  • InnoDB is for high volume, high performance
  • use MyISAM if they need speed and InnoDB for data integrity.
  • InnoDB has been designed for maximum performance when processing large data volumes
  • Even though MyISAM is faster than InnoDB
  • InnoDB supports transaction. You can commit and rollback with InnoDB but with MyISAM once you issue a command it’s done
  • MyISAM does not support foreign keys where as InnoDB supports
  • Fully integrated with MySQL Server, the InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files. InnoDB tables can be of any size even on operating systems where file size is limited to 2GB.
  • 36) how to set session tiem out at run time or how to extend the session timeout at runtime?

    Ans:

    Sometimes it is necessary to set the default timeout period for PHP. To find out what the default (file-based-sessions) session timeout value on the server is you can view it through a ini_get command:

    // Get the current Session Timeout Value
    $currentTimeoutInSecs = ini_get(’session.gc_maxlifetime’);

    Change the Session Timeout Value

    // Change the session timeout value to 30 minutes
    ini_set(’session.gc_maxlifetime’, 30*60);

    If you have changed the sessions to be placed inside a Database occasionally implementations will specify the expiry manually. You may need to check through the session management class and see if it is getting the session timeout value from the ini configuration or through a method parameter (with default). It may require a little hunting about.

    CSS Interview Questions And Answers – important good answers

    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.

    How do I eliminate the blue border around linked images?
    in your CSS, you can specify the border property for linked images:

    a img { border: none ; }
    However, note that removing the border that indicates an image is a link makes it harder for users to distinguish quickly and easily which images on a web page are clickable.

    Why call the subtended angle a “pixel”, instead of something else (e.g. “subangle”)?
    In most cases, a CSS pixel will be equal to a device pixel. But, as you point out, the definition of a CSS pixel will sometimes be different. For example, on a laser printer, one CSS pixel can be equal to 3×3 device pixels to avoid printing illegibly small text and images. I don’t recall anyone ever proposing another name for it. Subangle? Personally, I think most people would prefer the pragmatic “px” to the non-intuitive “sa”.

    Why was the decision made to make padding apply outside of the width of a ‘box’, rather than inside, which would seem to make more sense?
    It makes sense in some situations, but not in others. For example, when a child element is set to width: 100%, I don’t think it should cover the padding of its parent. The box-sizing property in CSS3 addresses this issue. Ideally, the issue should have been addressed earlier, though.

    How to use CSS to separate content and design ?
    The idea here is that all sites contain two major parts, the content: all your articles, text and photos and the design: rounded corners, colors and effects. Usually those two are made in different parts of a webpage?s lifetime. The design is determined at the beginning and then you start filling it with content and keep the design fixed.

    In CSS you just add the nifty -tag I’ve told you about to the head of your HTML document and you have created a link to your design. In the HTML document you put content only, and that link of yours makes sure it looks right. You can also use the exact same link on many of your pages, giving them all of them the same design. You want to add content? Just write a plain HTML document and think about marking things up like ?header? instead of ?big blue header? and use CSS to make all headers look the way you want!

    Some examples of good and bad coding. What’s wrong with this?
    Welcome to my page

    Comment: The font-tag is design and design shouldn?t be in the HTML document. All design should be in the CSS-file! Instead do this:

    In the HTML:

    Welcome to my page

    In the CSS:
    h1 { font-size: 2em; }

    One more example:

    An error occurred

    This looks right doesn?t it? But if you look up what stands for you quickly find bold. But bold is certainly design, so it still doesn?t belong in the HTML document. A better choice is that stands for emphasis or simply ?this piece of text is important?. So instead of saying ?this text looks like this? you are saying ?this text is important? and you let the looks be decided by the CSS. Seems like a minor change, but it illustrates how to select your tags. Use this instead:

    In the HTML:
    An error occured

    In the CSS:
    em {
    font-weight: bold;
    color: Red;
    }

    One last example:

    first link
    second link

    Can CSS be used with other than HTML documents?
    Yes. CSS can be used with any ny structured document format. e.g. XML, however, the method of linking CSS with other document types has not been decided yet.

    Can Style Sheets and HTML stylistic elements be used in the same document?
    Yes. Style Sheets will be ignored in browsers without CSS-support and HTML stylistic elements used.

    What are pseudo-classes?
    Pseudo-classes are fictional element types that do not exist in HTML. In CSS1 there is only one element type which can be classed this way, namely the A element (anchor). By creating three fictional types of the A element individual style can be attached to each class. These three fictional element types are: A as unvisited link, A as active link and A as visited link. Pseudo-classes are created by a colon followed by pseudo-class’s name. They can also be combined with normal classes, e.g.:

    A:link {background: black; color: white}
    A:active {background: black; color: red}
    A:visited {background: transparent; color: black}

    This anchor (or rather these anchors) will be displayed as declared above

    A.foot:link {background: black; color: white}
    A.foft:active {background; black: color: red}
    A.foot:visited {background: transparent; color: black}

    This anchor and all other anchors with CLASS foot will be displayed as declared above

    How do I design for backward compatibility using Style Sheets?
    Existing HTML style methods (such as and ) may be easily combined with style sheet specification methods. Browsers that do not understand style sheets will use the older HTML formatting methods, and style sheets specifications can control the appearance of these elements in browsers that support CSS1.

    As a reader, how can I make my browser recognize my own style sheet?
    Netscape
    It is not possible to do this in Netscape yet (as of version 4.0.)
    Internet Explorer 3.0 (Win95/NT)
    [It is possible to do this at least in Windows95/NT, but no user interface is provided. Unknown how this might be accomplished on other operating systems.]

    1. Open the Registry editor (Start..Run..regedit..ENTER)
    2. Under the ‘HKEY_LOCAL_MACHINE\Software\Microsoft\InternetExplorer\Styles’ key, Edit..New..String Value
    3. The new value should be called ‘StyleSheet Pathname’
    4. For the value, type in the full directory path of your .css style sheet.

    Internet Explorer 4.0 (Win95/NT)

    1. Under the View menu, select ‘Internet Options’.
    2. Under the ‘General’ tab, choose the ‘Accessibility’ button.
    3. Choose the ‘Format documents using my style sheet’ check box and ‘Browse…’ to the location of your .css style sheet.

    How do I get rid of the gap under my image?
    Images are inline elements, which means they are treated in the same way as text. Most people kind of know this – they know that if you use ‘text-align:center’ on an image it will be centred. What many people don’t realise is that this means you will have a gap underneath an image. This gap is for the descenders of letters like j,q,p,y and g. To get rid of this gap you need to make the image block-level – like this :

    CSS
    img {display:block;}

    One problem that this can cause is when you want to have a few images next to each other – if they are block-level, they won’t be next to each other. To get around that, you can use float:left. Of course, this might present another problem – maybe you don’t want the image to float left. In this case, you can use an unordered list like this :

    CSS
    ul, li {
    list-style-type:none;
    padding:0;
    margin:0 auto;
    }
    ul {
    width:150px;
    }
    li {
    float:left;
    }
    HTML


    Why use Style Sheets?
    Style sheets allow a much greater degree of layout and display control than has ever been possible thus far in HTML. The amount of format coding necessary to control display characteristics can be greatly reduced through the use of external style sheets which can be used by a group of documents. Also, multiple style sheets can be integrated from different sources to form a cohesive tapestry of styles for a document. Style sheets are also backward compatible – They can be mixed with HTML styling elements and attributes so that older browsers can view content as intended.

    What does the “Cascading” in “Cascading Style Sheets” mean?
    Style Sheets allow style information to be specified from many locations. Multiple (partial) external style sheets can be referenced to reduce redundancy, and both authors as well as readers can specify style preferences. In addition, three main methods can be employed by an author to add style information to HTML documents, and multiple approaches for style control are available in each of these methods. In the end, style can be specified for a single element using any, or all, of these methods. What style is to be used when there is a direct conflict between style specifications for an element?
    Cascading comes to the rescue. A document can have styles specified using all of these methods, but all the information will be reduced to a single, cohesive “virtual” Style Sheet. Conflict resolution is based on each style rule having an assigned weight according to its importance in the scheme of things. A rule with a higher overall importance will carry a higher weight. This will be used in place of a competing style rule with a lower weight/importance. A hierarchy of competing styles is thus formed creating a “cascade” of styles according to their assigned weights. The algorithm used to determine this cascading weight scale is fairly complex.

    What is CSS rule ‘at-rule’?
    There are two types of CSS rules: ruleset and at-rule. At-rule is a rule that applies to the whole style sheet and not to a specific selector only (like in ruleset). They all begin with the @ symbol followed by a keyword made up of letters a-z, A-Z, digits 0-9, dashes and escaped characters, e.g. @import or @font-face.

    What is selector?
    CSS selector is equivalent of HTML element(s). It is a string identifying to which element(s) the corresponding declaration(s) will apply and as such the link between the HTML document and the style sheet.
    For example in P {text-indent: 10pt} the selector is P and is called type selector as it matches all instances of this element type in the document.
    in P, UL {text-indent: 10pt} the selector is P and UL (see grouping); in .class {text-indent: 10pt} the selector is .class (see class selector).

    What is CLASS selector?
    Class selector is a “stand alone” class to which a specific style is declared. Using the CLASS attribute the declared style can then be associated with any HTML element. The class selectors are created by a period followed by the class’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. (Note: in HTML the value of the CLASS attribute can contain more characters).It is a good practice to name classes according to their function than their appearance.

    .footnote {font: 70%} /* class as selector */

    This element is associated with the CLASS footnote


    And so is this

    What is CSS declaration?
    CSS declaration is style attached to a specific selector. It consists of two parts; property which is equivalent of HTML attribute, e.g. text-indent: and value which is equivalent of HTML value, e.g. 10pt. NOTE: properties are always ended with a colon.

    What is ‘important’ declaration?
    Important declaration is a declaration with increased weight. Declaration with increased weight will override declarations with normal weight. If both reader’s and author’s style sheet contain statements with important declarations the author’s declaration will override the reader’s.

    BODY {background: white ! important; color: black}

    In the example above the background property has increased weight while the color property has normal.

    What is cascade?
    Cascade is a method of defining the weight (importance) of individual styling rules thus allowing conflicting rules to be sorted out should such rules apply to the same selector.

    Declarations with increased weight take precedence over declaration with normal weight:

    P {color: white ! important} /* increased weight */
    P (color: black} /* normal weight */

    Are Style Sheets case sensitive?
    No. Style sheets are case insensitive. Whatever is case insensitive in HTML is also case insensitive in CSS. However, parts that are not under control of CSS like font family names and URLs can be case sensitive – IMAGE.gif and image.gif is not the same file.

    How do I make my div 100% height?
    You need to know what the 100% is of, so the parent div must have a height set. One problem that people often come up against is making the main page fill the screen if there’s little content. You can do that like this :
    CSS
    body, html {
    height:100%;
    }
    body {
    margin:0;
    padding:0;
    }
    #wrap {
    position:relative;
    min-height:100%;
    }
    * html #wrap {
    height:100%;
    }

    Here, the #wrap div goes around your whole page – it’s like a sub-body.

    You need to use ‘min-height’ rather than ‘height’ for Firefox because otherwise it will set it to 100% of the viewport and no more. Internet Explorer, being well… crap, treats ‘height’ as it should be treating ‘min-height’ which it doesn’t recognise. (You can target IE by preceding your code with ‘ * html ‘).

    To make floated divs within this #wrap div 100% of the #wrap div… well that’s more difficult. I think the best way is to use the ‘faux columns’ technique which basically means that you put the background in your body rather than your columns. If the body has columns and your floats don’t then it looks like your floated content is in a column that stretches to the bottom of the page. I’ve used this technique in my layout demos.

    The problem is often not that the columns aren’t 100% height, but that they’re not equal lengths. Columns usually don’t start from the top of the page and end at the bottom – there’s often a header and a footer or sometimes, more interesting designs don’t have a recognisable columnar layout, but do require div boxes to be equal heights. This can be done with the aid of a couple of images and some css or with some javascript.

    What is property?
    Property is a stylistic parameter (attribute) that can be influenced through CSS, e.g. FONT or WIDTH. There must always be a corresponing value or values set to each property, e.g. font: bold or font: bold san-serif.

    How do I write my style sheet so that it gracefully cascades with user’s personal sheet ?
    You can help with this by setting properties in recommended places. Style rules that apply to the whole document should be set in the BODY element — and only there. In this way, the user can easily modify document-wide style settings.

    What are pseudo-elements?
    Pseudo-elements are fictional elements that do not exist in HTML. They address the element’s sub-part (non-existent in HTML) and not the element itself. In CSS1 there are two pseudo-elements: ‘first-line pseudo-element’ and ‘first-letter pseudo-element’. They can be attached to block-level elements (e.g. paragraphs or headings) to allow typographical styling of their sub-parts. Pseudo-element is created by a colon followed by pseudo-element’s name, e.g:

    P:first-line
    H1:first-letter

    and can be combined with normal classes; e.g:

    P.initial:first-line

    First-line pseudo-element allows sub-parting the element’s first line and attaching specific style exclusively to this sub-part; e.g.:

    P.initial:first-line {text-transform: uppercase}

    The first line of this paragraph will be displayed in uppercase letters

    First-letter pseudo-element allows sub-parting the element’s first letter and attaching specific style exclusively to this sub-part; e.g.:

    P.initial:first-letter { font-size: 200%; color: red}

    The first letter of this paragraph will be displayed in red and twice as large as the remaining letters

    As a developer who works with CSS every day, I find one complication that continues to bother me in my daily work. Support for CSS has always been good on the horizontal scope, but vertical positioning has always been quite complicated. Alone the procedure to affix a footer to the bottom of a screen in dependance of the amount of content is unnecessarily difficult. The old table method provided much easier methods for this. What are your thoughts on this and do you see improvement following in future CSS revisions?
    Indeed, the CSS formatting model allows more control horizontally than vertically. This is due to (typically) having a known width, but an unknown height. As such, the height is harder to deal with. However, CSS2 fixed positioning allows you to place content relative to the viewport (which is CSS-speak for window) instead of the document. For example, by setting position: fixed; bottom: 0 on an element, it will stick to the bottom. This works in Opera, Safari and Mozilla-based browsers. IE6 doesn’t support it, however. It remains to be seen if IE7 will support it.

    How can I make a page look the same in e.g. NS and MSIE ?
    The simple answer is, you can’t, and you shouldn’t waste your time trying to make it exactly the same. Web browsers are allowed, per definition, to interpret a page as they like, subject to the general rules set down in the HTML and CSS specifications. As a web author you can not have a prior knowledge of the exact situation and/or medium that will be used to render your page, and it’s almost always rather counterproductive to try to control that process. There is no necessity for a well-written page to look the same in different browsers. You may want to strive to ensure that it looks good in more than one browser, even if the actual display (in the case of graphical browsers) comes out a bit different. “Looking good” can be achieved by adopting sensible design and guidelines, such as not fixing the size or face of your fonts, not fixing the width of tables, etc? Don’t fight the medium; most web users only use one browser and will never know, or bother to find out, that your page looks different, or even “better”, in any other browser.

    Is there anything that CAN’T be replaced by Style Sheets?
    Quite a bit actually. Style sheets only specify information that controls display and rendering information. Virtual style elements that convey the NATURE of the content can not be replaced by style sheets, and hyperlinking and multimedia object insertion is not a part of style sheet functionality at all (although controlling how those objects appear IS part of style sheets functionality.) The CSS1 specification has gone out of its way to absorb ALL of the HTML functionality used in controlling display and layout characteristics. For more information on the possible properties in CSS, see the Index DOT Css Property Index.
    Rule of Thumb: if an HTML element or attribute gives cues as to how its contents should be displayed, then some or all of its functionality has been absorbed by style sheets.

    Can I include comments in my Style Sheet?
    Yes. Comments can be written anywhere where whitespace is allowed and are treated as white space themselves. Anything written between /* and */ is treated as a comment (white space). NOTE: Comments cannot be nested.

    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. By singling out one occurrence of an element the unique value can be declared to said element.

    CSS
    #eva1 {background: red; color: white}
    .eva2 {background: red; color: white}

    HTML – ID

    Paragraph 1 – ONLY THIS occurrence of the element P (or single occurrence of some other element) can be identified as eva1


    Paragraph 2 – This occurrence of the element P CANNOT be identified as eva1

    HTML – CLASS

    Paragraph 1 – This occurrence of the element P can be classified as eva2


    Paragraph 2 – And so can this, as well as occurrences of any other element,

    How to make text-links without underline?
    a:link, a:visited {text-decoration: none}

    or

    …will show the links without underlining. However, suppressing the underlining of links isn’t a very smart idea as most people are used to having them underlined. Also, such links are not spotted unless someone coincidentally runs a mouse over them. If, for whatever reason, links without underline are required background and foreground colors can be instead declared to them so that they can be distinguished from other text, e.g.;

    a:link, a:visited {text-decoration: none; background: red; color: blue}

    or

    Both background and foreground colors should be specified as the property that is not specified can be overridden by user’s own settings.

    How do you make a tool tip that appears on hover?
    The most simple way is to use the ‘title’ attribute like this…

    HTML
    like this

    CSS
    a.tooltip {
    position:relative;
    cursor:help;
    }
    a.tooltip span {
    display: none;
    position:absolute;
    top:1.5em;
    left:0;
    width:15em;
    padding:0 2px;
    }
    a.tooltip:hover {
    display:inline;
    }
    a.tooltip:hover span {
    display:block;
    border:1px solid gray;
    background-color:white;
    }

    HTML

    Karl Marx-info goes here-

    Without this part… a.tooltip:hover {
    display:inline;
    }

    ..it won’t work in IE.

    The “#n” in the link is to prevent the page from jumping to the top if the link is clicked. The “href” part is necessary as it won’t work in IE without it.

    Which characters can CSS-names contain?
    The CSS-names; names of selectors, classes and IDs 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. The names cannot start with a dash or a digit. (Note: in HTML the value of the CLASS attribute can contain more characters).

    What browsers support style sheets? To what extent?
    Microsoft’s Internet Explorer version 3.0 Beta 2 and above supports CSS, as does Netscape Communicator 4.0 Beta 2 and above and Opera 3.5 and above. Take note that the early implementations in these browsers did not support ALL of the properties and syntax described in the full CSS1 specification and beyond. Later versions have been getting much closer to full CSS1 compliance, but then comes the next hurdle – CSS2…it was such a big leap over CSS1 that it has taken the browsers years to come close to supporting a majority of CSS2’s features. Mozilla and Opera’s current versions both offer excellent CSS standards compliance. The Macintosh version of Internet Explorer is said to be very impressive in its CSS capabilities as well, but PC IE lags behind these implementations. Quite a few other implementations of CSS now exist in browsers that are not as widely-used (such as Amaya, Arena and Emacs-W3), but coverage of features in these documents currently only covers Internet Explorer, NCSA Mosaic, Netscape and Opera browsers.

    What is cascading order?
    Cascading order is a sorting system consisting of rules by which declarations are sorted out so that there are not conflicts as to which declaration is to influence the presentation. The sorting begins with rule no 1. If a match is found the search is over. If there is no match under rule no 1 the search continues under rule no 2 and so on.

    1. Find all declarations that apply to a specific selector/property and Declare the specified style if the selector matches the element if there isn’t any Let the element inherit its parent property if there isn’t any Use initial value

    2. Sort by weight (! important) Increased weight take precedence over normal weight

    3. Sort by origin Rules with normal weight declared in author’s style sheet will override rules with normal weight declared in user’s personal style sheets Rules with increased weight declared in user’s personal style sheet will override rules with normal weight declared in author’s style sheet Rules with increased weight declared in author’s style sheet will override rules with increased weight declared in user’s personal style sheets Author’s and user’s rules will override UA’s default style sheet.

    4. Sort by selector’s specificity More specific selector will override less specific one: ID-selector (most specific), followed by Classified contextual selectors (TABLE P EM.fot) Class selectors (EM.fot) Contextual selectors – the “lower down” the more weight, (TABLE P EM), (TABLE P EM STRONG) – STRONG has more weight than EM.

    5. Sort by order specified If two rules have the same weight, the latter specified overrides ones specified earlier. Style sheets are sorted out as follows: The STYLE attribute (inline style) overrides all other styles The Style element (embedded style) overrides linked and imported sheets The LINK element (external style) overrides imported style The @import statement – imported style sheets also cascade with each other in the same order as they are imported

    Why shouldn’t I use fixed sized fonts ?
    Only in very rare situations we will find users that have a “calibrated” rendering device that shows fixed font sizes correct. This tells us that we can never know the real size of a font when it’s rendered on the user end. Other people may find your choice of font size uncomfortable. A surprisingly large number of people have vision problems and require larger text than the average. Other people have good eyesight and prefer the advantage of more text on the screen that a smaller font size allows. What is comfortable to you on your system may be uncomfortable to someone else. Browsers have a default size for fonts. If a user finds this inappropriate, they can change it to something they prefer. You can never assume that your choice is better for them. So, leave the font size alone for the majority of your text. If you wish to change it in specific places (say smaller text for a copyright notice at the bottom of page), use relative units so that the size will stay in relationship to what the user may have selected already. Remember, if people find your text uncomfortable, they will not bother struggling with your web site. Very few (if any) web sites are important enough to the average user to justify fighting with the author’s idea of what is best.

    How do you make a whole div into a link?
    You can’t put ‘a’ tags around a div, but you can do this with javascript :

    HTML

    … stuff goes here …

    If you want to use an empty div with a background image as a link instead of putting your image into the html, you can do something like this:

    CSS
    #empty {
    background-image:url(wine.jpg);
    width:50px;
    height:50px;
    margin:auto;
    }
    #empty a {
    display:block;
    height:50px;
    }
    * html #empty a {
    display:inline-block;
    }

    HTML

    How do I have links of different colors on the same page?
    Recommending people to use classes in their ‘a’ tags like this :

    CSS
    a.red {
    color:red;
    }
    a.blue {
    color:blue;
    }

    HTML
    A red link
    A blue link

    This is a valid way to do it, but usually, this isn’t what a page looks like – two links next to each other with different colours – it’s usually something like a menu with one kind of link and main body text or another menu with different links. In this (normal) situation, To go higher up the cascade to style the links. Something like this :

    CSS
    a {
    color:red;
    }
    #menu a {
    color:blue;
    }

    HTML

    There’s a blue link here.

    What is shorthand property?
    Shorthand property is a property made up of individual properties that have a common “addressee”. For example properties: font-weight, font-style, font-variant, font-size, font-family, refer to the font. To reduce the size of style sheets and also save some keystrokes as well as bandwidth they can all be specified as one shorthand property font, e.g.:

    H1 {font-weight: bold;
    font-style: italic;
    font-variant: small-caps;
    font-size: 160%;
    font-family: serif}

    can be all shorthanded to a space separated list:

    H1 {font: bold italic small-caps 160% serif}

    Note: To make things even simpler the line-height property can be specified together with the font-size property:

    H1 {font: bold italic small-caps 160%/170% serif}

    How to use CSS building a standards based HTML template?
    It should:
    1. Contain: header, navigation, content, footer
    2. Use well-structured HTML
    3. Be error-free and encourage good coding

    Let?s start with number one there:

    HTML document split up in four parts all with different meaning, use the
    -tag. Div is short for ?division? and isn?t header, navigation and so on …

    !DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN”>

    Your own page title

    Content

    Some sample content, add your own here

    body {
    background-color: Green;
    }
    div {
    border: 3px solid Black;
    padding: 7px;
    width: 600px;
    }
    h1, h2, h3, h4, h5, h6 {
    margin: 0;
    }

    #navigation {
    float: left;
    width: 150px;
    }
    #content {
    float: left;
    width: 430px;
    }
    #footer {
    clear: both;
    }

    What is value?
    Value is a ‘physical’ characteristic of the property. Property declares what should be formatted, e.g. FONT while value suggests how the property should be formatted, e.g. 12pt. By setting the value 12pt to the property FONT it is suggested that the formatted text be displayed in a 12 point font. There must always be a corresponding property to each value or set of values.

    H1 {font: bold 180%}
    In the example above the H1 selector is declared the FONT property which in its turn is declared the values BOLD and 180%.
    The values suggesting alternatives are specified in a comma separated list, e.g.
    H1 {font-family: font1, font2}

    What is initial value?
    Initial value is a default value of the property, that is the value given to the root element of the document tree. All properties have an initial value. If no specific value is set and/or if a property is not inherited the initial value is used. For example the background property is not inherited, however, the background of the parent element shines through because the initial value of background property is transparent.

    Hello World


    Content of the element P will also have red background
    How frustrating is it to write a specification knowing that you’re at the browser vendors’ mercy?
    That’s part of the game. I don’t think any specification has a birthright to be fully supported by all browsers. There should be healthy competition between different specifications. I believe simple, author-friendly specifications will prevail in this environment.
    Microformats are another way of developing new formats. Instead of having to convince browser vendors to support your favorite specification, microformats add semantics to HTML through the CLASS attribute. And style it with CSS.

    How far can CSS be taken beyond the web page–that is, have generalized or non-web specific features for such things as page formatting or type setting?
    Yes, it’s possible to take CSS further in several directions. W3C just published a new Working Draft which describes features for printing, e.g., footnotes, cross-references, and even generated indexes.
    Another great opportunity for CSS is Web Applications. Just like documents, applications need to be styled and CSS is an intrinsic component of AJAX. The “AJAX” name sounds great.

    How To Style Table Cells?
    Margin, Border and Padding are difficult to apply to inline elements. Officially, the

     

     

    tag is a block level element because it can contain other block level elements (see Basics – Elements).
    If you need to set special margins, borders, or padding inside a table cell, then use this markup: yourtext

    to apply the CSS rules to the div inside the cell.

    How To Style Forms?
    Forms and form elements like SELECT, INPUT etc. can be styled with CSS – partially.
    Checkboxes and Radiobuttons do not yet accept styles, and Netscape 4.xx has certain issues, but here is a tutorial that explains the application of CSS Styles on Form Elements.

    How do I get my footer to sit at the bottom…?
    Need a div which makes space at the bottom of the main page (inside the #wrap div). Then, the footer (being inside #wrap) can be placed in that space by using absolute positioning. Like this :

    CSS body, html {
    height:100%;
    }
    body {
    margin:0;
    padding:0;
    }
    #wrap {
    position:relative;
    width:780px;
    margin:auto; min-height:100%;
    }
    * html #wrap {
    height:100%;
    }
    #clearfooter {
    height:50px;
    overflow:hidden;
    }
    #footer {
    position:absolute;
    bottom:0;
    width:100%;
    height:50px;
    }

    HTML

    …content goes here… 

    Can I attach more than one declaration to a selector?
    Yes. If more than one declaration is attached to a selector they must appear in a semi colon separated list, e.g.;

    Selector {declaration1; declaration2}
    P {background: white; color: black}

    Border around a table?
    Try the following:

    .tblboda {
    border-width: 1px;
    border-style: solid;
    border-color: #CCCCCC;
    }
    /*color, thickness and style can be altered*/

    You put this style declaration either in
    an external stylesheet, or you can stuff it in
    the section, like:

    (here you can place your styles)

    and apply it to the table as follows:

    Content text and more content

    That should give you a grey thin border around this table.

    If you want the border to ‘shrink wrap’ around the table, then you have to use the tag instead the
    tag. But that is not quite proper CSS or HTML, because a is for inline elements. A table is not an inline element, therefore the correct tag is a

    . If you play around with it a bit then you have a good chance to achieve what you want and still have correct HTML/CSS.The other way would be that you apply the class .tblboda directly to the table (for IE and other contemporary browsers), like 

    and you define another class for each stylesheet: .tblboda2In the NN4.xx stylesheet, you use the same properties as above, and in the IE and other contemporary browsers you carefully set all those properties to default, like {border-style: none;}

    Then you wrap the table in the

    with the class .tblboda2 (NN4.xx does that) (IE a.o.c.b. don’t do anything, because the border-style is set to “none” = no border at all).This way you have a table that is wrapped in a nice little border: .tblboda2 for NN4.xx, .tblboda for IE and other modern browsers. 

    How do you target a certain browser?
    IE can be targetted by preceding your properties with ‘* html’. For example…

    #nav {
    position:fixed;
    }
    * html #nav { /* this will target IE */
    position:absolute;
    }

    Another way to target IE is with conditional comments. Put this (below) in the head – just before the closing tag – and put anything you want to be directed only at IE in another stylesheet.

    If you need to target IE5x…

    #wrap {
    width:760px; /* for IE5x */
    w\idth:780px; /* for all other major browsers */
    }

    How does inheritance work?
    HTML documents are structured hierarchically. There is an ancestor, the top level element, the HTML element, from which all other elements (children) are descended. As in any other family also children of the HTML family can inherit their parents, e.g. color or size.

    By letting the children inherit their parents a default style can be created for top level elements and their children. (Note: not all properties can be inherited). The inheritance starts at the oldest ancestor and is passed on to its children and then their children and the children’s children and so on.

    Inherited style can be overridden by declaring specific style to child element. For example if the EM element is not to inherit its parent P then own style must be declared to it. For example:

    BODY {font-size: 10pt}
    All text will be displayed in a 10 point font

    BODY {font-size: 10pt}
    H1 {font-size: 14pt} or H1 {font-size: 180%}

    All text except for the level 1 headings will be displayed in a 10 point font. H1 will be displayed in a 14 point font (or in a font that is 80% larger than the one set to BODY). If the element H1 contains other elements, e.g. EM then the EM element will also be displayed in a 14 point font (or 180%) it will inherit the property of the parent H1. If the EM element is to be displayed in some other font then own font properties must be declared to it, e.g.:

    BODY {font-size: 10pt}
    H1 {font-size: 14pt} or H1 {font-size: 180%}
    EM {font-size: 15pt} or EM {font-size: 110%}

    The EM element will be displayed in a 15 point font or will be 10% larger than H1. NOTE: EM is, in this example, inside H1 therefore will inherit H1’s properties and not Body’s.

    The above declaration will display all EM elements in 15 point font or font that is 10% larger than font declared to the parent element. If this specific font is to apply to EM elements but only if they are inside H1 and not every occurrence of EM then EM must take a form of a contextual selector.

    H1 EM {font-size: 15pt} or H1 EM {font-size: 110%}

    In the example above EM is a contextual selector. It will be displayed in specified font only if it will be found in the context of H1.

    Not all properties are inherited. One such property is background. However, since it’s initial value is transpar

    What is the percentage value in ‘font-size’ relative to?
    It is relative to the parent element’s font-size. For example, if the style sheet says:

    H1 {font-size: 20pt;}
    SUP {font-size: 80%;}

    …then a inside an

    will have a font-size of 80% times 20pt, or 16pt.What is wrong with font-family: “Verdana, Arial, Helvetica”?
    The quotes. This is actually a list with a single item containing the well-known ‘Verdana, Arial, Helvetica’ font family. It is probably intended to be a list of three items. 

    Unlike in most other CSS1 properties, values for the font-family are separated by a comma to indicate that they are alternatives. Font names containing whitespace should be quoted. If quoting is omitted, any whitespace characters before and after the font name are ignored and any sequence of whitespace characters inside the font name is converted to a single space.

    So to ask for two fonts foo and bar the syntax is:

    font-family: foo, bar

    To ask for the two fonts Revival 555 and Iodine you can do this:

    font-family: “Revival 555″, Iodine

    You could also do this:

    font-family: Revival 555, Iodine

    which is equivalent. Notice that this is not three fonts; you can tell because after the “l” you didn’t hit a comma, (more list items to come) a semicolon (end of that property, another property coming up) or a curly brace (end of that rule). This is also equivalent:

    font-family: Revival 555, Iodine

    ^^^^^^ whole bunch of spaces converts to one space

    But this next one is asking for a different font with two spaces in the name

    font-family: “Revival 555″, Iodine
    ^^two spaces, which are not converted

    In general it is more tolerant of user typing to leave out the quotes. Sometimes you need them, for example there is a real font sold by Fontworks and designed in 1995 by Stephan M?ller called Friday, Saturday, Sunday. Yes, two commas in the actual font name. CSS1 can handle this:

    font-family: “Friday, Saturday, Sunday”, cursive

    Because it can handle this, the example in the title is syntactically correct. But what the author or tool wrote was almost certainly not what the document author intended.

    How do I centre my page?
    This is very easy. If we take the code in the last question and change it to this :
    CSS
    body, html {
    height:100%;
    }
    body {
    margin:0;
    padding:0;
    }
    #wrap {
    position:relative;
    width:780px;
    margin:auto; min-height:100%;
    }
    * html #wrap {
    height:100%;
    }

    you get a page that fits an 800×600 resolution screen without a horizontal scrollbar, which will be centered at higher resolutions.

    Must I quote property values?
    Generally no. However, values containing white spaces, e.g. font-family names should be quoted as whitespaces surrounding the font name are ignored and whitespaces inside the font name are converted to a single space, thus font names made up of more than one word (e.g.) ‘Times New Roman’ are interpreted as three different names: Times, New and Roman.

    Do any WYSIWYG editors support the creation of Style Sheets? Any text-based HTML editors?
    As support for CSS in browsers has matured in the last year, both WYSIWYG and Text-based HTML editors have appeared that allow the creation or the assistance of creating Cascading Style Sheet syntax. There are now at least two dozen editors supporting CSS syntax in some form. The W3C maintains an up-to-date list of these WYSIWYG and text-based editors.

    Which style specification method should be used? Why?
    The answer to this one is tricky. The short answer is: “it depends.” The long answer is, however, another story.

    If you are planning on using more than one style specification method in your document, you must also worry about Cascading Order of Style methods (see question 11.) If you are going to use only one method, then some guidelines about the nature of each method need to be kept in mind. The answer to this question is also very much related to the advantages and disadvantages to using each of them (next question.)

    Method 1: External Style Sheets (The LINK [-->Index DOT Html] element)
    This method should be used if you want to apply the same style to multiple documents. Each document can reference the stand-alone style sheet and use the styles contained within. Using this method, the appearance of many documents can be controlled using a single or small number of style sheets. This can save a LOT of time for an author.

    Method 2: Embedded Style Sheets (The Style [-->Index DOT Html] element)
    The syntax used with Method 2 is the same as that for Method 1. This method is a happy medium between External Style Sheets and Inline Styles (see below.). It should be used in place of Method 1 if you only want to specify styles for a single document. This method should also be used when you want to specify a style for multiple tag types at once or the list of style definitions is of larger size. Method 3: Inline Styles (STYLE attribute to HTML elements)

    If you only have to apply style to one or a few elements in a single document, your best bet will often be an Inline Style. This method attaches a style definition within the HTML element it is modifying.

    Justified Text?
    You redefine the

    tag like:

    p {text-align: justify;}

    and that renders all

    s with justified text.

    Another possibility is to define a class, like:

    .just {text-align: justify;}

    and then you style the paragraphs in question like:

     

    Note that NN 4.xx has problems with the inheritance of styles; that some NN4.xx browsers have a funny way to interpret “justify”; and that you have to have at least one blank space between the last character and the

    tag, because otherwise NN 4.xx likes to justify even a three word half-sentence… also, some browsers do a pretty ugly job of rendering justified text, adding spaces between words, instead of spaces between letters, as with word-processing programs.

    Why can @import be at the top only?
    A style sheet that is imported into another one has a lower ranking in the cascading order: the importing style sheet overrides the imported one. Programmers may recognize this as the same model as in Java, Modula, Object-Pascal, Oberon and other modular programming languages.
    However, there is a competing model, well-known to C programmers, where the imported material is not lower in rank, but is expanded in-place and becomes an integral part of the importing document.
    By allowing @import only at the top of the style sheet, people that think in terms of the second model (although in principle incorrect) will still get the expected results: as long as the @import is before any other overriding rules, the two models are equivalent.
    Btw. In all the modular languages import statements are only allowed at the top. In C, the #include can be put elsewhere, but in practice everybody always puts it at the top. So there may not be that much need to allow @import elsewhere in the style sheet either.

    Colored Horizontal Rule?
    You can apply styles to Horizontal Rules


    in IE without problems, but NN4.xx can only render the silvery HR. But there is a way around it:.rule {border-top-width: 1px;
    border-top-style: solid;
    border-color: #FF0000;
    margin: 0px 2%;} 

    that, applied to a div, should give you a red HR in NN4.xx and IE, with a 2% gap on the left and right side.

    CSSharky Logo
    On this page is an Example of a coloured ‘Horizontal Rule’.
    Update:
    Thanks to Matt Del Vecchio here is an improved format for the Horizontal Rule:

    hr { height:0px;
    border:0px;
    border-top:1px solid #ff1493; }

    ….this works in both IE and Netscape. It tells the browser to not render the hr rule itself, and then sets a 1px border, which looks just how most folks want to render the hr rule. It uses the


    element and that is better than writing your own class as all devices will know what to do with an 


    tag.Do URL’s have quotes or not?
    Double or single quotes in URLs are optional. The tree following examples are equally valid: 

    BODY {background: url(pics/wave.png) blue}
    BODY {background: url(“pics/wave.png”) blue}
    BODY {background: url(‘pics/wave.png’) blue}

    To what are partial URLs relative?
    Partial URLs are relative to the source of the style sheet. The style sheet source can either be linked or embedded. To which source partial URLs are relative to depends on their occurrence.
    If a partial URL occurs in a linked style sheet then it is relative to the linked style sheet. The URL of the linked style sheet is the URL of the directory where the sheet is kept.
    If a partial URL occurs in an embedded style sheet then it is relative to the embedded style sheet. The URL of the embedded style sheet is the URL of the HTML document in which the sheet is embedded.
    Note that Navigator 4.x treats partial URLs as being relative to the HTML document, regardless of the place where the partial URL occurs. This is a serious bug which forces most authors to use absolute URLs in their CSS.

    What’s the difference between ‘class’ and ‘id’?
    As a person, you may have an ID card – a passport, a driving license or whatever – which identifies you as a unique individual. It’s the same with CSS. If you want to apply style to one element use ‘id’ (e.g.

    ). In the stylesheet, you identify an ‘id’ with a ‘#’ ie. ‘#myid’…
    As a person, if you are in a class, you are one of many. It’s the same with CSS. If you want to apply the same style to more than one element, use ‘class’ (e.g. 

    ). In the stylesheet, you identify a ‘class’ with a ‘.’ ie. ‘.myclass’…
    If id’s are more restrictive than classes, then why not just litter your page with classes? Well, I think the main thing is that it’s simply wrong. You don’t put headings in ‘p’ tags – you use ‘h1′, ‘h2′, etc. You don’t (or shouldn’t) make a list by writing asterisks or the little divider bar ( | ) – you use list tags (‘ol’/’ul’ + ‘li’) . You don’t say that your footer is part of a class of elements called ‘footer’ – that’s just stupid – you can’t have more than one footer – it can’t be a class. Of course, practically, the effect is about the same – the rules are applied – but that’s not the point – it’s semantically wrong to do it that way… However, if you try to give more than one element the same id, you will have problems – so don’t do it.
    An element may have an id and a class, but that’s usually not necessary. You can also give an element two classes if you need to – like this : class=”class1 class2″. It can be very useful. Needless to say, you can’t give an element two id’s.
    Another difference is to do with power. You can give an element an id and a class, but if any of the properties of the two conflict, the id style will win. Ids are more powerful than classes.
    One more useful thing about id’s is that they can be used as a link reference. Many people still think that you need named anchors to make links within a page, but that’s simply not true – in fact, the name attribute is deprecated in XHTML except for in forms. One example of using id’s as link references is this page. There are no named anchors on this page – the questions at the top of the page link to the id’s of the divs that the answers are in.I made a 10px-high div, but IE makes it 20px high…
    Yeah
    This problem sometimes comes up when you make a div just to contain the bottom border of a box, or something like that. In this situation, there’s no text in the div, but IE won’t let the height of the div be smaller than the line-height (which usually depends on the font-size). The answer is to set the font-size to zero.
    CSS
    #thediv {
    font-size:0;

    How do I place two paragraphs next to each other?
    There are several ways to accomplish this effect, although each has its own benefits and drawbacks. We start with the simplest method of positioning two paragraphs next to each other.

    Paragraph 1
    Paragraph 2

    Trickier is this example, which relies on positioning but does not suffer the vertical-overlap problems which plague many other positioning solutions. The problem is that it relies on an incorrect positioning implementation, and will break down dramatically in conformant browsers.


    Paragraph 1

    Paragraph 2

    If floating is not sufficient to your purposes, or you cannot accept display variances in older browsers, then it may be best to fall back to table-based solutions.

    Can you use someone else’s Style Sheet without permission?
    This is a somewhat fuzzy issue. As with HTML tags, style sheet information is given using a special language syntax. Use of the language is not copyrighted, and the syntax itself does not convey any content – only rendering information.
    It is not a great idea to reference an external style sheet on someone else’s server. Doing this is like referencing an in-line image from someone else’s server in your HTML document. This can end up overloading a server if too many pages all over the net reference the same item. It can’t hurt to contact the author of a style sheet, if known, to discuss using the style sheet, but this may not be possible. In any case, a local copy should be created and used instead of referencing a remote copy.

    I want my page fonts to look the same everywhere as in?
    a) Why are my font sizes different in different browsers ?
    b) Why are my font sizes different on different platforms ?

    These questions represent the tip of the iceberg of a large topic about which whole essays have been written and a wide range of different views are held.
    The WWW was originally devised to present the same content in different presentation situations and for a wide range of readers: on that basis, “looking the same” is not a design criterion, indeed different presentations would be expected to look different.
    Some would have it that this original aim is no longer relevant, and that the purpose of web design is now to factor out the differences between display situations and put the author in control of the details of the presentation. Others point out that CSS was designed to give the reader a substantial amount of joint control over this process, and that this is desirable, for example to accommodate users with different visual acuity.
    Reading of textual matter on a computer screen is quite a delicate business, what with the relatively coarse pixel structure of a computer display; even with a close knowledge of the display details, it isn’t possible to achieve the detailed control that would be possible, say, on a printer. Whatever one’s aims, the practical truth is that many of the efforts made to guarantee the precise result on the screen have seriously counterproductive side effects in a www situation.
    The CSS specifications themselves recommend that authors should not use absolute size units in a situation where the properties of the display are unknown. There’s a lot to be said for flexible design, that in an appropriate situation looks the way you had in mind, but still successfully conveys content and message in a wide range of other browsing situations.
    And so, before looking at the technical detail of what can be specified, it’s strongly suggested that you read some of those essays on web design, and reach your own conclusions as to the strengths and weaknesses of the medium, and how you can best exploit the strengths in a web environment, without falling foul of the weaknesses.

    When is auto different from 0 in margin properties?
    In vertical margins, auto is always equal to 0. In horizontal margins, auto is only equal to 0 if the width property is also auto. Here are three examples, assume that there is a

    that is a child of:

    Example 1: auto value on the width.

    BODY {width: 30em;}
    P {width: auto; margin-left: auto; margin-right: auto;}

    Since the width property is auto, the auto values of the two margins will be ignored. The result is a P that is 30em wide, with no margins.

    Example 2: two auto margins

    BODY {width: 30em;}
    P {width: 20em; margin-left: auto; margin-right: auto;}

    The P will be 20em wide and the remaining 10em will be divided between the two margins. Paragraphs will be indented 5em at both sides.

    Example 3: one auto margin

    BODY {width: 30em;}
    P {width: 20em; margin-left: 2em; margin-right: auto;}

    In this case, paragraphs are 20em wide and are indented 2em on the left side. Since the total width available is 30em, that means the right margin will be 8em.
    Note that the default value of width is auto, so setting one or both margins to auto is only useful if you set the width to something other than auto at the same time.

    How do I move the list bullet to the left/right?
    CSS1 has no properties for setting margins or padding around the bullet of a list item and in most cases the position of the bullet is browser-dependent. This is especially true since most browsers disagreed on whether a bullet is found within the margin or padding of a list item.
    In CSS2, properties were introduced to provide greater control over the placement of bullets (which CSS2 calls a “marker”) but these were not widely supported by mid-2001 browsers. Here is an example of changing a marker’s placement:
    li:before {display: marker; marker-offset: 22px; content: url(triangle.jpg);}
    In this example, a graphic of a triangle is inserted before the content of the li element, set to be a marker (through display: marker;), and given an offset of 22 pixels. Depending on the margin size of the list item, there may not be room for the marker to appear next to the list item’s content.

    How does a simple CSS style rule look ?
    P { font-family: serif; font-size: 1.2em; }
    Here we see a rule with a ‘selector’ P that has been given two style declarations, i.e. two ‘property:value’ pairs.
    ‘font-family’ and ‘font-size’ are properties of the content of element P , and these properties are assigned the values of ‘serif’ and ‘1.2em’ respectively.
    A colon ‘:’ is the value assignment symbol in CSS, so using an equal sign ‘=’ instead is an error and is required by the CSS specification to be ignored. Any browser that appears to honor this style is behaving improperly.
    For length values a ‘unit’ is always needed and there shall never be any space between a number and its length unit.
    A value given as e.g. ‘1.2 em’ is an error and is required by the CSS specification to be ignored. Any browser that appears to honor this style is behaving improperly.
    A semicolon ‘;’ between declarations is required but it’s also good “rule of thumb” to put a ‘;’ even after the last declaration.
    Finally, curly braces ‘{?}’ group one or more declarations into a final CSS rule.

    Why are there gaps above and below my form in IE?
    A lot of the time, when you find gaps that you can’t account for, they are due the default styles of different browsers – especially the margins and padding. IE gives forms some margins above and below forms while Firefox doesn’t. It’s like with lists – you’ll find bigger padding and margins for lists in IE than in Firefox. Paragraph margins are different, as are the margins on heading tags (h1,h2, etc).

    A good way to not get caught out by these problems is to set all margins and padding to zero at the top of your style sheet and then add them as and when you feel the a need for them, in that way, any margins and padding will be the same in different browsers.

    CSS
    * {
    margin:0;
    padding:0;
    }

    If one were to set Text and Link colors using a style sheet, should one also define the background colors for these elements as well?
    It is generally true that you should give background or background-color a value, but not necessarily a color value. E.g., if the document has a background image, you would “highlight” all links if you give them a background color.

    body { background-image: url(light-texture.png) #FFF; color: #000 }
    a:link, a:visited, a:active { color: #00F; background-color: transparent; }

    By setting the background-image explicitly to transparent, you lower the risk of another rule in the cascade giving links a background that would highlight them.

    How do you override the underlining of hyperlinks?
    CSS has the ability to explicitly control the status of underlining for an element – even for hyperlinks. The correct way to do this in an external or document-level style sheet is:
    A { text-decoration: none }
    and within an anchor element as:
    link text

    Note: The underlining of hyperlinks is a long-standing visual convention that assists in the visual identification of active hyperlink areas. Many users expect to see hyperlinks underlined and may be confused and/or irritated if they are not used. User-defined style sheets address this user need by allowing the user to have final control over this feature. Unfortunately, wide support for this ability does not yet exist.

    How do you show which page you’re on (in a menu)?
    If PHP is not available to you, you could use the cascade. Put an id in your body tags and an id in each of your ‘a’ tags for the links.
    Let’s say on page one you have this:
    CSS

    ….
    page one

    In your CSS, you can have something like this:
    CSS
    #page1 a#page1link {
    color:purple;

    How can I specify two different sets of link colors?
    By classifying each set of links and then attaching desired color to each set.
    CSS:

    You can name set1 and set2 any way you like as long as the names are made up of letters 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.
    Note: to avoid conflict with user’s settings a background property (background color) should also be specified together with the color property (foreground color).

    How can I place multiple blocks next to each other?
    In theory, the following will produce 4 “columns”:

    Block 1
    Block 2
    Block 3
    Block 4

    Each “column” will occupy 25% of the screen. This relies on a correct implementation of float, which cannot be said of many legacy browsers. If you cannot accept display variances in older browsers, then it may be best to fall back to table-based solutions.

    2. By making the block an inline element and then use text-align property

    text

    This technique depends on the incorrect implementation of text-align behavior in older browsers. It will likely cease to work in future CSS-conformant browsers, and eventually it will probably not be a viable solution.

    Document Style Semantics and Specification Language (DSSSL)?
    Document Style Semantics and Specification Language is an international standard, an expression language, a styling language for associating processing (formatting and transformation) with SGML documents, for example XML.

    What is Extensible Stylesheet Language (XSL)?
    XSL is a proposed styling language for formatting XML (eXtensible Markup Language) documents. The proposal was submitted to the W3C by Microsoft, Inso, and ArborText.

    Which font names are available on all platforms ?
    The simple answer is “None” which is why CSS offers five generic font names as ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’ and ‘monospace’. Never put any of these generic font names in quotes.

    A CSS aware browser should make a suitable choice from the available fonts in response to each of those generic names.
    Specifying any other font name in a www environment comes out as a suggestion only, that may or may not be acknowledged by a browser.
    The problem with using names of specific fonts is that there is little point in naming fonts that few users will have, so you’re down to listing a few mass-market font names. This will then override any superior selection that a minority of discerning readers may have made for themselves.
    Note also that fonts may differ in their character repertoire, but this is often not evident from the font name itself: by selecting an inappropriate font name, you might prevent internationalized content from displaying correctly for a proportion of users.

    Why does Netscape lose my styles ?
    Netscape 4.x has poor support for CSS. Having said that, the following points should be noted.
    Invalid HTML will almost certainly cause Netscape to ignore your CSS suggestions at some point. You will find that valid HTML is your best friend, but for Netscape to work properly you must ensure that all elements in your markup which permit closing tags are explicitly closed.
    Check and correct your CSS suggestions for the very same reason, Netscape 4.x is in fact doing “the right thing”, as per CSS specs (as opposed to MSIE) when it ignores style rules with errors.
    Netscape 4.x has what’s called an “inheritance problem” into its TABLE element. It can be argued that NS is all within its right to behave as it does in this case, but since the workaround is quite simple it’s easy enough to just use it and be done with it.
    Let’s say you want your TABLE content to “look the same” as your BODY content? “Redundant” styling comes to your help as in e.g. BODY, TABLE, TH, TD { /* insert your styles here */ }
    On a generic level, Netscape 4.x likes to have style rules applied directly to the elements where they are needed. You can never really trust the inheritance principle to work correctly at any level in Netscape 4.x.

    Why is it my ‘:hover’ declaration for links does not work ?
    Assuming you have already checked that your style sheet declarations do conform to correct CSS syntax, it could be that you have overlooked the importance of a correct order of style declarations for links.
    The CSS2 specification makes this following note on the importance of placing the dynamic pseudo-classes ‘:hover’ and ‘:active’ in correct positions in a list of style declarations.
    Note that the ‘a:hover’ must be placed after the ‘a:link’ and ‘a:visited’ rules, since otherwise the cascading rules will hide the ‘color’ property of the ‘a:hover’ rule.

    Similarly, because ‘a:active’ is placed after ‘a:hover’, the active color will apply when the user both activates and hovers over the ‘a’ element.

    HTML, CSS & JavaScript Web Designer or Web Developer Interview Questions

    HTML, CSS & JavaScript Web Designer or web Developer Interview Questions

    HTML Web Standards Interview Question

     

    What is a DTD? What DTD do you generally use? Why? Pros and cons.

    A DTD is a Document Type Definition, also know as DOCTYPE. In a document served as text/html, the DOCTYPE informs the browswer how to interpret the content of the page. If the the doctype is not declared, the browser assumes you don’t know how to code, and goes into “quirks mode”. If you know what you are doing and include a correct XHTML DOCTYPE, your page will be rendered in “standards mode”.

    Accessibility Interview Question

    Importance in selecting font size for a web page?

    Font sizes should be declared using relative measurement values, such as ems, via a style sheet, without the use of the term !important. There are issues with browser font size enlarging which can be rectified via CSS.

    CSS Interview Question

    a) What are the possible values for the display attribute that are supported by all browsers?

    b) What is the default value for the display attribute for the image element? (what is the difference between inline and block level elements)
    c)What does display: run-in do?
    d) Difference between “visibility:hidden” and “display:none”? What are the pros and cons of using display:none?

    Answer

    main values: none, block, inline, list-item, run-in
    all values: inline | block | list-item | run-in | compact | marker | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit
    default value: inline, block or list-item, depending on the element. The <img> is an inline element.
    Run-in should make the run-in element be the first line of the next sibling block level element, if it is before a block level element that is not floated or absolutely positioned. If the next sibling is positioned or floated, then the run-in element will be a block level element instead of appearing in-line.
    PPK’s Quirksmode explains it well. The w3schools lists table display values.
    When visibility is set to hidden, the element being hidden still occupies its same place in the layout of the page. If the display is set to none, the element does not occupy any space on the page — as if it didn’t exist..

     

    CSS Interview Question

    Question

    a) What are the five possible values for “position”?
    b) What is the default/initial value for “position”?
    c) How does the browser determine where to place positioned elements
    d) What are the pros and cons of using absolute positioning?
    e) if they are really advanced, ask about IE z-index issues with positioned elements.

    Answer

    a) Values for position: static, relative, absolute, fixed, inherit
    b) Static
    c) They are placed relative to the next parent element that has absolute or relative value declared
    d) Absolutely positioned elements are removed from the document flow. The positioned element does not flow around the content of other elements, nor does their content flow around the positioned element. An absolutely positioned element may overlap other elements, or be overlapped by them.
    e) IE treats a position like a z-index reset, so you have to declare position of static on the parent element containing the z-indexed elements to have them responsd to z-index correctly.

     

    CSS Interview Question

    Question:

    Write a snippet of CSS that will display a paragraph in blue in older browsers, red in newer browsers, green in IE6 and black in IE7

    Possible Answer:

    #content p{color:blue}
    html>body #content p {color:red}
    * html #content p{color:green}
    html>body #content p {*color:black;}

     

    Basic Javascript Interview Question

    Question:

    What is the correct way to include JavaScript into your HTML?

    Answer:

    correct explanation using inline event handlers or inline code

    Basic Javascript Array / XHTML Form Interview Question

    Question

    Are the following all equal, and, if so, what would your code look like to make the following all equal the same thing:

      alert(document.forms["myform"].elements["field"].value);
      alert(document.forms[1].elements[1].value);
      alert(document.myform.field.value);

    answer:

    <form name="myform" method="post" action="something">
    <input name="anything" value="anything" type="something" />
    <input name="field" value="something" type="something" />
    </form>

    Answer includes knowing that the form is the second form on the page, and that the field input element is the second element within that form.

     

    JavaScript Interview Question

    Question:

    How do you dynamically add a paragraph with stylized content to a page?

    Possible Answer:

    newParagraph = document.createElement('p');
    newParagraph.setAttribute('class', 'myClass');
    newText = document.createTextNode('this is a new paragraph');
    newParagraph.appendChild(newText);
    myLocation = document.getElementById('parent_of_new_paragraph);
    myLocation.appendChild(newParagraph);

     

    Other questions ideas:

    Q: How do you organize your CSS? How do you come up with id and class names (what naming conventions do you use)?
    A: While there are no right answers, there are best practices. Issues to look for are not having div mania, no inline CSS, no presentational markup, minimal use of classes, understanding the CSS cascade.

    Q: What do you think of hacks? When should you use them? If you use them, how do you maintain them? What can be done to avoid needing to use box-model hacks? (if they aren’t pros, you can ask them what is the issue with x-browsers and the box model)

    Q: What are the pros and cons of using tables for layout? Do you use tables? What are the pros and cons of tableless design? How do you generally layout your pages?
    A: check for them NOT using tables

    Q: What are some deprecated elements and attributes that you use, and in what instances do you use them?

    A: List of deprecated elements and attributes.

    Q: What is involved in making a website accessible? What are arguments you use to convince others to invest in making their web site accessible.
    A:  Making sites accessible also makes them more search engine friendly (saves money), makes your pages accessible to the 20% of the population that has some type of disability (so you can make more money) and it’s the law in many places.

    Q: Define what web standards mean to you? How do you implement web standards?

    Standardized specifications for Internet markup languages such as HTML, CSS, and XML. Formulated by the W3 organisation, these standards enable people to create websites that will work in almost any browser or internet-enabled device, instead of being specific to certain versions of Internet Explorer or Netscape Navigator.

    Q: In CSS, how can you make a form elments background-color change when the user is entering text? will this work in all browsers?

    It’s possible to change the default look of form elements by styling their html tags: inputselect and textarea.

    but it won’t work in all browsers

    Q: How can you target an element in your HTML using the DOM?

    by using the nodes of the DOm elements we can target any element on any event in HTML

    var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.&#8221; : “http://www.&#8221;);
    document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

    try {
    var pageTracker = _gat._getTracker(“UA-1855756-5″);
    pageTracker._trackPageview();
    } catch(err) {}

    Follow

    Get every new post delivered to your Inbox.

    Join 66 other followers