Set - 4

Question 1 :

What can be done with style sheets that can not be accomplished with regular HTML?

Answer :

Many of the recent extensions to HTML have been tentative and somewhat crude attempts to control document layout. Style sheets go several steps beyond, and introduces complex border, margin and spacing control to most HTML elements. It also extends the capabilities introduced by most of the existing HTML browser extensions. Background colors or images can now be assigned to ANY HTML element instead of just the BODY element and borders can now be applied to any element instead of just to tables. For more information on the possible properties in CSS, see the Index DOT Css Property Index.


Question 2 :

How do I make my div 100% height?

Answer :

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.


Question 3 :

What are pseudo-elements?

Answer :

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>


Question 4 :

What is the difference between ID and CLASS? 

Answer :

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>


Question 5 :

How to make text-links without underline?

Answer :

a:link, a:visited {text-decoration: none}
or
<a style="text-decoration: none" HREF="...">

...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
<a style="text-decoration: none; background: red; color: blue" HREF="...">

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


Question 6 :

How do you make a tool tip that appears on hover? 

Answer :

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.


Question 7 :

What is cascading order?

Answer :

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


Question 8 :

Why shouldn't I use fixed sized fonts ?

Answer :

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.


Question 9 :

How do you make a whole div into a link?

Answer :

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>


Question 10 :

How do I have links of different colors on the same page? 

Answer :

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>


Question 11 :

What is shorthand property?

Answer :

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}


Question 12 :

How to use CSS building a standards based HTML template?

Answer :

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">
<html lang="en">
<head>
<meta http-equiv="Content-Type" 
content="text/html; charset=ISO-8859-1">
<title>Your own page title</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>

<div id="header">
<h1>The name of this page</h1>
</div>
<div id="navigation">
<h2>Navigation</h2>
<ul>
<li><a href="first.html">First</a></li>
<li><a href="second.html">Second</a></li>
<li><a href="third.html">Third</a></li>
</ul>
</div>
<div id="content">
<h2>Content</h2>
<p>Some sample content, add your own here</p>
</div>
<div id="footer">
<p>This page is written by [Your name] and builds 
n a <a href="http://friendlybit.com">
Friendlybit template</a>.</p>
</div>

</body>
</html>
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;
}


Question 13 :

What is value?

Answer :

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}


Question 14 :

What is initial value?

Answer :

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. 

<P style="background: red">Hello <strong>World </strong> </P>

Content of the element P will also have red background


Question 15 :

How frustrating is it to write a specification knowing that you're at the browser vendors' mercy?

Answer :

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.


Question 16 :

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?

Answer :

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.


Question 17 :

How To Style Table Cells?

Answer :

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>


Question 18 :

How To Style Forms? 

Answer :

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.


Question 19 :

How do I get my footer to sit at the bottom...? 

Answer :

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>


Question 20 :

Can I attach more than one declaration to a selector?

Answer :

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}


Question 21 :

Border around a table?

Answer :

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 <head></head> section, like:

<style type="text/css">
(here you can place your styles)
</style>

and apply it to the table as follows:

<div class="tblboda">
<table yaddayadda>
<tr>
<td>Content text and more content</td>
</tr>
</table>
</div>

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 <span> 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 <div>. 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 <table ... class="tableboda"> and you define another class for each stylesheet: .tblboda2

In 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 <div> 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.


Question 22 :

How do you target a certain browser? 

Answer :

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 IE]>
<link href="ieonly.css" rel="stylesheet" type="text/css">
<![endif]-->

If you need to target IE5x...

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


Question 23 :

How does inheritance work? 

Answer :

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.


Question 24 :

What is the percentage value in 'font-size' relative to?

Answer :

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 <SUP> inside an <H1> will have a font-size of 80% times 20pt, or 16pt.


Question 25 :

What is wrong with font-family: "Verdana, Arial, Helvetica"?

Answer :

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&uuml;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.