CSS Reviewer
CSS Reviewer
CSS stands for Cascading Style Sheets the style, and all elements in all the web
Styles - define how to display HTML elements. pages will be updated automatically.
Styles are normally stored in Style Sheets
SUPERIOR STYLES TO HTML
Definition: CSS has a much wider array of
Cascading Style Sheets (CSS) attributes than HTML, so you can give a
is a style sheet language used for far better look to your HTML page in
describing the look and formatting of a comparison to HTML attributes.
document written in a markup language
used in the web. MULTIPLE DEVICE COMPATIBILITY
CSS is a simple design language Style sheets allow content to be
intended to simplify the process of optimized for more than one type of
making web pages presentable. device.
CSS handles the look and feel part of a By using the same HTML document,
web page. Using CSS, you can control different versions of a website can be
the color of the text, the style of fonts, presented for handheld devices such as
the spacing between paragraphs, how PDAs and cell phones or for printing.
columns are sized and laid out, what
background images or colors are used, GLOBAL WEB STANDARDS
layout designs, variations in display for Now HTML attributes are being
different devices and screen sizes as deprecated and it is being
well as a variety of other effects. recommended to use CSS.
CSS specifications are maintained by the So its a good idea to start using CSS in
World Wide Web Consortium (W3C) all the HTML pages to make them
compatible to future browsers.
CSS ADVANTAGES
CSS SAVES TIME CSS SYNTAX
You can write CSS once and then reuse A style rule is made of 5 parts:
same sheet in multiple HTML pages. 1. Selector- A selector is an HTML tag at which a
You can define a style for each HTML style will be applied. This could be any tag like
element and apply it to as many Web or <table> etc./ Customized variable
pages as you want. 2. Property - A property is a type of attribute of
Styles are normally saved in HTML tag. Put simply, all the HTML attributes
external .css files. are converted into CSS properties. They could
External style sheets enable you to be color, border etc.
change the appearance and layout of all 3. Value - Values are assigned to properties. For
the pages in a Web site, just by editing example, color property can have value either
one single file. red or #F1F1F1 etc.
4. Declaration - example is “ selector
PAGES LOAD FASTER { property: value } “
If you are using CSS, you do not need to 5. Declaration Block – example is “ h1 { color:
write HTML tag attributes every time. #36C; fontweight: normal; letter-
Just write one CSS rule of a tag and spacing: .4em; } “
apply it to all the occurrences of that
tag.
So less code means faster download
times.
EASY MAINTENANCE
example below, all HTML elements with
class="center" will be center aligned:
TYPES OF SELECTORS *Do NOT start a Class name with a number!
UNIVERSAL SELECTORS
rather than selecting elements of a .center {text-align:center;}
specific type, the universal selector <h1 class =”center”>Center-aligned
quite simply matches the name of any heading</h1>
element type − • { color: #000000; } <p class = “center”>Center-aligned paragraph.
This rule renders the content of every </p<
element in our document in black.
p.center {text-align:left;}
DESCENDANT SELECTORS <p class=”left”> Center-aligned paragraph. </p>
Suppose you want to apply a style rule
to a particular element only when it lies THE ID SELECTOR
inside a particular element. You can define style rules based on the
As given in the following example, style id attribute of the elements. All the
rule will apply to element only when it elements having that id will be
lies inside formatted according to the defined rule.
tag. ul em { color: #000000; } #black { color: #000000; }
This rule renders the content in black
CLASS SELECTORS for every element with id attribute set
You can define style rules based on the to black in our document. You can make
class attribute of the elements. All the it a bit more particular. For example :
elements having that class will be −This rule renders the content in black for only
formatted according to the defined rule. <h1> elements with id attribute set to black.
.black { color: #000000; } h1#black { color: #000000; }
This rule renders the content in black
for every element with class attribute The true power of id selectors is when they are
set to black in our document. You can used as the foundation for
make it a bit more particular. For descendant selectors, For example −
example − h1.black { color: #000000; } #black h2 { color: #000000; }
This rule renders the content in black
for only elements with class attribute In this example all level 2 headings will be
set to black. You can apply more than displayed in black color when those headings
one class selectors to given element. will lie with in tags having id attribute set to
Consider the following example − black.
<p class = “center bold”>This paragraph will be
styled by the classes center and bold. </p> SAMPLE OF ID SELECTOR
The id selector is used to specify a style
CLASS SELECTOR for a single, unique element.
The class selector is used to specify a The id selector uses the id attribute of
style for a group of elements. Unlike the the HTML element, and is
id selector, the class selector is most defined with a "#".
often used on several elements. The style rule below will be applied to
This allows you to set a particular style the element with id="wrapper":
for many HTML elements with the same
class.
The class selector uses the HTML class
attribute, and is defined with a "." In the
Each declaration Block consists of
Multiple Style Rules
For example, to identify a
paragraph as “head”, use
the code:
<div id=“wrapper”>… </div>