CSS3 Interview Questions & Answers

Posted On:December 8, 2018, Posted By: Latest Interview Questions, Views: 1750, Rating :

CSS3 Interview Questions and Answers for Freshers & Experienced Pdf

Dear Readers, Welcome to CSS3 Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your Job interview for the subject of CSS3. These CSS3 questions are very important for campus placement test and job interviews. As per my experience good interviewers hardly plan to ask any particular questions during your Job interview and these model questions are asked in the online technical test and interview of many IT companies.

CSS Interview Questions

1. What is CSS?

1. 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 occurrence of a specific element within that type can be declared an unique style, e.g. margins, positioning, color or size.

2. CSS is a web standard that describes style for XML/HTML documents. 

3. CSS is a language that adds style (colors, images, borders, margins…) to your site. It’s really that simple. CSS is not used to put any content on your site, it’s just there to take the content you have and make it pretty. First thing you do is link a CSS-file to your HTML document. Do this by adding this line:

<link rel="stylesheet" href="style.css"

type="text/css">

The line should be placed in between your <head> and </head> tags. If you have several pages you could add the exact same line to all of them and they will all use the same stylesheet, but more about that later. Let’s look inside the file “style.css” we just linked to.

h1 {

font-size: 40px;

height: 200px;

}

.warning {

color: Red;

font-weight: bold;

}

#footer {

background-color: Gray;

}

4. Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents. This is also where information meets the artistic abilities of a web-designer. CSS helps you spice up your web-page and make it look neat in wide variety of aspects.

 

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 two ways of centering block level elements:

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

Another example:

TABLE {margin-left: auto; margin-right: auto; width: 400px;} 

In most legacy browsers, a table's width is by default determined by its content. In CSS-conformant browsers, the complete width of any element (including tables) defaults to the full width of its parent element's content area. As browser become more conformant, authors will need to be aware of the potential impact on their designs.

 

4. If background and color should always be set together, why do they exist as separate properties? 

There are several 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.

1) The rule P {color: red} will display red text in all paragraphs. By classifying the selector P different style can be attached to each class allowing the display of some paragraphs in one style and some other paragraphs in another style.

2) A class can also be specified without associating a specific element to it and then attached to any element which is to be styled in accordance with it's declaration. All elements to which a specific class is attached will have the same style.

To classify an element add a period to the selector followed by an unique 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). (Note: text between /* and */ are my comments).

CSS:

P.name1 {color: red} /* one class of P selector */

P.name2 {color: blue} /* another class of P selector */

.name3 {color: green} /* can be attached to any element */

 

HTML:

<P class=name1>This paragraph will be red</P>

<P class=name2>This paragraph will be blue</P>

<P class=name3>This paragraph will be green</P>

<LI class=name3>This list item will be green</LI>

It is a good practice to name classes according to their function than their appearance; e.g. P.fotnote and not P.green. In CSS1 only one class can be attached to a selector. CSS2 allows attaching more classes, e.g.: 

P.name1.name2.name3 {declaration} <P class="name1 name2 name2">This paragraph has three classes attached</P>

 

6. What is grouping ?

Grouping is gathering (1) into a comma separated list two or more selectors that share the same style or (2) into a semicolon separated list two or more declarations that are attached to the same selector (2).

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}

2. The declarations {font-style: italic} and {color: red} can be attached to one selector, e.g.:

H2 {font-style: italic}

H2 {color: red}

and can also be grouped into one list:

H2 {font-style: italic; color: red}

 

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.css. <HEAD> <LINK REL=STYLESHEET HREF="style.css" TYPE="text/css"> </HEAD>

 

8. Is CSS case sensitive? 

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

The trick is that if you write a document using an XML declaration and an XHTML doctype, then the CSS class names will be case sensitive for some browsers.

It is a good idea to avoid naming classes where the only difference is the case, for example:

div.myclass { ...}

div.myClass { ... }

If the DOCTYPE or XML declaration is ever removed from your pages, even by mistake, the last instance of the style will be used, regardless of case.

 

9. What are Style Sheets? 

Style Sheets are templates, very similar to templates in desktop publishing applications, containing a collection of rules declared to various selectors (elements).

 

10. What is embedded style? How to link? 

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

<HEAD>

<STYLE TYPE="text/css">

<!--

P {text-indent: 10pt}

-->

</STYLE>

</HEAD>

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

 

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

<P ID=abc123>This and only this element can be identified as abc123 </P>

 

12. 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;}

 

13. Why do style sheets exist?

