Thursday, October 11, 2012

How to create a number list 1, 2, 3, and Sub number list 1.1, 1.2, 1.3 … HTML list?

CSS Code:
ul.numeric-decimals { counter-reset:section; list-style-type:none; }
ul.numeric-decimals li { list-style-type:none; }
ul.numeric-decimals li ul { counter-reset:subsection; }
ul.numeric-decimals li:before{
    counter-increment:section;
    content:counter(section) ". ";/*content:"Section " counter(section) ". ";*/
}
ul.numeric-decimals li ul li:before {
    counter-increment:subsection;
    content:counter(section) "." counter(subsection) " ";
}


Html Code:
<ul class="numeric-decimals">
  <li>Cats
    <ul>
      <li>Birds</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Dogs
    <ul>
      <li>Birds</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Rabbits</li>
  <li>Ants
    <ul>
      <li>Lions</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Ducks</li>
</ul>

Tuesday, October 2, 2012

3 ways of inserting CSS media queries

CSS media queries can be added to CSS in all of the ways you're able to define it:

External stylesheet:
<link rel="stylesheet" type="text/css" href="smallscreen.css" media="only screen and (max-width: 480px)" />

Imported stylesheet within the <style> element:
@import "smallscreen.css" only screen and (max-width: 480px);

Within the <style> element as a media rule:
 <style type="text/css">
  @media only screen and (max-width: 480px){
    /* rules defined inside here are only applied to browsers that support CSS media queries and the browser window is 480px or smaller */
  }
</style>

Source from: http://www.javascriptkit.com/dhtmltutors/cssmediaqueries.shtml

Wednesday, September 26, 2012

CSS media queries and IE fix

Take a peek at adapt.js is a lightweight JavaScript file that determines which CSS file to load before the browser renders a page.
Make sure you try respond.js - a fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more)

If you want to be able to correctly display a fluid design on multiple resolutions (including mobile) then you will probably use CSS Media Queries. CSS Media Queries are not complicated to use and were introduced by CSS3 specifications as an extension of CSS 2.1 media types.

Note that HTML4 supports media types like handheld, but this is poorly supported, old mobiles don't detect it, the modern devices completely ignore it.

CSS Media Queries work fine on modern browsers (IE9, FF, Chrome, Safari, Opera) and on mobile devices (iPhone, Android, Opera Mobile & Mini, Blackberry, IE Mobile 7, etc.)

And of course they don't work on IE < 9.0, but I have a solution that I'm already using on production servers. I wrote a small JavaScript file that reads all the <link> elements from DOM, checks which of them are destined for the current device resolution and applies them.

...
<head>
<!-- Your .css files. IE6, IE7 and IE8 ignore the media="only all ..." files. -->
   <link rel="stylesheet" type="text/css" href="core.css" />
   <link rel="stylesheet" type="text/css" href="smartphone.css" media="only all and (max-width: 480px)" id="stylesheet-480" />
   <link rel="stylesheet" type="text/css" href="tablets.css" media="only all and (min-width: 480px) and (max-width: 1024px)" id="stylesheet-1024" />
   <link rel="stylesheet" type="text/css" href="wide.css" media="only all and (min-width: 1200px)" id="stylesheet-1280" />

<!-- The mighty fix which chooses the correct stylesheet file based on the
screen resolution, and strips the 'media' attribute so IE6, IE7 and IE8
can read/interpret it -->

<!--[if lt IE 9]>
   <script type="text/javascript" src="/js/css-media-query-ie.js"></script>
<![endif]-->

</head>
...


Source From: http://ghita.org/tipoftheday/css-media-queries-for-ie

Tuesday, September 11, 2012

Smooth Scroll jQuery


<script type="text/javascript">
$(function() {
$('.parallex_controllers a').bind('click',function(event){
var $anchor = $(this);

$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500,'easeInOutExpo');
/*
if you don't want to use the easing effects:
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1000);
*/
event.preventDefault();
});
});
});
</script>

Saturday, August 25, 2012

Display a loading image until the page completes loading

Similar to how GDGT.com has it’s loading.gif while the page completes this method will do something very similar.

Right after the body I include the image inside a div:


<div id="loading-image">
    <img src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif" alt="Loading..." />
</div>


Of course I’m using wordpress so you might need to include a different path for your ajax-loader.gif.

Here’s the CSS I’m using on my current project:
#loading-image {
    display:block;
    background-color: #000;
    height:100%;
    width:100%;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 999999;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px; /* future proofing */
    -khtml-border-radius: 10px;
}

Now the most important part. I’m using jQuery to hide that div after the page completes loading.
<script type="text/javascript">
jQuery(window).load(function(){
    jQuery('#loading-image').fadeOut(1000);
});
</script>

Thursday, August 2, 2012

HTML5 Features


1.      New Doctype

( HTML )       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
( HTML5 )    <!DOCTYPE html>

2.      The Figure Element

( HTML )       <img src="image/image.jpg" alt="image" title=” image” />
        <p>Image of Mars. </p>
( HTML5 )
<figure>
    <img src="image/image.jpg" alt="image" title=”image” />
    <figcaption>  
        <p>This is an image of something interesting.</p>  
    </figcaption>  
</figure>  

3.      No More Types for Scripts and Links

( HTML )     <link rel="stylesheet" href="css/ stylesheet.css" type="text/css" />  
      <script src="path/to/script.js" type="text/javascript"></script>
( HTML5 )  <link rel="stylesheet" href="css/stylesheet.css" />
     <script src="path/to/script.js"></script>  
  

4.      To Quote or Not to Quote.

( HTML )     <p class=”myclass” id=”someId”> Welcome.</p>
( HTML5 )  <p class=myclass id=someId> Welcome.</p>
 

5. Email Inputs

( HTML5 )
                 <!DOCTYPE html>  
                       <html lang="en">  
                            <head>  
                                  <meta charset="utf-8">  
                                      <title>untitled</title>  
                            </head>  
                            <body>  
                                  <form action="" method="get">  
                                      <label for="email">Email:</label>  
                                          <input id="email" name="email" type="email" />
                                          <button type="submit"> Submit Form </button>  
                                   </form>  
                            </body>  
                       </html>

6.  The Semantic Header and Footer

( HTML )      <div id="header">    ...  </div>    
                       <div id="footer">       ...  </div>  
( HTML5 )    <header>       ...      </header>  
                        <footer>          ...      </footer>

7.Audio Support

( HTML5 ) HTML5 now offers the <audio> element.
                        <audio autoplay="autoplay" controls="controls">  
                             <source src="file.ogg" />  
                             <source src="file.mp3" />  
                             <a href="file.mp3">Download this file.</a>  
                        </audio>  

8. Video Support

( HTML5 ) HTML5 now offers the <vidio> element.
                        <video controls preload>  
                             <source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" />  
                             <source src="filename.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" />  
                             <p>Your browser is old.<a href="cohagenPhoneCall.mp4">Download this video instead.</a></p>  
                        </video>  

CSS3 Gradient Button Without Images


