SlideShare a Scribd company logo
CSS Basics
Style and format your web site using CSS
Shabab Shihan
What is CSS?
 CSS (Cascading Style Sheets) allows us to apply
formatting and styling to the HTML that builds our web
pages.
 CSS can control many elements of our web pages: colors,
fonts, alignment, borders, backgrounds, spacing, margins,
and much more.
How does CSS work?
 CSS works in conjunction with HTML.
 An HTML file (or multiple files) links to a CSS file (or multiple
CSS files) and when the web browser displays the page, it
references the CSS file(s) to determine how to display the
content.
 HTML elements are marked with “IDs” and “classes,” which
are defined in the CSS file – this is how the browser knows
which styles belong where. Each element type (<h1>, <img>,
<p>, <li>, etc.) can also be styled with CSS.
 IDs and classes are defined by the person writing the code – there
are no default IDs and classes.
What is the difference between ID and
class?
 IDs and classes function the same way – they can both
provide the same styling functionality to an HTML
element, however…
 IDs are unique; each element can only have one ID, and that
ID can only be on the page once.
 Classes are not unique; an element can have multiple classes,
and multiple elements can have the same class.
 What does that mean?
 IDs can be used to style elements that are different from
anything else on the page.
 Classes can be used to style multiple elements on a single page
that have things in common, like font size, color, or style.
What does a CSS file look like?
 The styles for each element, ID, or class used on an
HTML page are defined in a CSS document.
#title { }
 Classes are declared with a period and the class name; styles for the class
are wrapped with curly brackets:
.bodytext { }
 IDs are declared with a pound sign and the ID name; styles for the ID are
wrapped with curly brackets:
 Elements are declared with the element (HTML) tag; styles for the
element are wrapped with curly brackets:
h1 { }
What does a CSS file look like?
 Within each CSS element, styles are added that apply to
that particular element/ID/class:
h1 {
color: green;
}
 This style would apply to anything within HTML <h1></h1>
tags; the text inside the tags would be green.
Adding CSS to HTML
 CSS must be used in conjunction with HTML to be
effective. CSS files can be linked to HTML documents
with a bit of code in the <head></head> tags of an HTML
file:
<link rel="stylesheet" type="text/css" href=“myfile.css" />
 CSS can also be written “in line,” within HTML code, but
it’s preferable to include an external style sheet:
Let’s write some CSS!
 We’ll work in a web-based editing tool, but CSS can
easily be written in text editing software like
Notepad.
Go to http://dabblet.com/gist/9103656
 *This tool references our CSS automatically, so in this case, we don’t need to
link our CSS file like we normally would.
Adding IDs and Classes to HTML
 First, we need to add our IDs and classes to the HTML:
<h1>Wolverine</h1>
<img
src=http://www.uvu.edu/web/images/wolverine.jpg
class=“bordered” />
This class won’t do
anything yet. We’ll
define its associated
styles in our CSS file.
Adding IDs and Classes to HTML
<p id="introduction" class="emphasis">The
wolverine, also referred to as glutton, carcajou,
skunk bear, or quickhatch…
<p class="emphasis">The adult wolverine is
about the size of a medium dog, with a length
usually ranging from…
…
We’re adding a class and an ID
to this paragraph; we want the
styles from both to be applied
to it.We only want the styles
from one class to apply
to this paragraph.
Defining Elements in CSS
 We’ve added IDs and classes to our HTML file, but we
need to define what those IDs and classes will do.
 How will each class or ID change the appearance of that
HTML element?
 This is where CSS comes in!
 By defining the styles that go with each attribute/class/ID, we
have complete control over the look of our content.
Writing CSS
 Let’s create a new CSS document in Notepad.
 We’ll begin by defining the “bordered” class that is
applied to one of the images.
 CSS uses . to identify classes, and # to identify IDs. Because
our HTML indicates class=“bordered” we need to use the
matching identifier in our CSS document.
.bordered { }
All the styles inside these brackets will be applied to any
elements in our HTML file that include class=“bordered”.
Writing CSS
 First, let’s add a simple style to .bordered:
.bordered {
width: 300px;
}
Each style ends with a
semicolon.
 Now, any HTML element that includes class=“border” will be
300 pixels wide.
Writing CSS
 Let’s add a border to that image that has class=“bordered”.
 The “border” style requires some additional attributes.
.bordered {
width: 300px;
border: 3px solid
#000000;
}
Tells the browser “I
want a border around
this element.”
The border
should be 3
pixels wide.
The border
should be solid.
(Other possible
values include
dotted and dashed.)
The border should
be black (defined
by hexadecimal
color code).
Using Colors in CSS
 Though there are standard color names that are supported by
