Introduction to Css II
Introduction to Css II
Web Design
Class
can apply to any tag
E.g. .indent{margin-right:5%;margin-left: 5%;}
In HTML, <p class=“indent”>
Advanced
IDs, pseudo-class selectors
E.g. #myId {color: #38608A;}}
ICT453: Internet Technologies and Web Design - GTUC 2013 Delivery #Lempogo Forgor
Classes and IDs
Class and id selectors are used to define styles in your
document that are independent of elements.
Classes can be used to define styles for any number of
elements and for any number of occurrences of elements
in a document.
The id attribute occurs only once in a document, so it
should not be used to declare styles for a number of
elements.
For example
if you know that a certain element in a document will be used
to uniquely identify the document, but you are not sure which
element it will be in each document, you can use the id
selector to generically reference the unique element
independent of the document itself.
ICT453: Internet Technologies and Web Design - GTUC 2013 Delivery #Lempogo Forgor
Class Selector Syntax
Style Sheet
.class_example {
color : red
}
<p class=“class_example”>
ID Selector Syntax
Style Sheet
#id_example {
color : black
}
<p id=“id_example”>
Using class and id Selectors
Classes can also be assigned to individual elements to
allow more control over formatting.
This is done by placing the name of an element in front of
the period in a class style declaration.
For example, the following defines class formatting styles
that apply only to the <p> element:
p{ color: black }
p.red_text { color: red }
p.cyan_text { color: cyan}
These declarations set font colors for the <p> element
depending on which class is defined in the element.
If no class attribute is specified, then the declaration for
the <p> element of black is applied.
class and id Selectors Example
div.box{margin-top:50px;background-color:yellow;
color:#000090;border-style: double; padding:10px; border-
color:#000090; }
p { font-size:16pt; }
p.description{color:#000099;background-color:#cccccc; font-
style: italic; }
#identifier{ color:red; }
.right { text-align: right; }
* { color:#333333; font-family:arial; font-size:10pt; }
h1{ font-size:30pt; text-align:center; font-style:italic; }
h2{ font-size:18pt; text-align:left; font-style:italic; }
h3{ font-size:16pt; text-align:left; font-style:italic; }
<!DOCTYPE html>
class and id Selectors Example
<html lang="en"> <head> <title> CSS Example 2</title>
<link rel="stylesheet" href="example1.css" type="text/css">
</head> <body>
<h1> Course Description </h1>
<div class="box">
<div class="right">
<strong> Course Name: </strong> <span style="color:red"> Internet Technologies
</span> and Web Design <br>
</div> <strong> Course Code: </strong> ICT 453 <br>
<strong> Lecturer: </strong> Mr. Forgor Lempogo <br>
<strong> Class Meets: </strong> Mondays and Wednesdays <br> </div>
<h2 id="identifier"> Course Description: </h2>
<p class="description"> The purpose of this course is to give students the knowledge
and skills to build creative, interactive, and well-designed Web sites. </p>
<h3> Prerequisites
<ul><li> ICT 112 </li> <li> ICT 233 </li> </ul>
</body>
Property Inheritance
We looked at nesting elements in the HTML5 notes.
border-radius: 10px;
The above syntax would style the element to which it
applied to have each corner of the box styled with 10
pixel radius corners.
where the first four numbers represent the horizontal radii and
border-radius: 150px;
border-radius: 15px; width: 150px;
width: 150px;
CSS3 – Radiused Corners
border-radius: 35px/75px;
border-radius: 15px/35px; width: 150px;
width: 150px;
Box Shadows in CSS3
Shadows on HTML element boxes are another example of an effect
that in the days before CSS3, used to take all kinds of graphics,
<div> elements, and patience to produce.
With CSS3, again, only a single line is required to produce the effect.
horizontal offset
vertical offset
blur
spread
color
If you use negative values for right and bottom, then the
shadow appears at the left and top, respectively.
Productivity drop.
Developers who are already proficient at developing
Web pages using tables for the layout will see
productivity drop (temporarily) as they learn about
CSS3 techniques and properties.
Positioning Content Using CSS
In normal flow, the browser renders and places each block
content beneath the previous in the order that they appear
in the HTML5 source code.
<html>
<head></head>
<body>
<h2>Fun with Div Tags and CSS</h2>
<p>Aloha!</p>
<p>Let’s play with div tags. These tags create divisions within a web
page that can be formatted using style elements. </p>
</body>
</html>
<!DOCTYPE html>
CREATING COLUMNS
<html>
<head> </style>
</head>
<style>
<body>
#header {
<div id="header">
background-color:black;
<h1>City Gallery</h1>
color:white; </div>
text-align:center;
padding:5px; <div id="nav">
} London<br>
#nav {
Paris<br>
Tokyo<br>
line-height:30px;
</div>
background-color:#eeeeee;
height:300px; <div id="section">
width:100px; <h2>London</h2>
float:left; <p>
padding:5px; London is the capital city of England. It is the most populous city in the
United Kingdom,
}
with a metropolitan area of over 13 million inhabitants.
#section {
</p>
width:350px;
<p>
float:left; Standing on the River Thames, London has been a major settlement
padding:10px; for two millennia,
} its history going back to its founding by the Romans, who named it
Londinium.
#footer {
</p>
background-color:black;
</div>
color:white;
clear:both; <div id="footer">
text-align:center; Copyright © W3Schools.com
padding:5px; </div>
}
</body>
</html>
Creating Columns - HTML
Creating Columns - CSS
Creating Columns - Results
Creating Columns - Results
By fixing the width of the wrapper and applying auto
horizontal margins to it, as shown in the CSS, the layout
will be centered in the window.
Its height can increase freely as more content is added to
it (see next page rendering with more content added to
the first paragraph - browser window not resized from
previous version).
The article element inside the wrapper div simply
behaves like any unwidthed block-level element and
expands horizontally to fill the wrapper.
Add Columns
We will add a second column of navigational elements to
the left side of the page.
we need to float the wrapper containers for the two
columns in order to get them to sit side by side.
the width of the two containers must equal the width of
the wrapper (150+810=960), and floating them causes
them to sit side by side to form two columns.
Each column is as long as its content.
resetting the width of the layout every time you adjust the
margins or padding would get very tedious, and is thus not an
ideal situation.
It is too easy to break the layout, even accidently, when
adjusting the padding and borders.
Preventing Float-Slip – Solution 2
Apply padding and borders to elements inside the container
Problem
ICT453: Internet Technologies and Web Design - GTUC 2013 Delivery #Lempogo Forgor