<!DOCTYPE HTML>
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
.button {
    display: inline-block;
    outline: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font: 14px/100% Arial, Helvetica, sans-serif;
    padding: .5em 2em .55em;
    text-shadow: 0 1px 1px rgba(0,0,0,.3);
    -webkit-border-radius: .5em;
    -moz-border-radius: .5em;
    border-radius: .5em;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
    text-decoration: none;
}
.button:active {
    position: relative;
    top: 1px;
}
.orange {
    color: #fef4e9;
    border: solid 1px #da7c0c;
    background: #f78d1d;
    background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
    background: -moz-linear-gradient(top,  #faa51a,  #f47a20);
filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
}
.orange:hover {
    background: #f47c20;
    background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
    background: -moz-linear-gradient(top,  #f88e11,  #f06015);
    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
}
.orange:active {
    color: #fcd3a5;
    background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
    background: -moz-linear-gradient(top,  #f47a20,  #faa51a);
    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
}
</style>
</head>
<body>
<div class="button orange" style="width:100px;">Collabor</div>
<input type="button" class="button orange" name="Collabor" value="collabor"/>
</body>
</html>

Saturday, July 28, 2012

CSS Background transparency without affecting child elements, through RGBa and filters

The solution!

.alpha60 {
/* Fallback for web browsers that doesn't support RGBa */
background: rgb(0, 0, 0);
/* RGBa with 0.6 opacity */
background: rgba(0, 0, 0, 0.6);
}


A little caveat

Shockingly enough (erm), no version of Internet Explorer supports RGBa colors (i.e. not IE 6, IE 7 or IE 8 at the time of this writing). However, and lucky for us, in year 2000 Microsoft went crazy with implementing various filters in IE. One of them are the gradient filter, and what we can do is use that and just define the same start and end color. “Ok, but how do I get the transparency”, you might be thinking now. The answer to that is that you will declare that as part of the color hex value. A CSS gradient filter achieving the same effect as the CSS code above would look like this:



.alpha60 {
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
}



Source From: http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/


---------------------------------------
Sample Code::::

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>www.fouressinsurance.com</title>
<style>
    .main{
        height:300px;
        width:100px;
        background: rgba(0, 0, 0, 0.5);
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
}
    .inner{ color:#ff0000; opacity:100%; }
</style>
</head>

<body style="background:#fff">
<div class="main">
    <div class="inner">Hyderabad Web Designer www.hydwebdesigner.com</div>
</div>
 </body>
</html>
 

---------------------------------------

jQuery and JavaScript CSS !important

jQuery CSS !important

One thing that everyone must have wonder (those that haven’t tried yet) is whether jQuery support declaration of !important for their css() method such as this.
1    jQuery('#id').css('height', '200px !important');

You will find that nothing will happen with a declaration of such manipulation. If we were to try out on pure JavaScript with the above declaration, it will be something like this.
1    document.getElementById('id').style.height = "200px !important";

Having a pure JavaScript instruction such as this will not work in most browser other than safari 3++. Hence, jQuery will definitely won’t work too. This is not a bug but something that most browser doesn’t acknowledge a need since inline style already have the highest priority other than user defined ones. (unless you do not want your user to change how they view your website).

Solution to jQuery CSS !important

Well, the typical way of getting !important will not work. Rather, you might want to try CSS DOM cssText. Hence, you will force !important to your jQuery statement by doing this.
1    jQuery('#id').css('cssText', 'height: 200px !important');

However, most people will be unfamiliar with cssText. cssText will overwrites the css of that particular element. Hence, you will have to redeclare the rule for that particular element all over again. On the other hand, if you are using JavaScript cssText, different browser treat cssText different such as ie you will define this way,
1    document.getElementById('id').style.cssText = 'height: 200px !important'

While normally you will use it this way.
1    document.getElementById('id').cssText = 'height: 200px !important'

Definitely, there is a better alternative such as using the cssRules/rules array which can specify the rule in that element to be modify.

The other more practical way of doing it is by introducing new class for your element. Instead of styling through jQuery or DOM object which is applying inline styling (means highest priority already), you should leave every majority styling or best all of the styling to an external style sheet that help you reduce some bytes on the script and also improve maintainability for both your code and style. You can do this using the toggleClass which adds a new class to that element automatically.
1    jQuery('#id').toggleClass('classname');

or you can do this in JavaScript by replacing the class (this is more efficient than the jQuery one since there isn’t any additional checking and stuff)
1    document.getElementById('id').className = 'classname';

Removing inline CSS styles using Jquery?

You can remove that inline style with this:

$(document).ready(function(){
  $('.myheader').each(function(idx,el){
    el.style.marginTop='';
  });
});

Thursday, July 5, 2012

IE9 - IE10pp4 CSS Hack


#element {
    color:orange;
}
#element {
    *color: white;    /* IE6 + 7, doesn't work in IE8/9 as IE7 */
}
#element {
    _color: red;     /* IE6 */
}
#element {
    color: green\0/IE8+9; /* IE8 + 9 + IE10pp4  */
}
:root #element { color:pink \0/IE9; }  /* IE9 + IE10pp4 */

Clearfix - Force Element To Self-Clear its Children

.clearfix:after {
     visibility: hidden;
     display: block;
     font-size: 0;
     content: " ";
     clear: both;
     height: 0;
     }
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */
 
 
Source from: http://css-tricks.com/snippets/css/clear-fix/ 

Wednesday, July 4, 2012

Stick div at top after scrolling


<style>
#sticky {
  background-color: #fff;
  -moz-border-radius: 0.5ex;
  -webkit-border-radius: 0.5ex;
  border-radius: 0.5ex;
  color: #000;
  font-size: 2em;
  padding: 0.5ex;
  width: 600px;
  }
#sticky.stick {
  -moz-border-radius: 0 0 0.5em 0.5em;
  -webkit-border-radius: 0 0 0.5em 0.5em;
  border-radius: 0 0 0.5em 0.5em;
  position: fixed;
  top: 0;
  z-index: 10000;
  }
</style>
</div>

<!-- If you have jQuery directly, then skip next line -->
<script src="http://www.google.com/jsapi"></script>

<script type="text/javascript">
// If you have jQuery directly, then skip next line
google.load("jquery", "1");

function sticky_relocate() {
  var window_top = $(window).scrollTop();
  var div_top = $('#sticky-anchor').offset().top;
  if (window_top > div_top)
    $('#sticky').addClass('stick')
  else
    $('#sticky').removeClass('stick');
  }
// If you have jQuery directly, use the following line, instead
// $(function() {
// If you have jQuery via Google AJAX Libraries
google.setOnLoadCallback(function() {
  $(window).scroll(sticky_relocate);
  sticky_relocate();
  });
</script>


Source From: http://blog.yjl.im/2010/01/stick-div-at-top-after-scrolling.html

Saturday, June 30, 2012

jQuery.noConflict()

Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict():

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  // Code that uses other library's $ can follow here.
</script>

Tuesday, June 19, 2012

How to remove named anchor when we click on blog post Continue Reading...


On the loop.php change the code as per provided blow...
From
-------------------------------------------------------------------------------------------------------------------------------
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div>

To
------------------------------------------------------------------------------------------------------------------------------- <div class="entry-content">
<?php the_excerpt( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div>

Rotate text through CSS


.text{
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
/*filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);*/ /* Option for 90deg, -90deg */
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678); /* It for any deg */
display:block;
position:relative;
margin-left:100px;
margin-left:50px\9;
font-family:Arial, Helvetica, sans-serif;
font-weight:normal;
font-size:20px;
}

Thursday, June 14, 2012

Selector css: class, id, pseudo-class, pseudo-element


An important aspect in using css is to be able to select an element to apply to it the css style.
This selection can be done based on the position of the element in the page’s structure (css selector), on a specific name given to the element (class and id) or on information other then the page structure or name (pseudo-class and pseudo-element).
To facilitate the reading of this article, I added the index of selection methods classified as css selectorclass and idpseudo-class e pseudo-element:

Css selector:

  • Selector * : select every single elements of the page
  • Type selector : select directly a specific html element
  • Descendant selector : select an element descendant from another
  • Selector > : select the direct child and of first level fo an element
  • Selector + : select an element directly adjacent to another
  • Selector [atr] : select an element with a specific attribute or an attribute with a specific

.class e #id:

  • .class : select an element based on a specific class name
  • #id : select an element based on a specific identification name (id)

Pseudo-class:

Pseudo-element:

  • :first-line : define the css style of the first line of an element
  • :first-letter : define the css style of the first letter of an element
  • :before and :after : define the css style of a content generated before or after an element