all browsers (i.e. green, red, yellow, etc.), colors are often
declared in CSS using hexadecimal color codes.
 How can I find the hex color code?
Color picker tool in Photoshop/image
editing software.
Online tools:
http://www.w3schools.com/tags/ref_colorpicker.asp
Official UVU web colors:
http://www.uvu.edu/web/standards/
Writing CSS
 We want the image to be on the right side of the page,
so we need to add a “float” to the class styles:
.bordered {
width: 300px;
border: 1px solid #000;
float: right;
}
We could also align the element
to the left side of the page using
“float: left;”.
Writing CSS
 Next, let’s write some styles to apply to our paragraphs.
First, we’ll create styles for the ID called “introduction.”
 We want this paragraph to stand out from the rest, so
we’ll make the font size bigger and change the color.
#introduction {
font-size: 20px;
color: #4d7123;
}
Writing CSS
 We want a few paragraphs to have some additional
emphasis, so let’s write an additional class for those
styles:
.emphasis {
font-style: italic;
font-weight: bold;
}
Other font-style options
include “underline,” and
“normal.”
Other font-weight options
include “normal,” “lighter,” or
numerical values.
Writing CSS
 We can also apply CSS styles to HTML elements without
using classes and IDs. These will apply to any HTML
element of that type, unless they are overwritten by
classes or IDs.
h1 {
font-family: “Arial”, sans-serif;
}
Any <h1> tag on the page will
be in Arial unless the <h1>
has a class that overwrites it.
Using Fonts in CSS
 Because every computer has a different set of fonts installed
by default, we can’t know for sure if our visitors will have a
certain font on their computer.
 If we design our site using a certain font, and a visitor doesn’t have
that font installed, our site will not look as we intended it to.
 Luckily, there is a set of “web safe” fonts that most computers
have. Choosing from these fonts will make our site look
(almost) the same on any computer.
 Web safe fonts include: Times New Roman, Georgia, Arial,
Tahoma, Verdana. More info:
http://www.w3schools.com/cssref/css_websafe_fonts.asp
 In CSS, the font-family style often includes a list of a few fonts, so
that there is a “fallback” option in case the font we specify first isn’t
available.
Writing CSS
 We may want the same styles to apply to more than one
element in our site. Combining our styles can help us do
this so that we don’t have to duplicate our CSS code:
h1, h2 {
font-family: “Arial”, sans-serif;
}
Adding additional, comma-
separated elements, classes, or
IDs allows the same styles to be
used in more than one place.
More about CSS
 The possibilities with CSS are endless…this is just
scratching the surface
 CSS can: add rollover effects to text and images, change
background colors and images, create very intricate page
layouts and designs, change element opacity, create gradient
colors, control page layout in adaptive/responsive design (new
uvu.edu mobile-friendly design), show and hide content,
create animations, and much more!
 A nice CSS “cheat sheet” is available at
http://www.w3schools.com/cssref/
 Find more CSS tutorials at
http://www.uvu.edu/web/training/basics.html
Skype: shabab.shihan1
Twitter: http://bit.ly/1HkfemT
Facebook: http://on.fb.me/1N3DhbN
Linkedin: http://bit.ly/1RGnZNF
Portfolio site: www.shababshihan.com
For hire me create your website: http://bit.ly/1GTFk5b
Ad

More Related Content

What's hot (20)

Css3
Css3Css3
Css3
Rahma Boufalgha
 
Css.html
Css.htmlCss.html
Css.html
Anaghabalakrishnan
 
Css ppt
Css pptCss ppt
Css ppt
Nidhi mishra
 
Css
CssCss
Css
shanmuga rajan
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
Singsys Pte Ltd
 
CSS 101
CSS 101CSS 101
CSS 101
dunclair
 
Intro to css & sass
Intro to css & sassIntro to css & sass
Intro to css & sass
Sean Wolfe
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style Sheets
St. Petersburg College
 
Responsive web design with html5 and css3
Responsive web design with html5 and css3Responsive web design with html5 and css3
Responsive web design with html5 and css3
Divya Tiwari
 
CSS
CSS CSS
CSS
Sunil OS
 
The Dark Arts of CSS
The Dark Arts of CSSThe Dark Arts of CSS
The Dark Arts of CSS
SiddharthBorderwala
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
casestudyhelp
 
Css
CssCss
Css
Balakumaran Arunachalam
 
Css3
Css3Css3
Css3
Deepak Mangal
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
Michael Jhon
 
Basic css
Basic cssBasic css
Basic css
Gopinath Ambothi
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
Denise Jacobs
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Erin M. Kidwell
 
Html
HtmlHtml
Html
Kamal Acharya
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
apnwebdev
 

Similar to CSS: How To Learn Easily (20)

Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
 
