1 What is CSS? What is CSS? CSS stands for Cascading Style Sheets CSS stands for Cascading Style Sheets Styles define how to display HTML Styles define how to display HTML elements elements Styles are normally stored in Style Styles are normally stored in Style Sheets Sheets Styles were added to HTML 4.0 to solve a Styles were added to HTML 4.0 to solve a problem problem External Style Sheets can save you a lot External Style Sheets can save you a lot of work of work External Style Sheets are stored in CSS External Style Sheets are stored in CSS files files
24
Embed
1 What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles are normally stored in Style Sheets Styles.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
What is CSS?What is CSS?
CSS stands for Cascading Style Sheets CSS stands for Cascading Style Sheets
Styles define how to display HTML elements Styles define how to display HTML elements
Styles are normally stored in Style Sheets Styles are normally stored in Style Sheets
Styles were added to HTML 4.0 to solve a problem Styles were added to HTML 4.0 to solve a problem
External Style Sheets can save you a lot of work External Style Sheets can save you a lot of work
External Style Sheets are stored in CSS filesExternal Style Sheets are stored in CSS files
Multiple style definitions will cascade into oneMultiple style definitions will cascade into one
With CSS, your HTML document can be displayed With CSS, your HTML document can be displayed
using different output stylesusing different output styles
2
Advantages of CSS?
With CSS, you will be able to:
- define the look of your pages in one place rather than repeating yourself over and over again throughout your site. (Ever get tired of defining colors and fonts each time you start a new cell in a table? Those days are over with CSS!)
- easily change the look of your pages even after they're created. Since the styles are defined in one place you can change the look of the entire site at once. (Ever get tired of replacing tags throughout your site when you want to change the look of a certain element? Those days are over with CSS!)
3
- - define font sizes and similar attributesdefine font sizes and similar attributes
with the same accuracy as you have with a word with the same accuracy as you have with a word
processor - not being limited to just the seven different processor - not being limited to just the seven different
font sizes defined in HTML.font sizes defined in HTML.
- - position the contentposition the content of your pages with pixel of your pages with pixel
precision.precision.
- - redefine entire HTML tagsredefine entire HTML tags. Say for example, if you . Say for example, if you
wanted the bold tag to be red using a special font - this wanted the bold tag to be red using a special font - this
can be done easily with CSScan be done easily with CSS
4
- - define customized styles for linksdefine customized styles for links - such as getting rid of - such as getting rid of the underline.the underline.
- - define layersdefine layers that can be positioned on top of each other that can be positioned on top of each other (often used for menus that pop up).(often used for menus that pop up).
5
Disadvantages of CSS?
- these will only work on version 4 browsers or these will only work on version 4 browsers or newernewer. However, more than 95% of all browsers live up . However, more than 95% of all browsers live up to that.to that.
6
Cascading orderCascading order
Style will “cascade” into a new “virtual” style sheet by the Style will “cascade” into a new “virtual” style sheet by the
following rules, where number 4 has the highest priorityfollowing rules, where number 4 has the highest priority
1.1. Browser defaultBrowser default
2.2. External Style SheetExternal Style Sheet
3.3. Internal Style Sheet (inside the <head> tag)Internal Style Sheet (inside the <head> tag)
4.4. Inline Style (inside HTML element)Inline Style (inside HTML element)
So, an inline style has the highest priority, which mean that it So, an inline style has the highest priority, which mean that it
will override every style declared inside the <head> tag, in an will override every style declared inside the <head> tag, in an
external style sheet, and in a browser (a default value)external style sheet, and in a browser (a default value)
7
CSS syntaxCSS syntax
•The syntax is made up of three parts: The syntax is made up of three parts: •a selectora selector
normally the element/tag you wish to definenormally the element/tag you wish to define•a propertya property
the attribute you wish to changethe attribute you wish to change•a valuea value
each property can take a valueeach property can take a value
•The property and value are separated by a colon and The property and value are separated by a colon and
surrounded by curly bracessurrounded by curly braces
selector { property : value }
body { color : black }
8
CSS syntaxCSS syntax
•If the value is multiple words, put quotes around the valueIf the value is multiple words, put quotes around the value
•If you wish to specify more than one property, you should If you wish to specify more than one property, you should
separate each property with semi-colon.separate each property with semi-colon.•The example below shows how to define a center aligned The example below shows how to define a center aligned
paragraph, with a red text colorparagraph, with a red text color
p { font-family : “sans serif” }
p { text-align : center ; color : red }
9
GroupingGrouping
•You can group selectorsYou can group selectors•Each selector need to be separate with a commaEach selector need to be separate with a comma•The example below have grouped all the header elements. The example below have grouped all the header elements.
Each header element will be greenEach header element will be green
h1, h2, h3, h4, h5, h6 { color: green }
10
The class attributeThe class attribute
•With the class attribute you can define different styles for With the class attribute you can define different styles for
the same elementthe same element•Example below show how to set a 2 types of different Example below show how to set a 2 types of different
p.center {text-align: center}p.center {text-align: center}•You have to use the class attribute in your HTML documentYou have to use the class attribute in your HTML document
<p class=“right”> This paragraph will <p class=“right”> This paragraph will
be right-aligned </p>be right-aligned </p>
<p class=“center”> This paragraph will <p class=“center”> This paragraph will
be center-aligned </p>be center-aligned </p>
11
The class attributeThe class attribute
•You can also omit the tag name in the selector to define a You can also omit the tag name in the selector to define a
style that can be used by many elementsstyle that can be used by many elements•egeg. . .center {text-align: center}.center {text-align: center}
•To use the style we can look at the example belowTo use the style we can look at the example below
<h1 class=“center”><h1 class=“center”>
This heading will be center-aligned This heading will be center-aligned
</h1></h1>
<p class=“center”><p class=“center”>
This paragraph will also be center-This paragraph will also be center-
aligned </p>aligned </p>
12
CSS commentsCSS comments
You can insert comments in CSS to explain your code, You can insert comments in CSS to explain your code,
which can help you when you edit the source code at a which can help you when you edit the source code at a
later datelater date
A comment will be ignored by the browserA comment will be ignored by the browser
CSS comment begin with /* and end with */CSS comment begin with /* and end with */
egeg /* This is a comment *//* This is a comment */
13
How to insert a Style SheetHow to insert a Style Sheet
There are 3 ways of inserting a style sheetThere are 3 ways of inserting a style sheet
External Style SheetExternal Style Sheet
Internal Style SheetInternal Style Sheet
Inline Style SheetInline Style Sheet
14
External Style SheetExternal Style Sheet
An external style sheet is ideal when the style is applied to An external style sheet is ideal when the style is applied to
many pagesmany pages
With an external style sheet, you can change the look of an With an external style sheet, you can change the look of an
entire web site by changing one fileentire web site by changing one file
Each page must link to the style sheet using the <link> tagEach page must link to the style sheet using the <link> tag
The <link> tag goes inside the head sectionThe <link> tag goes inside the head section