Css selector

1. Selector *

Selector * said universal select every single element of the page.
Example of css rule:
* {
font-style: italic;
color: red;
}
In this example, all the page fonts will be in italic and colored red.

2. Type selector

The type selector allows you to select an html element directly.
Example of css rule:
h1{
font-style: italic;
color: red;
}
In this example, all the element h1 will be in italic and colored red.

3. Descendant selector

The descendant selector select the child elements of another element
Example of css rule:
p span{
font-style: italic;
color: red;
}
In this example, all the span elements inside a paragraph will be in italic and colored red.
Example of css rule:
#myDiv a{
font-style: italic;
color: red;
}
In this example, all the links inside the div with the id name myDiv will be in italic and colored red.

4. Selector >

The selector > select the direct child of first level of an element

NB: NOT compatible with Internet Explorer 6 and inferior version
Example of css rule:
body > p{
font-style: italic;
color: red;
}
Example HTML:
<body>
<p>I am a direct child of first level of body</p>
<div>
<p>I am not a child of first level of body but a paragraph of second level</p>
</div>
</body>
In this example, only the paragraphs directly inside body will be italic and colored red.
Instead, if the paragraphs are inside another element, they are not considered as first child of first level and the css rules will not be applied to them.

5. Selector +

The selector + select an element directly adjacent to another.
Example of css rule:
div + p{
font-style: italic;
color: red;
}
Example HTML:
<div>I am an element div</div>
<p>I am a paragraph directly adjacent to the div</p>
<p>I am NOT a paragraph directly adjacent to the div</p>
In this example, only the first paragraph directly after the element div will be italic and colored red.
The css rules will not be applied to the following paragraphs.

6. Selector [attr]

Selettore [attr] select an element with a specific attribute or an attribute with a specific value.
NB: NOT compatible with Internet Explorer 6.
Example of css rules to select an element with an attribute without a specific value:
p[id]{
font-style: italic;
color: red;
}
Example HTML:
<p id="selected">I am paragraph with an id name</p>
<p>I am a paragraph without an id name</p>
In this example, all the paragraphs with an id will be in italic and colored red whatever is the id name.
The css rules will not be applied to the paragraph without an id.
Example of css rules to select an element with an attribute and a specific value:
p[class="selected"]{
font-style: italic;
color: red;
}
Example HTML:
<p class="selected">I am a paragraph with an attribute ‘class’ and the value ‘selected’</p>
<p class="other">I am a paragraph with an attribute ‘class’ but with another value then ‘selected’</p>
<p>I am a paragraph without an attribute ‘class’</p>
In this example, all the paragraphs with an attribute ‘class’ and the value ‘selected’ will be in italic and colored red.
The css rules will not be applied to the paragraphs without the attribute ‘class’ o with an attribute ‘class’ of different value of ‘selected’.

.class and #id

1. Selector .class

Select an element based on a specific class name (syntax: .className).
The class name can be applied to more elements which share the same css style.
Example of css rule:
p.myClass{
font-style: italic;
color: red;
}
Esempio HTML:
<p class="myClass">
I am a paragraph with the class name ‘myClass’
</p>
In this case, all the paragraph with the class name ‘myClass’ will be in italic and colored red.
The classes can be applied to different types of element.
Example of css rule:
.myClass{
font-style: italic;
color: red;
}
ExampleHTML:
<div class="myClass">I am a div element with the class name ‘ myClass’</div>
<p> <span class="miaClasse">I am a span element with the class name ‘myClass’</span></p>
In this example, both html elements <div> and <span> will be in italic and colored red.
NB: more classes can be applied to an element (buggy with Internet Explorer 6)
Example of css rules:
.myClass1{
font-style: italic;
}

.myClass2{
color: red;
}
Example HTML:
<p class="myClass1 myClass2">I am an element p with 2 class names</p>

2. Selector #id