Css
CssCss
Css
Jahid Blackrose
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
Shawn Calvert
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
Doncho Minkov
 
Web Typography
Web TypographyWeb Typography
Web Typography
Shawn Calvert
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
Shawn Calvert
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
VarunMM2
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
VarunMM2
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
QA TrainingHub
 
Cordova training - Day 2 Introduction to CSS 3
Cordova training - Day 2 Introduction to CSS 3Cordova training - Day 2 Introduction to CSS 3
Cordova training - Day 2 Introduction to CSS 3
Binu Paul
 
Css
CssCss
Css
NIRMAL FELIX
 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
jackchenvlo
 
CSS Presentation Notes.pptx
CSS Presentation Notes.pptxCSS Presentation Notes.pptx
CSS Presentation Notes.pptx
VineetaSingh713208
 
Css Founder.com | Cssfounder org
Css Founder.com | Cssfounder orgCss Founder.com | Cssfounder org
Css Founder.com | Cssfounder org
Css Founder
 
Css jon duckett - flashcards
Css   jon duckett - flashcardsCss   jon duckett - flashcards
Css jon duckett - flashcards
Chirag Aggarwal
 
Css
CssCss
Css
actacademy
 
Css
CssCss
Css
actacademy
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
Css notes
Css notesCss notes
Css notes
Computer Hardware & Trouble shooting
 
Cascstylesheets
CascstylesheetsCascstylesheets
Cascstylesheets
Digital Insights - Digital Marketing Agency
 
Ad

Recently uploaded (20)

Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
TrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI PaymentsTrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI Payments
Trs Labs
 
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Raffi Khatchadourian
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Raffi Khatchadourian
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
TrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI PaymentsTrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI Payments
Trs Labs
 
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Raffi Khatchadourian
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Raffi Khatchadourian
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Ad

CSS: How To Learn Easily

  • 1. CSS Basics Style and format your web site using CSS Shabab Shihan
  • 2. What is CSS?  CSS (Cascading Style Sheets) allows us to apply formatting and styling to the HTML that builds our web pages.  CSS can control many elements of our web pages: colors, fonts, alignment, borders, backgrounds, spacing, margins, and much more.
  • 3. How does CSS work?  CSS works in conjunction with HTML.  An HTML file (or multiple files) links to a CSS file (or multiple CSS files) and when the web browser displays the page, it references the CSS file(s) to determine how to display the content.  HTML elements are marked with “IDs” and “classes,” which are defined in the CSS file – this is how the browser knows which styles belong where. Each element type (<h1>, <img>, <p>, <li>, etc.) can also be styled with CSS.  IDs and classes are defined by the person writing the code – there are no default IDs and classes.
  • 4. What is the difference between ID and class?  IDs and classes function the same way – they can both provide the same styling functionality to an HTML element, however…  IDs are unique; each element can only have one ID, and that ID can only be on the page once.  Classes are not unique; an element can have multiple classes, and multiple elements can have the same class.  What does that mean?  IDs can be used to style elements that are different from anything else on the page.  Classes can be used to style multiple elements on a single page that have things in common, like font size, color, or style.
  • 5. What does a CSS file look like?  The styles for each element, ID, or class used on an HTML page are defined in a CSS document. #title { }  Classes are declared with a period and the class name; styles for the class are wrapped with curly brackets: .bodytext { }  IDs are declared with a pound sign and the ID name; styles for the ID are wrapped with curly brackets:  Elements are declared with the element (HTML) tag; styles for the element are wrapped with curly brackets: h1 { }
  • 6. What does a CSS file look like?  Within each CSS element, styles are added that apply to that particular element/ID/class: h1 { color: green; }  This style would apply to anything within HTML <h1></h1> tags; the text inside the tags would be green.
  • 7. Adding CSS to HTML  CSS must be used in conjunction with HTML to be effective. CSS files can be linked to HTML documents with a bit of code in the <head></head> tags of an HTML file: <link rel="stylesheet" type="text/css" href=“myfile.css" />  CSS can also be written “in line,” within HTML code, but it’s preferable to include an external style sheet:
  • 8. Let’s write some CSS!  We’ll work in a web-based editing tool, but CSS can easily be written in text editing software like Notepad. Go to http://dabblet.com/gist/9103656  *This tool references our CSS automatically, so in this case, we don’t need to link our CSS file like we normally would.
  • 9. Adding IDs and Classes to HTML  First, we need to add our IDs and classes to the HTML: <h1>Wolverine</h1> <img src=http://www.uvu.edu/web/images/wolverine.jpg class=“bordered” /> This class won’t do anything yet. We’ll define its associated styles in our CSS file.
  • 10. Adding IDs and Classes to HTML <p id="introduction" class="emphasis">The wolverine, also referred to as glutton, carcajou, skunk bear, or quickhatch… <p class="emphasis">The adult wolverine is about the size of a medium dog, with a length usually ranging from… … We’re adding a class and an ID to this paragraph; we want the styles from both to be applied to it.We only want the styles from one class to apply to this paragraph.
  • 11. Defining Elements in CSS  We’ve added IDs and classes to our HTML file, but we need to define what those IDs and classes will do.  How will each class or ID change the appearance of that HTML element?  This is where CSS comes in!  By defining the styles that go with each attribute/class/ID, we have complete control over the look of our content.
  • 12. Writing CSS  Let’s create a new CSS document in Notepad.  We’ll begin by defining the “bordered” class that is applied to one of the images.  CSS uses . to identify classes, and # to identify IDs. Because our HTML indicates class=“bordered” we need to use the matching identifier in our CSS document. .bordered { } All the styles inside these brackets will be applied to any elements in our HTML file that include class=“bordered”.
  • 13. Writing CSS  First, let’s add a simple style to .bordered: .bordered { width: 300px; } Each style ends with a semicolon.  Now, any HTML element that includes class=“border” will be 300 pixels wide.
  • 14. Writing CSS  Let’s add a border to that image that has class=“bordered”.  The “border” style requires some additional attributes. .bordered { width: 300px; border: 3px solid #000000; } Tells the browser “I want a border around this element.” The border should be 3 pixels wide. The border should be solid. (Other possible values include dotted and dashed.) The border should be black (defined by hexadecimal color code).
  • 15. Using Colors in CSS  Though there are standard color names that are supported by all browsers (i.e. green, red, yellow, etc.), colors are often declared in CSS using hexadecimal color codes.  How can I find the hex color code? Color picker tool in Photoshop/image editing software. Online tools: http://www.w3schools.com/tags/ref_colorpicker.asp Official UVU web colors: http://www.uvu.edu/web/standards/
  • 16. Writing CSS  We want the image to be on the right side of the page, so we need to add a “float” to the class styles: .bordered { width: 300px; border: 1px solid #000; float: right; } We could also align the element to the left side of the page using “float: left;”.
  • 17. Writing CSS  Next, let’s write some styles to apply to our paragraphs. First, we’ll create styles for the ID called “introduction.”  We want this paragraph to stand out from the rest, so we’ll make the font size bigger and change the color. #introduction { font-size: 20px; color: #4d7123; }
  • 18. Writing CSS  We want a few paragraphs to have some additional emphasis, so let’s write an additional class for those styles: .emphasis { font-style: italic; font-weight: bold; } Other font-style options include “underline,” and “normal.” Other font-weight options include “normal,” “lighter,” or numerical values.
  • 19. Writing CSS  We can also apply CSS styles to HTML elements without using classes and IDs. These will apply to any HTML element of that type, unless they are overwritten by classes or IDs. h1 { font-family: “Arial”, sans-serif; } Any <h1> tag on the page will be in Arial unless the <h1> has a class that overwrites it.
  • 20. Using Fonts in CSS  Because every computer has a different set of fonts installed by default, we can’t know for sure if our visitors will have a certain font on their computer.  If we design our site using a certain font, and a visitor doesn’t have that font installed, our site will not look as we intended it to.  Luckily, there is a set of “web safe” fonts that most computers have. Choosing from these fonts will make our site look (almost) the same on any computer.  Web safe fonts include: Times New Roman, Georgia, Arial, Tahoma, Verdana. More info: http://www.w3schools.com/cssref/css_websafe_fonts.asp  In CSS, the font-family style often includes a list of a few fonts, so that there is a “fallback” option in case the font we specify first isn’t available.
  • 21. Writing CSS  We may want the same styles to apply to more than one element in our site. Combining our styles can help us do this so that we don’t have to duplicate our CSS code: h1, h2 { font-family: “Arial”, sans-serif; } Adding additional, comma- separated elements, classes, or IDs allows the same styles to be used in more than one place.
  • 22. More about CSS  The possibilities with CSS are endless…this is just scratching the surface  CSS can: add rollover effects to text and images, change background colors and images, create very intricate page layouts and designs, change element opacity, create gradient colors, control page layout in adaptive/responsive design (new uvu.edu mobile-friendly design), show and hide content, create animations, and much more!  A nice CSS “cheat sheet” is available at http://www.w3schools.com/cssref/  Find more CSS tutorials at http://www.uvu.edu/web/training/basics.html
  • 23. Skype: shabab.shihan1 Twitter: http://bit.ly/1HkfemT Facebook: http://on.fb.me/1N3DhbN Linkedin: http://bit.ly/1RGnZNF Portfolio site: www.shababshihan.com For hire me create your website: http://bit.ly/1GTFk5b