css training material
TRANSCRIPT
-
8/6/2019 CSS TRaining Material
1/61
EDIT INSTITUTE(A Division of Edit Systems Pvt. Ltd.)
Cascading Style Sheet
EDIT SYSTEMS PVT. LTD.2nd Floor, 43, Kennedy Bridge, Next to Parekh Market, Oepra House, Mumbai 400 004. Ph.:- 23865161 / 23863337.
-
8/6/2019 CSS TRaining Material
2/61
CSS (Basic & Advanced) 2 Edit Institute
Session 1
Introduction to CSS (Basic) / Syntax
Introduction to CSS
What You Should Already Know
Before you continue you should have some basic understanding of the following:
HTML / XHTML
What is CSS?
CSS stands for Cascading Style Sheets
Styles define how to display HTML elements
Styles are normally stored in Style Sheets
Styles were added to HTML 4.0 to solve a problem
External Style Sheets can save you a lot of work
External Style Sheets are stored in CSS files
Multiple style definitions will cascade into one
With CSS, your HTML documents can be displayed using different output styles:
Styles Solve a Common Problem
HTML tags were originally designed to define the content of a document. They were supposed tosay "This is a header", "This is a paragraph", "This is a table", by using tags like ,
,, and so on. The layout of the document was supposed to be taken care of by thebrowser, without using any formatting tags.
As the two major browsers - Netscape and Internet Explorer - continued to add new HTML tags
and attributes (like the tag and the color attribute) to the original HTML specification, itbecame more and more difficult to create Web sites where the content of HTML documents wasclearly separated from the document's presentation layout.
To solve this problem, the World Wide Web Consortium (W3C) - the non profit, standard settingconsortium, responsible for standardizing HTML - created STYLES in addition to HTML 4.0.
All major browsers support Cascading Style Sheets.
Style Sheets Can Save a Lot of Work
Styles sheets define HOW HTML elements are to be displayed, just like the font tag and the colorattribute in HTML 3.2. Styles are normally saved in external .css files. External style sheetsenable you to change the appearance and layout of al l the pages in your Web, just by editing onesingle CSS document!
CSS is a breakthrough in Web design because it allows developers to control the style and layout
of multiple Web pages all at once. As a Web developer you can define a style for each HTMLelement and apply it to as many Web pages as you want. To make a global change, simplychange the style, and all elements in the Web are updated automatically.
TM
-
8/6/2019 CSS TRaining Material
3/61
Edit Institute 3 CSS (Basic & Advanced)
Multiple Styles Will Cascade Into One
Style sheets allow style information to be specified in many ways. Styles can be specified inside a
single HTML element, inside the element of an HTML page, or in an external CSS file.Even multiple external style sheets can be referenced inside a single HTML document.
Cascading Order
What style will be used when there is more than one style specif ied for an HTML element?
Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet bythe following rules, where number four has the highest priority:
i. Browser default
ii. External style sheet
iii. Internal style sheet (inside the tag)
iv. 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 declared inside the tag, in an external style sheet, or in a browser (adefault valu1e).
CSS Syntax
Syntax
The CSS syntax is made up of three parts: a selector, a property and a value:
selector {property: value}
The selector is normally the HTML element/tag you wish to define, the property is the attribute
you wish to change, and each property can take a value. The property and value are separatedby a colon, and surrounded by curly braces:
body {color: black}
Note: If the value is multiple words, put quotes around the value:
p {font-family: "sans serif"}
Note: If you wish to specify more than one property, you must separate each property with a
semicolon. The example below shows how to define a center aligned paragraph, with a red textcolor:
p {text-align:center;color:red}
To make the style definitions more readable, you can describe one property on each line, like
this:
p
{
text-align: center;
color: black;
font-family: arial
-
8/6/2019 CSS TRaining Material
4/61
CSS (Basic & Advanced) 4 Edit Institute
}
Grouping
You can group selectors. Separate each selector with a comma. In the example below we havegrouped all the header elements. All header elements will be displayed in green text color:
h1,h2,h3,h4,h5,h6
{
color: green
}
The class Selector
With the class selector you can define different styles for the same type of HTML element.
Say that you would like to have two types of paragraphs in your document: one right-alignedparagraph, and one center-aligned paragraph. Here is how you can do it with styles:
p.right {text-align: right}
p.center {text-align: center}
You have to use the class attribute in your HTML document:
This paragraph will be right-aligned.
This paragraph will be center-aligned.
Note: Only one class attribute can be specified per HTML element! The example below is wrong:
This is a paragraph.
You can also omit the tag name in the selector to define a style that will be used by all HTMLelements that have a certain class. In the example below, all HTML elements with class="center"will be center-aligned:
.center {text-align: center}
In the code below both the h1 element and the p element have class="center". This means thatboth elements will follow the rules in the ".center" selector:
This heading will be center-aligned
-
8/6/2019 CSS TRaining Material
5/61
Edit Institute 5 CSS (Basic & Advanced)
This paragraph will also be center-aligned.
Note:- Do NOT start a class name with a number! It will not work in Mozilla/Firefox.
The id Selector
You can also def ine styles for HTML elements with the id selector. The id selector is defined as a#.
The style rule below will match the element that has an id attribute with a value of "green":
#green {color: green}
The style rule below will match the p element that has an id with a value of "para1":
p#para1
{
text-align: center;
color: red
}
Note: Do NOT start an ID name with a number! It will not work in Mozilla/Firefox.
CSS Comments
Comments are used to explain your code, and may help you when you edit the source code at alater date. A comment will be ignored by browsers. A CSS comment begins with "/*", and endswith "*/", like this:
/* This is a comment */
p
{
text-align: center;
/* This is another comment */
color: black;
font-family: arial
}
-
8/6/2019 CSS TRaining Material
6/61
CSS (Basic & Advanced) 6 Edit Institute
Session 2
CSS How to
CSS How to
Insert a Style Sheet
When a browser reads a style sheet, it will format the document according to it. There are threeways of inserting a style sheet:
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 tothe style sheet using the tag. The tag goes inside the head section:
The browser will read the style definitions from the file mystyle.css, and format the documentaccording to it.
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 shownbelow:
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
Note: Do NOT leave spaces between the property value and the units! If you use "margin-left: 20
px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not work inMozilla/Firefox or Netscape.
Internal Style Sheet
An internal style sheet should be used when a single document has a unique style. You defineinternal styles in the head section by using the tag, like this:
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
TM
-
8/6/2019 CSS TRaining Material
7/61
Edit Institute 7 CSS (Basic & Advanced)
The browser will now read the style definitions, and format the document according to it.
Note: A browser normally ignores unknown tags. This means that an old browser that does not
support styles, will ignore the tag, but the content of the tag will be displayed onthe page. It is possible to prevent an old browser from displaying the content by hiding it in the
HTML comment element:
Inline Styles
An inline style loses many of the advantages of style sheets by mixing content with presentation.
Use this method sparingly, such as when a style is to be applied to a single occurrence of anelement.
To use inline styles you use the style attribute in the relevant tag. The style attribute can containany CSS property. The example shows how to change the color and the left margin of aparagraph:
This is a paragraph
Multiple Style Sheets
If some properties have been set for the same selector in dif ferent style sheets, the values will beinherited from the more specific style sheet.
For example, an external style sheet has these properties for the h3 selector:
h3
{
color: red;
text-align: left;
font-size: 8pt
}
-
8/6/2019 CSS TRaining Material
8/61
CSS (Basic & Advanced) 8 Edit Institute
And an internal style sheet has these properties for the h3 selector:
h3
{
text-align: right;
font-size: 20pt
}
If the page with the internal style sheet also links to the external style sheet the properties for h3will be:
color: red;
text-align: right;
font-size: 20pt
The color is inherited from the external style sheet and the text-alignment and the font-size is
replaced by the internal style sheet.
-
8/6/2019 CSS TRaining Material
9/61
Edit Institute 9 CSS (Basic & Advanced)
Session 3
CSS Background
CSS Background
The CSS background properties define the background effects of an element.
CSS Background Properties
The CSS background properties allow you to control the background color of an element, set an
image as the background, repeat a background image vertically or horizontally, and position animage on a page.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
background A shorthand property for
setting all backgroundproperties in one declaration
background-color
background-image
background-repeatbackground-attachmentbackground-position
4 1 6 1
background-attachmentSets whether a backgroundimage is fixed or scrolls withthe rest of the page
scrollfixed
4 1 6 1
background-color Sets the background color ofan element
color-rgb
color-hex
color-nametransparent
4 1 4 1
background-image Sets an image as thebackground
urlnone
4 1 4 1
background-position Sets the starting position ofa background image
top left
top centertop rightcenter leftcenter centercenter rightbottom left
bottom centerbottom rightx-% y-%x-pos y-pos
4 1 6 1
background-repeat Sets if/how a backgroundimage will be repeated
repeatrepeat-xrepeat-yno-repeat
4 1 4 1
TM
-
8/6/2019 CSS TRaining Material
10/61
-
8/6/2019 CSS TRaining Material
11/61
Edit Institute 11 CSS (Basic & Advanced)
4. How to repeat a background image horizontally
body{background-image:url('bgdesert.jpg');background-repeat: repeat-x}
5. How to place background imagebody{
background-image:url('smiley.gif');background-repeat:no-repeat;background-position:center;
}
6. A fixed background image (this image will not scroll with the rest of the page)
body{background-image:url('smiley.gif');
-
8/6/2019 CSS TRaining Material
12/61
CSS (Basic & Advanced) 12 Edit Institute
background-repeat:no-repeat;background-attachment:fixed}
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
The image will not scroll with the rest of the page
7. All the background properties in one declarationbody{background: #00ff00 url('smiley.gif') no-repeat fixed center;}
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
-
8/6/2019 CSS TRaining Material
13/61
Edit Institute 13 CSS (Basic & Advanced)
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
This is some text
-
8/6/2019 CSS TRaining Material
14/61
CSS (Basic & Advanced) 14 Edit Institute
Session 4
CSS Text / Font
CSS Text
The CSS text properties define the appearance of text.
CSS Text Properties
The CSS text properties allow you to control the appearance of text. It is possible to change thecolor of a text, increase or decrease the space between characters in a text, align a text, decoratea text, indent the first line in a text, and more.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Property Description Values IE F N W3C
color Sets the color of a text color 3 1 4 1
direction Sets the text direction ltrrtl
6 1 6 2
letter-spacing Increase or decrease thespace between characters
normallength
4 1 6 1
text-align Aligns the text in an element left
right
centerjustify
4 1 4 1
text-decoration Adds decoration to text noneunderlineoverlineline-throughblink
4 1 4 1
text-indent Indents the first line of text inan element
length%
4 1 4 1
text-shadow nonecolorlength
text-transform Controls the letters in anelement
none
capitalizeuppercaselowercase
4 1 4 1
unicode-bidi normal
embed
5 2
TM
-
8/6/2019 CSS TRaining Material
15/61
Edit Institute 15 CSS (Basic & Advanced)
bidi-override
white-space Sets how white space insidean element is handled
normal
prenowrap
5 1 4 1
word-spacing Increase or decrease thespace between words
normallength
6 1 6 1
CSS Font
The CSS font properties define the font in text.
CSS Font Properties
The CSS font properties allow you to change the font family, boldness, size, and the style of atext.
Note: In CSS1 fonts are identified by a font name. If a browser does not support the specifiedfont, it will use a default font.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Property Description Values IE F N W3C
font A shorthand property forsetting all of the propertiesfor a font in one declaration
font-style
font-variantfont-weight
font-size/line-heightfont-family
caption
iconmenumessage-boxsmall-captionstatus-bar
4 1 4 1
font-family A prioritized list of font family
names and/or generic familynames for an element
family-namegeneric-family
3 1 4 1
font-size Sets the size of a font xx-smallx-smallsmall
mediumlargex-largexx-largesmallerlargerlength%
3 1 4 1
-
8/6/2019 CSS TRaining Material
16/61
CSS (Basic & Advanced) 16 Edit Institute
font-size-adjust Specifies an aspect value foran element that will preservethe x-height of the first-choice font
nonenumber
- - - 2
font-stretch Condenses or expands the
current font-family
normal
widernarrowerultra-condensedextra-condensedcondensedsemi-condensedsemi-expandedexpandedextra-expandedultra-expanded
- - - 2
font-style Sets the style of the font normal
italic
oblique
4 1 4 1
font-variant Displays text in a small-capsfont or a normal font
normalsmall-caps
4 1 6 1
font-weight Sets the weight of a font normal
boldbolderlighter100200300400
500600700800900
4 1 4 1
Examples
Text
1. Set the color of the text
h1 {color: #00ff00}h2 {color: #dda0dd}p {color: rgb(0,0,255)}
-
8/6/2019 CSS TRaining Material
17/61
Edit Institute 17 CSS (Basic & Advanced)
This is header 1This is header 2
This is a paragraph
2. Specify the space between characters
h1 {letter-spacing: -3px}h4 {letter-spacing: 0.5cm}
This is header 1
This is header 4
3. Align the texth1 {text-align: center}h2 {text-align: left}h3 {text-align: right}
This is header 1This is header 2This is header 3
4. Decorate the text
h1 {text-decoration: overline}h2 {text-decoration: line-through}h3 {text-decoration: underline}a {text-decoration: none}
This is header 1
-
8/6/2019 CSS TRaining Material
18/61
CSS (Basic & Advanced) 18 Edit Institute
This is header 2This is header 3
This is a link
5. Indent textp {text-indent: 1cm}
This is some text in a paragraphThis is some text in a paragraphThis is some text in a paragraph
This is some text in a paragraphThis is some text in a paragraphThis is some text in a paragraph
6. Control the letters in a textp.uppercase {text-transform: uppercase}p.lowercase {text-transform: lowercase}
p.capitalize {text-transform: capitalize}
This is some text in a paragraph
This is some text in a paragraph
This is some text in a paragraph
-
8/6/2019 CSS TRaining Material
19/61
Edit Institute 19 CSS (Basic & Advanced)
Font
1. Set the font of a texth3 {font-family: times}p {font-family: courier}p.sansserif {font-family: sans-serif}
This is header 3
This is a paragraph
This is a paragraph
2. Set the size of the fonth1 {font-size: 150%}h2 {font-size: 130%}p {font-size: 100%}
This is header 1This is header 2
This is a paragraph
3. Set the style of the fonth1 {font-style: italic}h2 {font-style: normal}p {font-style: oblique}
This is header 1This is header 2
This is a paragraph
-
8/6/2019 CSS TRaining Material
20/61
CSS (Basic & Advanced) 20 Edit Institute
4. Set the variant of the fontp.normal {font-variant: normal}p.small {font-variant: small-caps}
This is a paragraph
This is a paragraph
5. Set the boldness of the font
p.normal {font-weight: normal}p.thick {font-weight: bold}p.thicker {font-weight: 900}
This is a paragraph
This is a paragraph
This is a paragraph
6. All the font properties in one declarationp{font: italic small-caps 900 12px arial}
This is a paragraph
-
8/6/2019 CSS TRaining Material
21/61
Edit Institute 21 CSS (Basic & Advanced)
Session 5
CSS Border / Margin / Padding
CSS Border
The CSS border properties define the borders around an element.
CSS Border Properties
The CSS border properties allow you to specify the style and color of an element's border. In
HTML we use tables to create borders around a text, but with the CSS border properties we cancreate borders with nice effects, and it can be applied to any element.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
border A shorthand property for
setting all of the propertiesfor the four borders in onedeclaration
border-width
border-styleborder-color
4 1 4 1
border-bottom A shorthand property forsetting all of the propertiesfor the bottom border in onedeclaration
border-bottom-width
border-styleborder-color
4 1 6 1
border-bottom-color Sets the color of the bottomborder
border-color 4 1 6 2
border-bottom-style Sets the style of the bottomborder
border-style 4 1 6 2
border-bottom-width Sets the width of the bottomborder
thin
mediumthicklength
4 1 4 1
border-color Sets the color of the fourborders, can have from oneto four colors
color 4 1 6 1
border-left A shorthand property forsetting all of the propertiesfor the left border in onedeclaration
border-left-widthborder-styleborder-color
4 1 6 1
border-left-color Sets the color of the leftborder
border-color 4 1 6 2
border-left-style Sets the style of the left border-style 4 1 6 2
TM
-
8/6/2019 CSS TRaining Material
22/61
CSS (Basic & Advanced) 22 Edit Institute
border
border-left-width Sets the width of the leftborder
thin
mediumthicklength
4 1 4 1
border-right A shorthand property forsetting all of the propertiesfor the right border in onedeclaration
border-right-widthborder-styleborder-color
4 1 6 1
border-right-color Sets the color of the rightborder
border-color 4 1 6 2
border-right-style Sets the style of the rightborder
border-style 4 1 6 2
border-right-width Sets the width of the rightborder
thinmedium
thicklength
4 1 4 1
border-style Sets the style of the four
borders, can have from oneto four styles
none
hiddendotteddashedsoliddoublegrooveridgeinsetoutset
4 1 6 1
border-top A shorthand property forsetting all of the propertiesfor the top border in onedeclaration
border-top-widthborder-styleborder-color
4 1 6 1
border-top-color Sets the color of the topborder
border-color 4 1 6 2
border-top-style Sets the style of the topborder
border-style 4 1 6 2
border-top-width Sets the width of the top
border
thin
mediumthicklength
4 1 4 1
border-width A shorthand property for
setting the width of the fourborders in one declaration,can have from one to fourvalues
thin
mediumthicklength
4 1 4 1
-
8/6/2019 CSS TRaining Material
23/61
Edit Institute 23 CSS (Basic & Advanced)
CSS Margin
The CSS margin properties define the space around elements.
CSS Margin Properties
The CSS margin properties define the space around elements. It is possible to use negativevalues to overlap content. The top, right, bottom, and left margin can be changed independentlyusing separate properties. A shorthand margin property can also be used to change all of themargins at once.
Note: Netscape and IE give the body tag a default margin of 8px. Opera does not! Instead, Opera
applies a default padding of 8px, so if one wants to adjust the margin for an entire page and haveit display correctly in Opera, the body padding must be set as well!
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
margin A shorthand property forsetting the margin propertiesin one declaration
margin-topmargin-right
margin-bottommargin-left
4 1 4 1
margin-bottom Sets the bottom margin of anelement
autolength%
4 1 4 1
margin-left Sets the left margin of an
element
auto
length%
3 1 4 1
margin-right Sets the right margin of anelement
autolength%
3 1 4 1
margin-top Sets the top margin of anelement
autolength%
3 1 4 1
CSS Padding
CSS Padding
The CSS padding properties define the space between the element border and the elementcontent.
CSS Padding Properties
The CSS padding properties define the space between the element border and the elementcontent. Negative values are not allowed. The top, right, bottom, and left padding can be changed
-
8/6/2019 CSS TRaining Material
24/61
CSS (Basic & Advanced) 24 Edit Institute
independently using separate properties. A shorthand padding property is also created to controlmultiple sides at once.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Property Description Values IE F N W3C
padding A shorthand property for
setting all of the paddingproperties in one declaration
padding-top
padding-rightpadding-bottompadding-left
4 1 4 1
padding-bottom Sets the bottom padding ofan element
length%
4 1 4 1
padding-left Sets the left padding of anelement
length%
4 1 4 1
padding-right Sets the right padding of anelement
length%
4 1 4 1
padding-top Sets the top padding of anelement
length%
4 1 4 1
Examples
Border
1. Set the style of the four borders
p.dotted {border-style: dotted}p.dashed {border-style: dashed}p.solid {border-style: solid}p.double {border-style: double}p.groove {border-style: groove}p.ridge {border-style: ridge}p.inset {border-style: inset}p.outset {border-style: outset}
A dotted border
A dashed border
A solid border
A double border
A groove border
-
8/6/2019 CSS TRaining Material
25/61
Edit Institute 25 CSS (Basic & Advanced)
A ridge border
An inset border
An outset border
2. Set different borders on each sidep.soliddouble {border-style: solid double}p.doublesolid {border-style: double solid}p.groovedouble {border-style: groove double}p.three {border-style: solid double groove}
Some text
Some text
Some text
Some text
3. Set the color of the four borders
p.one{border-style: solid;border-color: #0000ff}p.two{border-style: solid;
border-color: #ff0000 #0000ff}p.three{border-style: solid;border-color: #ff0000 #00ff00 #0000ff}p.four{border-style: solid;
-
8/6/2019 CSS TRaining Material
26/61
CSS (Basic & Advanced) 26 Edit Institute
border-color: #ff0000 #00ff00 #0000ff rgb(250,0,255)}
One-colored border!
Two-colored border!
Three-colored border!
Four-colored border!
Note: The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.
4. Set the width of the bottom borderp{border-style: solid;border-bottom-width: 15px}
Note: The "border-bottom-width" property does not work if it is used alone. Use the"border-style" property to set the borders first.
5. Set the width of the left borderp
{border-style: solid;border-left-width: 15px}
Note: The "border-left-width" property does not work if it is used alone. Use the"border-style" property to set the borders first.
-
8/6/2019 CSS TRaining Material
27/61
Edit Institute 27 CSS (Basic & Advanced)
6. Set the width of the right borderp{border-style: solid;border-right-width: 15px}
Note: The "border-right-width" property does not work if it is used alone. Use the"border-style" property to set the borders first.
7. Set the width of the top borderp{border-style: solid;border-top-width: 15px}
Note: The "border-top-width" property does not work if i t is used alone. Use the"border-style" property to set the borders first.
8. All the bottom border properties in one declaration
p{border-bottom: medium solid #ff0000}
Some text.
-
8/6/2019 CSS TRaining Material
28/61
CSS (Basic & Advanced) 28 Edit Institute
9. All the left border properties in one declarationp{border-left: medium solid #ff0000}
Some text.
10. All the right border properties in one declarationp{border-right: medium solid #ff0000}
Some text.
11. All the top border properties in one declarationp{border-top: medium solid #ff0000}
Some text.
-
8/6/2019 CSS TRaining Material
29/61
Edit Institute 29 CSS (Basic & Advanced)
12. All the width of the border properties in one declarationp.one{border-style: solid;border-width: 5px}p.two{border-style: solid;border-width: 5px 10px}p.three{border-style: solid;border-width: 5px 10px 1px}p.four
{border-style: solid;border-width: 5px 10px 1px medium}
Some text
Some text
Some text
Some text
Note: The "border-width" property does not work if it is used alone. Use the "border-
style" property to set the borders first.
13. All the border properties in one declarationp{border: medium double rgb(250,0,255)}
Some text
-
8/6/2019 CSS TRaining Material
30/61
CSS (Basic & Advanced) 30 Edit Institute
Margin
1. Set the left margin of a textp.leftmargin {margin-left: 2cm}
This is a paragraph with no margin specified
This is a paragraph with a specified left margin
2. Set the right margin of a text
p.rightmargin {margin-right: 8cm}
This is a paragraph with no margin specified
This is a paragraph with a specified right margin
3. Set the top margin of a text
p.topmargin {margin-top: 5cm}
This is a paragraph with no margin specified
This is a paragraph with a specified top margin
4. Set the bottom margin of a textp.bottommargin {margin-bottom: 2cm}
This is a paragraph with no margin specified
-
8/6/2019 CSS TRaining Material
31/61
Edit Institute 31 CSS (Basic & Advanced)
This is a paragraph with a specified bottom margin
This is a paragraph with no margin specified
5. All the margin properties in one declarationp.margin {margin: 2cm 4cm 3cm 4cm}
This is a paragraph with no specified margins
This is a paragraph with specified margins
This is a paragraph with no specified margins
Padding
1. Set the left padding of a table celltd {padding-left: 2cm}
This is a tablecell with a left padding. This is a tablecell with a lef t padding.
2. Set the right padding of a tablecell
td {padding-right: 5cm}
-
8/6/2019 CSS TRaining Material
32/61
CSS (Basic & Advanced) 32 Edit Institute
This is a tablecell with a right padding. This is a tablecell with a right padding.
3. Set the top padding of a tablecelltd {padding-top: 2cm}
This is a tablecell with a top padding
4. Set the bottom padding of a tablecelltd {padding-bottom: 2cm}
This is a tablecell with a bottom padding
5. All the padding properties in one declarationtd.test1 {padding: 1.5cm}td.test2 {padding: 0.5cm 2.5cm}
-
8/6/2019 CSS TRaining Material
33/61
Edit Institute 33 CSS (Basic & Advanced)
This is a tablecell with equal padding on each side.
This tablecell has a top and bottom padding of 0.5cm and a left and right padding of 2.5cm. -
8/6/2019 CSS TRaining Material
34/61
CSS (Basic & Advanced) 34 Edit Institute
Session 6
CSS List
CSS List
The CSS list properties allow you to place the list-item marker, change between differentlist-item markers, or set an image as the list-item marker.
CSS List Properties
The CSS list properties allow you to place the list-item marker, change between different list-itemmarkers, or set an image as the list-item marker.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Property Description Values IE F N W3C
list-style A shorthand property for
setting all of the propertiesfor a list in one declaration
list-style-type
list-style-positionlist-style-image
4 1 6 1
list-style-image Sets an image as the list-item marker
noneurl
4 1 6 1
list-style-position Sets where the list-itemmarker is placed in the list
insideoutside
4 1 6 1
list-style-type Sets the type of the list-itemmarker
nonedisc
circlesquaredecimaldecimal-leading-zerolower-romanupper-romanlower-alphaupper-alphalower-greeklower-latinupper-latinhebrewarmenian
georgiancjk-ideographichiraganakatakanahiragana-irohakatakana-iroha
4 1 4 1
marker-offset autolength
1 7 2
TM
-
8/6/2019 CSS TRaining Material
35/61
Edit Institute 35 CSS (Basic & Advanced)
Examples
List
1. The different list-item markers in unordered lists
ul.disc {list-style-type: disc}ul.circle {list-style-type: circle}ul.square {list-style-type: square}ul.none {list-style-type: none}
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
2. The different list-item markers in ordered lists
ol.decimal {list-style-type: decimal}ol.lroman {list-style-type: lower-roman}ol.uroman {list-style-type: upper-roman}ol.lalpha {list-style-type: lower-alpha}ol.ualpha {list-style-type: upper-alpha}
-
8/6/2019 CSS TRaining Material
36/61
CSS (Basic & Advanced) 36 Edit Institute
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
CoffeeTeaCoca Cola
3. Set an image as the list-item markerul{list-style-image: url('arrow.gif')}
CoffeeTeaCoca Cola
-
8/6/2019 CSS TRaining Material
37/61
Edit Institute 37 CSS (Basic & Advanced)
4. Place the list-item markerul.inside{list-style-position: inside}
ul.outside{list-style-position: outside}
This list has a list-style-position with a value of "inside":
Earl Grey Tea - A fine black teaJasmine Tea - A fabulous "all purpose" teaHoneybush Tea - A super fruity delight tea
This list has a list-style-position with a value of "outside":
Earl Grey Tea - A fine black teaJasmine Tea - A fabulous "all purpose" teaHoneybush Tea - A super fruity delight tea5. All list properties in one declarationul{list-style: square inside url('arrow.gif')}
CoffeeTeaCoca Cola
-
8/6/2019 CSS TRaining Material
38/61
CSS (Basic & Advanced) 38 Edit Institute
Session 7
CSS Dimension (Advanced)
CSS Dimension
The CSS dimension properties allow you to control the height and width of an element. Italso allows you to increase the space between two lines.
CSS Dimension Properties
The CSS dimension properties allow you to control the height and width of an element. It alsoallows you to increase the space between two lines.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
height Sets the height of anelement
autolength%
4 1 6 1
line-height Sets the distance betweenlines
normalnumber
length%
4 1 4 1
max-height Sets the maximum height ofan element
nonelength%
- 1 6 2
max-width Sets the maximum width ofan element
nonelength%
- 1 6 2
min-height Sets the minimum height ofan element
length%
- 1 6 2
min-width Sets the minimum width ofan element
length%
- 1 6 2
width Sets the width of an element auto%
length
4 1 4 1
Examples
Dimension
1. Increase the space between lines
TM
-
8/6/2019 CSS TRaining Material
39/61
Edit Institute 39 CSS (Basic & Advanced)
p.small {line-height: 0.4cm}p.big {line-height: 0.9cm}
This is a paragraph with a standard line-height.This is a paragraph with a standard line-height.This is a paragraph with a standard line-height.This is a paragraph with a standard line-height.
This is a paragraph with a smaller line-height.This is a paragraph with a smaller line-height.This is a paragraph with a smaller line-height.This is a paragraph with a smaller line-height.
This is a paragraph with a bigger line-height.This is a paragraph with a bigger line-height.This is a paragraph with a bigger line-height.This is a paragraph with a bigger line-height.
-
8/6/2019 CSS TRaining Material
40/61
CSS (Basic & Advanced) 40 Edit Institute
Session 8
CSS Classification / Positioning
CSS Classification
The CSS classification properties allow you to specify how and where to display anelement.
CSS Classification Properties
The CSS classification properties allow you to control how to display an element, set where an
image will appear in another element, position an element relative to its normal position, positionan element using an absolute value, and how to control the visibility of an element.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
clear Sets the sides of an element
where other floatingelements are not allowed
left
rightbothnone
4 1 4 1
cursor Specifies the type of cursorto be displayed
url
autocrosshairdefaultpointer
movee-resizene-resizenw-resizen-resizese-resizesw-resizes-resizew-resizetextwaithelp
4 1 6 2
display Sets how/if an element isdisplayed noneinlineblocklist-itemrun-incompactmarkertableinline-table
4 1 4 1
TM
-
8/6/2019 CSS TRaining Material
41/61
Edit Institute 41 CSS (Basic & Advanced)
table-row-grouptable-header-grouptable-footer-grouptable-rowtable-column-grouptable-column
table-celltable-caption
float Sets where an image or a
text will appear in anotherelement
left
rightnone
4 1 4 1
position Places an element in astatic, relative, absolute orfixed position
staticrelativeabsolutefixed
4 1 4 2
visibility Sets if an element should be
visible or invisible
visible
hiddencollapse
4 1 6 2
CSS Positioning
CSS Positioning
The CSS positioning properties allows you to position an element.
CSS Positioning Properties
The CSS positioning properties allow you to specify the left, right, top, and bottom position of an
element. It also allows you to set the shape of an element, place an element behind another, andto specify what should happen when an element's content is too big to fit in a specified area.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
Property Description Values IE F N W3C
bottom Sets how far the bottomedge of an element isabove/below the bottomedge of the parent element
auto%length
5 1 6 2
clip Sets the shape of anelement. The element isclipped into this shape, anddisplayed
shapeauto
4 1 6 2
left Sets how far the left edge of
an element is to the right/leftof the left edge of the parent
auto%length
4 1 4 2
-
8/6/2019 CSS TRaining Material
42/61
CSS (Basic & Advanced) 42 Edit Institute
element
overflow Sets what happens if the
content of an elementoverflow its area
visible
hiddenscrollauto
4 1 6 2
position Places an element in astatic, relative, absolute orfixed position
staticrelativeabsolutefixed
4 1 4 2
right Sets how far the right edge
of an element is to theleft/right of the right edge ofthe parent element
auto%length
5 1 6 2
top Sets how far the top edge ofan element is above/belowthe top edge of the parentelement
auto%length
4 1 4 2
vertical-align Sets the vertical alignment ofan element
baselinesubsupertoptext-topmiddlebottomtext-bottomlength%
4 1 4 1
z-index Sets the stack order of anelement
autonumber
4 1 6 2
Examples
Classification
1. How to display an element?p {display: inline}div {display: none}
A display property with a value of "inline" results in
no distance between two elements.
And this div section is not displayed!
-
8/6/2019 CSS TRaining Material
43/61
Edit Institute 43 CSS (Basic & Advanced)
2. A simple use of the float propertyimg{float:right}
In the paragraph below, we have added an image with style float:right. The result isthat the image will float to the right in the paragraph.
This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
3. An image with border and margins that floats to the right in a paragraphimg{float:right;border:1px dotted black;margin:0px 0px 15px 20px;}
In the paragraph below, the image will float to the right. A dotted black border is added to theimage.We have also added margins to the image to push the text away from the image:0 px margin on the top and right side, 15 px margin on the bottom, and 20 px margin on the leftside of the image.
-
8/6/2019 CSS TRaining Material
44/61
CSS (Basic & Advanced) 44 Edit Institute
This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
4. An image with a caption that floats to the rightdiv
{float:right;width:120px;margin:0 0 15px 20px;padding:15px;border:1px solid black;text-align:center;}
CSS is fun!This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
In the paragraph above, the div element is 120 pixels wide and it contains the image.The div element will float to the right.Margins are added to the div to push the text away from the div.
-
8/6/2019 CSS TRaining Material
45/61
Edit Institute 45 CSS (Basic & Advanced)
Borders and padding are added to the div to frame in the picture and the caption.
5. Let the first letter of a paragraph float to the leftspan{float:left;width:0.7em;font-size:400%;font-family:algerian,courier;line-height:80%;}
This is some text.This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
In the paragraph above, the first letter of the text is embedded in a span element.The span element has a width that is 0.7 times the size of the current font.The font-size of the span element is 400% (quite large) and the line-height is 80%.The font of the letter in the span will be in "Algerian".
6. Creating a horizontal menu
ul{float:left;width:100%;padding:0;margin:0;list-style-type:none;}a
-
8/6/2019 CSS TRaining Material
46/61
CSS (Basic & Advanced) 46 Edit Institute
{float:left;width:6em;text-decoration:none;color:white;background-color:purple;padding:0.2em 0.6em;border-right:1px solid white;}a:hover {background-color:#ff3300}li {display:inline}
Link oneLink twoLink threeLink four
In the example above, we let the ul element and the a element float to the left.The li elements will be displayed as inline elements (no line break before or after the element).This forces the list to be on one l ine.The ul element has a width of 100% and each hyperlink in the list has a width of 6em (6 times thesize of the current font).We add some colors and borders to make it more fancy.
7. Position an element relative to its normal positionh2.pos_left{position:relative;left:-20px}h2.pos_right{position:relative;
left:20px}
This is a heading in normal positionThis heading is moved left to its normal positionThis heading is moved right to its normal position
Relative positioning moves an element RELATIVE to its original position.
-
8/6/2019 CSS TRaining Material
47/61
Edit Institute 47 CSS (Basic & Advanced)
The style "left:-20px" subtracts 20 pixels from the element's original left position.
The style "left:20px" adds 20 pixels to the element's original left position.
8. Position an element with an absolute valueh2.pos_abs{position:absolute;left:100px;top:150px}
This is a heading with an absolute position
With absolute positioning, an element can be placed anywhere on a page. The heading belowis placed 100px from the left of the page and 150px from the top of the page.
9. How to make an element invisibleh1.visible {visibility:visible}h1.invisible {visibility:hidden}
This is a visible headingThis is an invisible heading
10. Change the cursor
Move the mouse over the words to see the cursor change:
Auto
Crosshair
Default
Pointer -
8/6/2019 CSS TRaining Material
48/61
CSS (Basic & Advanced) 48 Edit Institute
Move
e-resize
ne-resize
nw-resize
n-resize
se-resize
sw-resize
s-resize
w-resize
textwait
helpPositioning
1. Position an element relative to its normal position
h2.pos_left{position:relative;left:-20px}h2.pos_right{position:relative;left:20px}
This is a heading in normal positionThis heading is moved left to its normal positionThis heading is moved right to its normal position
Relative positioning moves an element RELATIVE to its original position.
The style "left:-20px" subtracts 20 pixels from the element's original left position.
The style "left:20px" adds 20 pixels to the element's original left position.
-
8/6/2019 CSS TRaining Material
49/61
Edit Institute 49 CSS (Basic & Advanced)
2. Position an element with an absolute valueh2.pos_abs{position:absolute;left:100px;top:150px}
This is a heading with an absolute position
With absolute positioning, an element can be placed anywhere on a page. The heading belowis placed 100px from the left of the page and 150px from the top of the page.
3. Set the shape of an elementimg{position:absolute;clip:rect(0px 50px 200px 0px)}
The clip property is here cutting an image:
4. What should happen when an element's content is too big to fit in a specified area
div{background-color:#00FFFF;width:150px;height:150px;overflow: scroll}
-
8/6/2019 CSS TRaining Material
50/61
CSS (Basic & Advanced) 50 Edit Institute
The overflow property decides what to do if the content inside an element exceeds the givenwidth and height properties.
You can use the overflow property when you want to have better control of the layout. Try tochange the overflow property to: visible, hidden, auto, or inherit and see what happens. Thedefault value is visible.
5. Vertical alignment of an imageimg.top {vertical-align:text-top}img.bottom {vertical-align:text-bottom}
This is animage inside a paragraph.
This is animage inside a paragraph.
6. Place an element "behind" another elementimg.x{
position:absolute;left:0px;top:0px;z-index:-1}
This is a Heading
-
8/6/2019 CSS TRaining Material
51/61
Edit Institute 51 CSS (Basic & Advanced)
Default z-index is 0. Z-index -1 has lower priority.
7. Place an element "behind" another element 2img.x{position:absolute;left:0px;top:0px;z-index:1}
This is a Heading
Default z-index is 0. Z-index 1 has higher priority.
-
8/6/2019 CSS TRaining Material
52/61
CSS (Basic & Advanced) 52 Edit Institute
Session 9
CSS Pseudo-classes / Elements
CSS Pseudo-classes
CSS pseudo-classes are used to add special effects to some selectors.
Syntax
The syntax of pseudo-classes:
selector:pseudo-class {property: value}
CSS classes can also be used with pseudo-classes:
selector.class:pseudo-class {property: value}
Anchor Pseudo-classes
A link that is active, visited, unvisited, or when you mouse over a link can all be displayed indifferent ways in a CSS-supporting browser:
a:link {color: #FF0000} /* unvisited link */
a:visited {color: #00FF00} /* visited link */
a:hover {color: #FF00FF} /* mouse over link */
a:active {color: #0000FF} /* selected link */
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!!
Note: a:active MUST come after a:hover in the CSS definition in order to be effective!!
Note: Pseudo-class names are not case-sensitive.
Pseudo-classes and CSS Classes
Pseudo-classes can be combined with CSS classes:
a.red:visited {color: #FF0000}
CSS Syntax
If the link in the example above has been visited, it will be displayed in red.
CSS2 - The :first-child Pseudo-class
The :first-child pseudo-class matches a specified element that is the first child of another element.
In this example, the selector matches any p element that is the first child of a div element,
and indents the first paragraph inside a div element:
div > p:first-child
{
text-indent:25px
}
TM
-
8/6/2019 CSS TRaining Material
53/61
Edit Institute 53 CSS (Basic & Advanced)
This selector will match the first paragraph inside the div in the following HTML:
First paragraph in div.
This paragraph will be indented.
Second paragraph in div.
This paragraph will not be indented.
but it will not match the paragraph in this HTML:
Header
The first paragraph inside the div.
This paragraph will not be indented.
In this example, the selector matches any em element that is the first child of a p element,and sets the font-weight to bold for the f irst em inside a p element:
p:first-child em
{
font-weight:bold
}
For example, the em in the HTML below is the first child of the paragraph:
I am a strong man.
In this example, the selector matches any a element that is the first child of any element, andsets the text-decoration to none:
a:first-child
{
text-decoration:none
-
8/6/2019 CSS TRaining Material
54/61
CSS (Basic & Advanced) 54 Edit Institute
}
For example, the first a in the HTML below is the first child of the paragraph and will not beunderlined. But the second a in the paragraph is not the first child of the paragraph and will beunderlined:
Visit W3Schools
and learn CSS!
Visit W3Schools
and learn HTML!
CSS2 - The :lang Pseudo-class
The :lang pseudo-class allows you to define special rules for different languages. In the examplebelow, the :lang class defines the type of quotation marks for q elements with a lang attribute with
a value of "no":
q:lang(no)
{
quotes: "~" "~"
}
Some text A quote in a paragraph
Some text.
Pseudo-classesBrowser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is
defined (CSS1 or CSS2).
Pseudo-class Purpose IE F N W3C
:active Adds special style to an activated element 4 1 8 1
-
8/6/2019 CSS TRaining Material
55/61
Edit Institute 55 CSS (Basic & Advanced)
:focus Adds special style to an element while the elementhas focus
- - - 2
:hover Adds special style to an element when you mouseover it
4 1 7 1
:link Adds special style to an unvisited link 3 1 4 1
:visited Adds special style to a visited link 3 1 4 1
:first-child Adds special style to an element that is the first childof some other element
1 7 2
:lang Allows the author to specify a language to use in aspecified element
1 8 2
CSS Pseudo-Elements
CSS Pseudo-elements
CSS pseudo-elements are used to add special effects to some selectors.
Syntax
The syntax of pseudo-elements:
selector:pseudo-element {property: value}
CSS classes can also be used with pseudo-elements:
selector.class:pseudo-element {property: value}
The :first-line Pseudo-element
The "first-line" pseudo-element is used to add special styles to the first line of the text in aselector:
p {font-size: 12pt}
p:first-line {color: #0000FF; font-variant: small-caps}
Some text that ends up on two or more lines
The output could be something like this:
SOME TEXT THAT ENDSup on two or more lines
In the example above the browser displays the first line formatted according to the "first-line"pseudo element. Where the browser breaks the line depends on the size of the browser window.
Note: The "first-line" pseudo-element can only be used with block-level elements.
Note: The following properties apply to the "first-line" pseudo-element:
font properties
color properties
-
8/6/2019 CSS TRaining Material
56/61
CSS (Basic & Advanced) 56 Edit Institute
background properties
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
clear
The :first-letter Pseudo-element
The "first-letter" pseudo-element is used to add special style to the first letter of the text in aselector:
p {font-size: 12pt}
p:first-letter {font-size: 200%; float: left}
The first words of an article.
The output could be something like this:
___
| he first| words of an
article.
Note: The "first-letter" pseudo-element can only be used with block-level elements.
Note: The following properties apply to the "first-letter" pseudo- element:
font properties
color properties
background properties
margin properties
padding properties
border properties
text-decoration
vertical-align (only if 'float' is 'none')
text-transform
line-height
float
clear
-
8/6/2019 CSS TRaining Material
57/61
Edit Institute 57 CSS (Basic & Advanced)
Pseudo-elements and CSS Classes
Pseudo-elements can be combined with CSS classes:
p.article:first-letter {color: #FF0000}
A paragraph in an article
The example above will make the first letter of all paragraphs with class="article" red.
Multiple Pseudo-elements
Several pseudo-elements can be combined:
p {font-size: 12pt}
p:first-letter {color: #FF0000; font-size: 200%}
p:first-line {color: #0000FF}
The first words of an article
The output could be something like this:___
| he first| words of an
article.
In the example above the first letter of the paragraph will be red with a font size of 24pt. The restof the first line would be blue while the rest of the paragraph would be the default color.
CSS2 - The :before Pseudo-element
The ":before" pseudo-element can be used to insert some content before an element.
The style below will play a sound before each occurrence of a header one element.
h1:before{content: url(beep.wav)}
CSS2 - The :after Pseudo-element
The ":after" pseudo-element can be used to insert some content after an element.
The style below will play a sound after each occurrence of a header one element.
h1:after
{
content: url(beep.wav)}
Pseudo-elements
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property isdefined (CSS1 or CSS2).
-
8/6/2019 CSS TRaining Material
58/61
CSS (Basic & Advanced) 58 Edit Institute
Pseudo-element Purpose IE F N W3C
:first-letter Adds special style to the first letter of a text 5 1 8 1
:first-line Adds special style to the first line of a text 5 1 8 1
:before Inserts some content before an element 1.5 8 2:after Inserts some content after an element 1.5 8 2
Examples
-
8/6/2019 CSS TRaining Material
59/61
Edit Institute 59 CSS (Basic & Advanced)
Session 10
CSS Media Types / Summary
CSS2 Media Types
Media Types allow you to specify how documents will be presented in different media. The
document can be displayed differently on the screen, on the paper, with an aural browser,etc.
Media Types
Some CSS properties are only designed for a certain media. For example the "voice-family"
property is designed for aural user agents. Some other properties can be used for different mediatypes. For example, the "font-size" property can be used for both screen and print media, butperhaps with different values. A document usually needs a larger font-size on a screen than onpaper, and sans-serif fonts are easier to read on the screen, while serif fonts are easier to readon paper.
The @media Rule
The @media rule allows different style rules for different media in the same style sheet.
The style in the example below tells the browser to display a 14 pixels Verdana font on thescreen. But if the page is printed, it will be in a 10 pixels Times font. Notice that the font-weight isset to bold, both on screen and on paper:
@media screen{
p.test {font-family:verdana,sans-serif; font-size:14px}
}
@media print
{
p.test {font-family:times,serif; font-size:10px}
}
@media screen,print
{
p.test {font-weight:bold}
}
TM
-
8/6/2019 CSS TRaining Material
60/61
CSS (Basic & Advanced) 60 Edit Institute
....
See it yourself ! If you are using Mozilla/Firefox or IE 5+ and print this page, you will see that the
paragraph under "Media Types" will be displayed in another font, and have a smaller font sizethan the rest of the text.
Different Media Types
Note: The media type names are not case-sensitive.
Media Type Description
All Used for all media type devices
Aural Used for speech and sound synthesizers
Braille Used for braille tactile feedback devices
embossed Used for paged braille printers
handheld Used for small or handheld devices
Print Used for printers
projection Used for projected presentations, like slides
Screen Used for computer screens
Tty Used for media using a fixed-pitch character grid, like teletypes and terminals
Tv Used for television-type devices
CSS Summary
You Have Learned CSS, Now What?
CSS Summary
This tutorial has taught you how to create style sheets to control the style and layout of multipleweb sites at once.
You have learned how to use CSS to add backgrounds, format text, add and format borders, andspecify padding and margins of elements.
You have also learned how to position an element, control the visibility and size of an element,set the shape of an element, place an element behind another, and to add special effects to someselectors, like links.
For more information on CSS, please take a look at our CSS examples and our CSS reference.
-
8/6/2019 CSS TRaining Material
61/61
Now You Know CSS, What's Next?
The next step is to learn XHTML and JavaScript.
XHTML
XHTML is the "new" HTML. The latest HTML recommendation is HTML 4.01. This is the last and
final HTML version.
HTML will be replaced by XHTML, which is a stricter and cleaner version of HTML.
If you want to learn more about XHTML, please visit our XHTML tutorial.
JavaScript
JavaScript can make your web site more dynamic.
A static web site is nice when you just want to show flat content, but a dynamic web site can reactto events and allow user interaction.
JavaScript is the most popular scripting language on the internet and it works with all majorbrowsers.