The selector #id select an element with a specific and unique id name which can not be applied to other elements.
Example css rules:
#myId{
font-style: italic;
color: green;
}
Example HTML:
<p id="myId">I am a paragraph with an id name ‘myId’</p>
In this example, only the paragraph with the id name ‘myId’ will be italic and colored green.

Pseudo-class

1. :first-child and :last-child

Le pseudo-classi :first-child e :last-child select the first or last child of an element.
NB: NOT compatible with Internet Explorer 6.
:last-child NOT compatible with Internet Explorer 7 and Safari 3.0
Example to select the first child element:
#parent p:first-child{
font-style: italic;
color: red;
}
Example HTML:
<div id="parent">
<p>I am a paragraph, first child of the div element</p>
<p>I am a paragraph, second child of the div element</p>
<p>I am a paragraph, third child of the div element</p>
</div>
In this example, only the first paragraph inside the element div will be italic and colored red. The css rules will not be applied to the following paragraphs.
Example of css rules to select the last child element
#parent p:last-child{
font-style: italic;
color: red;
}
Example HTML:
<div id="parent">
<p>I am a paragraph, first child of the div element</p>
<p>I am a paragraph, second child of the div element</p>
<p>I am a paragraph, third and last child of the div element</p>
</div>
In this example, only the last paragraph inside the element div will be italic and colored red. The css rules will not be applied to the preceding paragraphs.
I pseudo-classi :link e :visited define the css style of the links before and after being visited
Example of css rules for :link e :visited: applied to a link (element a) with a class name ‘mylink’:
a.myLink:link{
color: red;
}
a.myLink:visited{
color: green;
}
Example HTML:
<a class="myLink" href="#nogo">I am a link with a class name ‘myLink”, red before and green after being visited</a>

3. :hover and :active

The pseudo-classes :hover and :active define the css style of an element rolling over and once clicked with the mouse
NB: :active compatible with Internet Explorer only for links, html element a
:hover compatible with Internet Explorer 6 only for links, html element a
Example css rules for :hover and :active applied to a link (element a):
a:hover{
color: red;
}
a:active{
color: green;
}
Example HTML:
<a href="#nogo">I am a link, red on the hover state, green when clicked</a>
Example css rules for :hover and :active applied to a paragraph (element p):
p:hover{
background-color: #F5F5F5;
}
p:active{
background-color: black;
color: white;
}
Esempio HTML:
<p>I am a paragraph with a grey background on the over state; with a black background and white text when clicked.</p>

4. :focus

The pseudo-class :focus define the css style of a selected element in a form.
NB: NOT compatible with Internet Explorer 7 e inferior version.
Example css rule:
input:focus{
background-color: black;
color: white;
}
Example HTML:
<form action="#">
<label for="nome">Nome</label>
<input id="nome" />
<label for="email">Email</label>
<input id="email" />
</form>
In this case, the selected text field will have a black background and white text.

Pseudo element

1. :first-line

The pseudo-element :first-line define the css style of the first line of an element.
Example css rule:
#myParagraph:first-line{
font-style: italic;
color: red;
}
Example HTML:
<p id="myParagraph">The first line of this paragraph will be in italic and colored red</p>

2. :first-letter

The pseudo-element :first-letter define the css style of the first letter of an element
Example css rule:
#myParagraph:first-letter{
font-style: italic;
color: red;
font-size: 30px;
}
Example HTML:
<p id="myParagraph">The first letter of this paragraph will be in italic and colored red</p>

3. :before and :after

The pseudo-elements :after and :before define the css style of a content generated before or after an element
NB: NOT compatible with Internet Explorer 7 e inferior version.
Example css rules:
#myParagraph:before{
content: “I am the content generated before the paragraph”;
font-style: italic;
color: red;
font-size: 30px;
}
#myParagraph:after{
content: “I am the content generated after the paragraph”;
font-style: italic;
color: green;
font-size: 30px;
}
Example HTML:
<p id="myParagraph">I am a paragraph</p>