Set - 4

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>