1
CS1113 Web Programming
Lecture 09
Pseudo, Position, List, Links
Pseudo - Elements
• CSS pseudo elements
are used to add
special effects
to some selectors.
• Syntax:
select: pseudo-element {
property: value;
}
CSS Pseudo Elements
Value
Description
: first-line Use this element to add special styles to the first line of the text in a selector : first-letter Use this element to add special style to the first letter of the text in a selector. : before Use this element to insert some content before an element.
first-line
• <style>p:first-line {
text-decoration: underline; color: green;
}
</style>
<p>The first line of this paragraph will be underlined as defined in the CSS rule above. Rest of the lines in this paragraph will remain normal.</p>
• Output:
The first line of this paragraph will be underlined as
• The following properties apply to the
:first-line
pseudo-element:
– font properties
– color properties
– background properties
– word-spacing
– Letter-spacing
– text-decoration
– text-transform
– Line-height
– clear
first-letter
• <style>
p:first-letter { font-size: 20pt; color: blue;
}
</style>
<p>The first line of this paragraph will be underlined as defined in the CSS rule above. Rest of the lines in this paragraph will remain normal.</p>
• Output:
:before
• <style>
p:before { content: url(/images/bullet.gif) }
</style>
<p> This line will be preceded by a bullet.</p> <p> This line will be preceded by a bullet.</p> <p> This line will be preceded by a bullet.</p>
• Output:
This line will be preceded by a bullet. This line will be preceded by a bullet. This line will be preceded by a bullet.
:after
• <style>
p:after { content: url(/images/bullet.gif) }
</style>
<p> This line will be preceded by a bullet.</p> <p> This line will be preceded by a bullet.</p> <p> This line will be preceded by a bullet.</p>
• Output:
CSS Links
• You can set different properties of a
hyper link
,
you can set following properties of hyper link:
The
:link
property signifies unvisited hyperlinks.
The
:visited
property signifies visited hyperlinks.
The
:hover
property signifies an element that
currently has the user’s mouse pointer hovering
over it.
The
:active
property signifies an element on which
:link (color of links)
• <style>
a: link
{ color: #009900; }
</style>
<a href=“index.html”> Red Link </a>
• Output:
Red Link
• Possible values:
11
:visited (color of visited links)
• <style>
a: visited
{ color: #006600; }
</style>
<a href=“index.html”> Click this link </a>
• Output:
Click this link
(once you click this link, it will
change its color to green)
• Possible values:
:hover (change the color of links when
mouse is over)
• <style>
a: hover { color: #FFCC00; }
</style>
<a href=“index.html”> Bring mouse here </a>
• Output:
Bring mouse here (bring mouse over the link, it changes its color to yellow)
• Possible Values:
13
:active (color of active links)
• <style>
a:active
{ color: #FF00CC; }
</style>
<a href=“index.html”> Click this link </a>
• Output:
Click this link
(this will change its color to pink,
when user clicks it)
• Possible values:
Typical Web Page (Browser)
header
footer
main
menu
Creating Box
• You can
create boxes or layer
through HTML
elements. All you have to do is use the
position
property
to specify whether the element will be
positioned
absolute or relative
in the document
layout.
• A
relative positioned
layer will follow the natural
flow of the elements in the document.
• An
absolute positioned
layer will be placed
17
position property
• It’s a flag that the browser looks for to
distinguish it
from regular elements
.
• By setting it to a value of absolute, you are alerting the
browser that
it should be positioned at a specific
location
.
• By setting it to a
value of relative
, causes the layer/box
to follow the natural flow of the document order.
• When you specify a value of absolute, you must also
position
• <style>
div
{
position:
absolute;
}
</style>
• Output:
• Possible values:
left
• <style>
div {
position: absolute;
left: 20px;
}
</style>
• Output:
• Possible values:
number positive or negative, px, %, in, mm
top
• <style>
div {
position: absolute;
left: 20px;
top: 200px; }
</style>
• Output:
• Possible values:
width
• <style>
div {
border: 2px solid red;
left: 20px;
width: 200px;
}
</style>
• Output:
• Possible values:
number px, %, auto
height
• <style>
div {
border: 2px solid red;
left: 20px;
width: 200px;
height: 200px; }
</style>
• Output:
• Possible values:
z-index property
• The
z-index property
uses a positive
integer to specify into what position in the
stacking order a
box is placed
.
• A layer/box with z-index set to 1 will be
underneath all subsequent layers.
• The
larger the z-index
, the higher that
layer will be.
z-index
• #box1 { position: absolute; left: 10px; top: 100px; z-index: 3; }
#box2 { position: absolute; left: 100px; top: 258px; z-index: 2; }
#box3 { position: absolute; left: 280px; top: 75px; z-index: 1;
}
<div id=“box1”></div> <div id=“box2”></div> <div id=“box3”></div>
• Possible values:
CSS visibility property
• You can control if an
element is visible
or not
with the visibility property.
• Example:
p
{
visibility:
hide;
}
• Possible values:
CSS Lists
• There are following five CSS properties which can be used to control lists:
• The list-style-type Allows you to control the shape or appearance of the marker.
• The list-style-position Specifies whether a long point that wraps to a second line should align with the first line or
start underneath the start of the marker.
• The list-style-image Specifies an image for the marker rather than a bullet point or number.
• The list-style Serves as shorthand for the preceding properties.
list-style-image
• You can use an image for the bullet of
unordered lists.
• <ul
style=
“list-style-image: url(image.gif);”
>
<li>One</li>
<li>Two</li>
</ul>
• Output:
• Possible values:
list-style-type
• <ul
style=
“list-style-type: lower-alpha;”
>
<li>One</li>
<li>Two</li>
</ul>
• Output:
• Possible values:
disc, circle, square, decimal, lower-roman,
upper-roman, lower-alpha, upper-alpha,
list-style-position
• <ul
style=
“list-style-position: lower-alpha;”
>
<li>One</li>
<li>Two</li>
</ul>
• Output:
• Possible values:
list-style
• <ul
style=
“list-style: inside lower-alpha;”
>
<li>One</li>
<li>Two</li>
</ul>
• Output:
marker-offset
marker-offset
• <ul
style=
“list-style-type: upper-alpha;
marker-offset: 2cm;”
>
<li>Maths</li>
<li>Computer</li>
</ul>
• Output:
A. Maths
B. Computer
• Possible values:
cursor
• You can control the style of cursor to be
used in an element with the cursor property.
• Syntax:
cursor:
value;
• Possible Values: