:after

In this chapter you will learn:

  1. Definition for Selector :after
  2. An example showing how to use :after CSS selector
  3. How to add content after list item
  4. How to add after content for a class

Description

The :after selector inserts content after the selected elements.

Example

<!DOCTYPE html><!--from   j  av  a  2 s.c o  m-->
<html>
<head>
<style>
p:after{
   content:"added after";
}
</style>
</head>

<body>
   <p>this is a paragraph.</p>

</body>
</html>

Click to view the demo

Adding after content for list

<!DOCTYPE HTML><!--  j a  v  a2s  .  c o  m-->
<html>
<head>
<style type="text/css">
li:after {
 content: ", "; 
}
</style>
</head>
<body>
  <ul>
   <li>Database</li>
   <li>Privacy</li>
   <li>Best</li>
   <li>Whatever</li>
   <li class="last">Make One</li>
  </ul>
</body>
</html>

Click to view the demo

after content for a class

The following code adds after content for class named last.

<!DOCTYPE HTML><!--from ja v  a 2  s  .c o  m-->
<html>
<head>
<style type="text/css">
li.last:after {
 content: ".";
}
</style>
</head>
<body>
  <ul>
   <li>Database</li>
   <li>Privacy</li>
   <li>Best</li>
   <li>Whatever</li>
   <li class="last">Make One</li>
  </ul>
</body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. Definition for Selector:first-of-type
  2. An example showing how to use :first-of-type CSS selector
Home » HTML CSS Tutorial » CSS Selector Reference
.class
#id
*
element
element,element
element element
element>element
element+element
element1~element2
:lang
:link
:visited
:active
:hover
:focus
:first-letter
:first-line
:first-child
:last-child
:only-child
:nth-child(n)
:nth-last-child(n)
:before
:after
:first-of-type
:last-of-type
:only-of-type
:nth-of-type(n)
:nth-last-of-type(n)
:root
:empty
:target
:enabled
:disabled
:checked
:not
::selection
[attribute]
[attribute=value]
[attribute~=value]
[attribute|=value]
[attribute^=value]
[attribute$=value]
[attribute*=value]