Professional Documents
Culture Documents
🞂 Control of backgrounds.
🞂 Set font size to the exact height you want.
🞂 Highlight words, entire paragraphs, headings or even
individual letters with background colors.
🞂 Overlap words and make logo-type headers without
making images.
🞂 Precise positioning.
🞂 Linked style sheets to control the look of a whole website
from one single location.
🞂 And more
Writing CSS
🞂 Selector
🞂 HTML element tags
(examples: p, h2, body, img, table)
🞂 class and ID names
🞂 Property (examples: color, font-size)
🞂 Value (examples: red, 14pt)
Writing CSS
Example:
p {font-size: 8pt; color: red}
Notice the { } around the rule and the : before each value!
Types of Style Sheet
🞂 There are three ways to associate styles with your HTML
document. Most commonly used
🞂 inline CSS
🞂 Internal CSS
🞂 External CSS
Inline CSS
Inline styles relate to a specific HTML tag, using a style
attribute with a CSS rule to style a specific page element.
They’re useful for quick, permanent changes, but are less
flexible than external and internal style sheets as each
inline style you create must be separately edited should
you decide to make a design change.
INTERNAL CSS
🞂 This can be used when a single HTML document must
be styled uniquely. The CSS rule set should be within the
HTML file in the head section i.e the CSS is embedded
within the HTML file.
EXTERNAL CSS
🞂 External CSS contains separate CSS file which contains
only style property with the help of tag attributes (For
example class, id, heading, … etc). CSS property written
in a separate file with .css extension and should be
linked to the HTML document using link tag. This
means that for each element, style can be set only once
and that will be applied across web pages.
CSS Rule
🞂 A CSS comprises of style rules that are interpreted by the
browser and then applied to
🞂 the corresponding elements in your document. A style rule
is made of three parts: selector, property and its value.
Declaration is shown below.
Selector
{
Property_1 :value_1 ;
Property-2 :value_2;
Property_3 : value_3;
}
Types of Selector
1) Tag Selector
2) Class Selector
3) Universal Selector
4) ID selector
5) Grouping Selectors
6) Descendant Selector
7) Child Selector
Tag Selector
🞂 Any html element can be accessed in css using their tag
name. Tags can be used more than once, so all elements
will be called.
🞂 Example:
🞂 <style>
🞂 body{ font-family:sans-serif }
🞂 h3{ color:red}
🞂 p{ color:blue; text-align:center}
🞂 </style>
CLASS Selector
🞂 The CSS Class selector is one of the most helpful
selectors of all the selectors. It is declared by using a dot
followed by the name of the class. This class name is
defined by the coder, as is the case with the ID selector.
The class selector searches for every element having an
attribute value with the same name as the class name,
without the dot.
🞂 Example:
🞂 .square {
margin: 20px;
width: 20px;
}
Universal Selector
🞂 Selects all elements. Optionally, it may be restricted to a
specific namespace or to all namespaces.
🞂 Example:
🞂* {
color: blue;
font-size: 21px;
}
ID SELECTOR
🞂 Selects an element based on the value of its id attribute.
There should be only one element with a given ID in a
document.
🞂 Example:
🞂 #box {
width: 90px;
margin: 10px;
}
Grouping Selector
🞂 The grouping selector selects all the HTML elements with
the same style definitions.
🞂 In this example, we condense three rules with identical
declarations into one. Thus,
• Example:
• h1, h2, p {
text-align: center;
color: red;
}.
CSS Box Model
■ The “Box Model” is a tool we use to lay out our web
pages in a number of individual "boxes" or
"containers". When we plan our web page design, we
must take into account not only the size of page
content, but also the margins, borders, and padding
involved.
■ Before we start building a page, we can plan where
everything will go by arranging these boxes on the
screen. Our goal is to create a balanced layout, with
plenty of "white space" around the content.
The Component of a Box
Margin
Border
Padding
Content
<div> Tag
🞂 The <div> tag is our basic building block when laying out a
page design. By defining the height and width of the <div>,
we are "reserving" that amount of space on the screen for
whatever content we wish to place there.
<div class="box300">
This is outside the box.
This is a 300 by 300 pixel box
with a 1px border.
</div> By establishing the box
This is outside the box. dimensions, we can leave it there
as a placeholder until we have our
content ready. In the meantime,
the rest of the page can be built out
with our other content.
Adding padding:
<head> This is a 300 by 300 pixel box
<style type="text/css"> with a 1px border and 10px
.box300 { padding.
width:300px;
height:300px;
border:1px solid black;
padding:10px;
}
</style>
</head>
🞂 A useful technique is to set the right and left margins of a <div> to the
value "auto". This tells the browser to maintain an equal distance on the
right and left, effectively centering the <div> no matter how wide the
available area is:
.centerme {
margin:0 auto;
}
🞂 This same technique can be used on a <div> element that contains all your
page content in order to center your page on the screen, no matter what the
screen resolution of your web visitor.