SGML (of which HTML is a derivative) was meant to be a device-independent method for conveying a document's structural and semantic content (its meaning.) It was never meant to convey physical formatting information. HTML has crossed this line and now contains many elements and attributes which specify visual style and formatting information. One of the main reasons for style sheets is to stop the creation of new HTML physical formatting constructs and once again separate style information from document content.

 

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

 

15. 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 occurrence.

<P STYLE="text-indent: 10pt">Indented paragraph</P>

 

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

 

17. Why does my content shift to the left on some pages (in FF)? 

That'll be the pages with more content? The ones that have a vertical scrollbar? If you look in IE there's probably a white space on the right where there would be a scrollbar if there were enough content to require one. In Firefox, the scrollbar appears when it's needed and the viewport becomes about 20px smaller, so the content seems to shift to the left when you move from a page with little content to one with lots of content. It's not a bug or something that needs to be fixed, but it does confuse and irritate some developers.

If, for some reason, you'd like Firefox to always have scrollbars - whether they're needed or not - you can do this :

CSS html {

height:100.1%;

}

 

18. How do I combine multiple sheets into one?

To combine multiple/partial style sheets into one set the TITLE attribute taking one and the same value to the LINK element. The combined style will apply as a preferred style, e.g.:

<LINK REL=Stylesheet HREF="default.css" TITLE="combined">

<LINK REL=Stylesheet HREF="fonts.css" TITLE="combined">

<LINK REL=Stylesheet HREF="tables.css" TITLE="combined">

 

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

 

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

 

21. How can I specify background images? 

With CSS, you can suggest a background image (and a background color, for those not using your image) with the background property. Here is an example:

body {

background: white url(example.gif) ;

color: black ;

}

If you specify a background image, you should also specify text, link, and background colors since the reader's default colors may not provide adequate contrast against your background image. The background color may be used by those not using your background image. Authors should not rely on the specified background image since browsers allow their users to disable image loading or to override document-specified backgrounds.

 

22. How do I have a fixed (non-scrolling) background image? 

With CSS, you can use the background-attachment property. The background attachment can be included in the shorthand background property, as in this example:

body {

background: white url(example.gif) fixed ;

color: black ;

}

Note that this CSS is supported by Internet Explorer, Mozilla, Firefox Opera, Safari, and other browsers. In contrast, Microsoft's proprietary BGPROPERTIES attribute is supported only by Internet Explorer.

 

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

 

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

 

25. 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 3x3 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".

 

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

 

27. 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 <link>-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!

 

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

 

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

 

30. How do I design for backward compatibility using Style Sheets? 

Existing HTML style methods (such as <font SIZE> and <b>) 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.

 

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

 

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

 

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

 

34. 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).

 

35. 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 */

<ADDRESS CLASS=footnote/>This element is associated with the CLASS footnote</ADDRESS>

<P CLASS=footnote>And so is this</P>

 

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

 

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

 

38. 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 */

 

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

 

40. How do I quote font names in quoted values of the style attribute? 

The attribute values can contain both single quotes and double quotes as long as they come in matching pairs. If two pair of quotes are required include single quotes in double ones or vice versa:

<P STYLE="font-family: 'New Times Roman'; font-size: 90%">

<P STYLE='font-family: "New Times Roman"; font-size: 90%'>

It's been reported the latter method doesn't work very well in some browsers, therefore the first one should be used.

 

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

 

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

 

43. 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}

<P class=initial>The first line of this paragraph will be displayed in uppercase letters</P>

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}

<P class=initial>The first letter of this paragraph will be displayed in red and twice as large as the remaining letters</P>

 

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

 

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

 

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


47. 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).

 

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

 

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

 

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

<div onclick="javascript:location='http://bonrouge.com'" id="mydiv">

... stuff goes here ...

</div>

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

<div id="empty"><a href="#n"></a></div>

 

51. 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 href="#" class="red">A red link</a>

<a href="#" class="blue">A blue link</a>

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

<ul id="menu">

<li><a href="#">A red link</a></li>

<li><a href="#">A red link</a></li>

</ul>

<div id="content">

<p>There's <a href="#">a blue link</a> here.</p>

</div>

 

52. 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}

 

53. How To Style Table Cells? 

Margin, Border and Padding are difficult to apply to inline elements. Officially, the <TD> 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:

<td>

yourtext </div></td> 

to apply the CSS rules to the div inside the cell. </p>

 

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

 

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

<div id="wrap">

...content goes here...

<div id="clearfooter"></div>

<div id="footer">Footer</div>

</div>

 

56. 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}

 

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

 

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

 

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

 

60. 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;

}