Title: Introduction to CSS by programmerblog.net
1Cascading Style Sheets(CSS)
- Introduction to CSS By Programme Blog
- http//programmerblog.net/
2CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- What is CSS?
- CSS stands for Cascading Style Sheets
- Styles define how to display HTML elements
- Styles were added to HTML 4.0 to solve a problem
- External Style Sheets can save a lot of work
- External Style Sheets are stored in CSS files.
- HTML was never intended to contain tags for
formatting a document. - HTML was intended to define the content of a
document, like - lth1gtThis is a headinglt/h1gt
- ltpgtThis is a paragraph.lt/pgt
- When tags like ltfontgt, and color attributes were
added to the HTML 3.2 specification. - Development of large web sites, where fonts and
color information were added to every single
page, became a long and expensive process. - To solve this problem, the World Wide Web
Consortium (W3C) created CSS. - CSS Syntax
- A CSS rule has two main parts a selector, and
one or more declarations
3CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- CSS declarations always ends with a semicolon,
and declaration groups are surrounded by curly
brackets - p colorred text-aligncenter
- p colorred
text-aligncenter
4CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- The id and class Selectors
- The id Selector
- The id selector is used to specify a style for a
single, unique element. - The style rule below will be applied to the
element with id"para1" - The id selector uses the id attribute of the HTML
element, and is defined with a "". - para1 text-aligncenter
colorred - Note Do NOT start an ID name with a number! It
will not work in Mozilla/Firefox. - The class Selector
- The class selector is used to specify a style for
a group of elements. Unlike the id selector, the
class selector is most often used on several
elements. - This allows you to set a particular style for any
HTML elements with the same class. - The class selector uses the HTML class attribute,
and is defined with a "." - In the example below, all HTML elements with
class"center" will be center-aligned - Example
- .center text-aligncenter
5CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- You can also specify that only specific HTML
elements should be affected by a class. - In the example below, all p elements with
class"center" will be center-aligned - p.center text-aligncenter
- Note Do NOT start a class name with a number!
This is only supported in Internet Explorer.
6CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- Where CSS Fits In Page
- Three Ways to Insert CSS
- There are three ways of inserting a style sheet
- External style sheet
- Internal style sheet
- Inline style
- External Style Sheet
- An external style sheet is ideal when the style
is applied to many pages. With an external style
sheet, you can change the look of an entire Web
site by changing one file. Each page must link to
the style sheet using the ltlinkgt tag. The ltlinkgt
tag goes inside the head section - ltheadgt ltlink rel"stylesheet"
type"text/css" href"mystyle.css" /gtlt/headgt
7CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- An external style sheet can be written in any
text editor. - The file should not contain any html tags.
- Your style sheet should be saved with a .css
extension. An example of a style sheet file is
shown below - hr colorsienna p
margin-left20px body background-imageur
l("images/back40.gif") - Internal Style Sheet
- An internal style sheet should be used when a
single document has a unique style. You define
internal styles in the head section of an HTML
page, by using the ltstylegt tag, like this - ltheadgtltstyle type"text/css"gt hr
colorsienna p
margin-left20px body
background-imageurl("images/back40.gif")
lt/stylegtlt/headgt - Inline Styles
- An inline style loses many of the advantages of
style sheets by mixing content with presentation.
Use this method sparingly!
8CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- To use inline styles you use the style attribute
in the relevant tag. The style attribute can
contain any CSS property. The example shows how
to change the color and the left margin of a
paragraph - ltp style"colorsiennamargin-left20px"gtThis is
a paragraph.lt/pgt - Multiple Style Sheets
- If some properties have been set for the same
selector in different style sheets, the values
will be inherited from the more specific style
sheet. - For example, an external style sheet has these
properties for the h3 selector - h3 colorred text-alignleft font-size8pt
And an internal style sheet has these
properties for the h3 selector - h3 text-alignright font-size20pt
- If the page with the internal style sheet also
links to the external style sheet the properties
for h3 will be - colorredtext-alignrightfont-size20pt
9CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- Cascading order
- What style will be used when there is more than
one style specified for an HTML element? - Generally speaking we can say that all the styles
will "cascade" into a new "virtual" style sheet
by the following rules, where number four has the
highest priority - Browser default
- External style sheet
- Internal style sheet (in the head section)
- Inline style (inside an HTML element)
- So, an inline style (inside an HTML element) has
the highest priority, which means that it will
override a style defined inside the ltheadgt tag,
or in an external style sheet, or in a browser (a
default value).
10CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- CSS Styling
- CSS background properties are used to define the
background effects of an element. - CSS properties used for background effects
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
- name - a color name, like "red"
- RGB - an RGB value, like "rgb(255,0,0)"
- Hex - a hex value, like "ff0000"
- h1 background-color6495ed p
background-colore0ffff div
background-colorb0c4de - body background-imageurl('bgdesert.jpg')
- background-repeatno-repeat OR repeat-x OR
repeat-y - Short - Hand for Background
- body backgroundffffff url('img_tree.png')
no-repeat right top
11CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- Text Color
- body colorblue
- Text Alignment
- h1 text-aligncenter
- Text Decoration
- The text-decoration property is mostly used to
remove underlines from links for design purposes. - a text-decorationnone
- Text Transformation
- Text Indentation
- The text-indentation property is used to specify
the indentation of the first line of a text. - p text-indent50px
- CSS- FONT
12CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- CSS Font Families
- In CSS, there are two types of font family names
- generic family - a group of font families with a
similar look (like "Serif" or "Monospace") - font family - a specific font family (like
"Times New Roman" or "Arial") - p font-family"Times New Roman", Times, serif
- p.normal font-stylenormal
- h1 font-size40px
- Styling Links
- Links can be styled with any CSS property (e.g.
color, font-family, background, etc.). - The four links states are
- alink - a normal, unvisited link
- avisited - a link the user has visited
- ahover - a link when the user mouses over it
- aactive - a link the moment it is clicked
- alink colorFF0000 /
unvisited link /avisited color00FF00
/ visited link /ahover colorFF00FF
/ mouse over link /aactive
color0000FF / selected link / - avisited text-decorationnone
13CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- CSS Tables
- Table Borders
- To specify table borders in CSS, use the border
property. - table, th, td border 1px
solid black - Table will have double borders. This is because
both the table, th, and td elements have separate
borders. - Collapse Borders
- The border-collapse property sets whether the
table borders are collapsed into a single border
or separated tableborder-collapsecollapse
table,th, tdborder 1px solid black - Table Width and Height
- Width and height of a table is defined by the
width and height properties. - table width100 th
height50px
14CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
- Table Text Alignment
- The text in a table is aligned with the
text-align and vertical-align properties. - td text-alignright
- Table Color Table Padding
- td padding15px
- table, td, thborder1px solid
greenthbackground-colorgreencolorwhite
-
15CSS Cascading Style SheetsBy Programmer Blog
http//programmerblog.net/
-
Thank you for viewing this slide. -
- Hope this is
helpful for you. - Please visit
our blog -
http//programmerblog.net/ -
Follow us on twitter https//twitter.com/progblogd
otnet/ -
By ProgrammerBlog.net -
http//programmerblog.net/