SlideShare a Scribd company logo
CSS Basics
Style and format your web site using CSS
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.
 Elements are declared with the element (HTML) tag; styles for the
element are wrapped with curly brackets:
h1 { }
 IDs are declared with a pound sign and the ID name; styles for the ID are
wrapped with curly brackets:
#title { }
 Classes are declared with a period and the class name; styles for the class
are wrapped with curly brackets:
.bodytext { }
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:
<p style=“font-size: 14px;”>Lorem ipsum…</p>
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 only want the styles
from one class to apply
to this paragraph.
We’re adding a class and an ID
to this paragraph; we want the
styles from both to be applied
to it.
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).
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).
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.
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.
We also provide classroom and online training classes
For More Details
www.asit.amcsquare.com
Wise Machines India Pvt Ltd
#360, Sri Sai Padma Arcade,
Varthur Main Road,
Ramagondanahalli,
Whitefiled ,Bangalore – 560066.
We also having Branches in Hyderabad & Chennai

More Related Content

PPTX
Internet tech &amp; web prog. p4,5
PPT
Introduction to CSS
PPT
CSS: How To Learn Easily
PDF
Intro to css & sass
PPTX
CSS introduction
PPT
CSS 101
PPSX
Introduction to css
PPTX
Introduction to CSS
Internet tech &amp; web prog. p4,5
Introduction to CSS
CSS: How To Learn Easily
Intro to css & sass
CSS introduction
CSS 101
Introduction to css
Introduction to CSS

What's hot (19)

PPTX
1 03 - CSS Introduction
PPTX
Complete Lecture on Css presentation
PPT
Cascading Style Sheets (CSS) help
PPTX
Responsive web design with html5 and css3
PDF
Introduction to css
PPTX
Cascading style sheets - CSS
PPTX
Cascading style sheet an introduction
PPTX
Css ppt
PPTX
Cascading Style Sheet (CSS)
PPTX
Journey To The Front End World - Part2 - The Cosmetic
PDF
The Dark Arts of CSS
PPT
CSS
KEY
Intro to SASS CSS
PPT
Cascading Style Sheets
PPT
CSS Part I
PPTX
1 03 - CSS Introduction
Complete Lecture on Css presentation
Cascading Style Sheets (CSS) help
Responsive web design with html5 and css3
Introduction to css
Cascading style sheets - CSS
Cascading style sheet an introduction
Css ppt
Cascading Style Sheet (CSS)
Journey To The Front End World - Part2 - The Cosmetic
The Dark Arts of CSS
CSS
Intro to SASS CSS
Cascading Style Sheets
CSS Part I
Ad

Similar to Css basics (20)

PPTX
David Weliver
PDF
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
PPTX
Web technologies-course 03.pptx
PPT
Basic css
PPTX
Cascading Style Sheets for web browser.pptx
PPTX
Module 2 CSS . cascading style sheet and its uses
PPTX
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx
PPT
Unit 2-CSS & Bootstrap.ppt
PPTX
uptu web technology unit 2 Css
PDF
Intro to HTML and CSS - Class 2 Slides
KEY
Web Design, Lesson Plan: Classes and IDs
PPTX
Lecture 3CSS part 1.pptx
PPT
PDF
8--CSS-Classes-and-IDs.pdf for second to college
PPTX
CSS Presentation Notes.pptx
PPT
Learning CSS for beginners.ppt all that are but
PPT
PPT
CSS Training in Bangalore
David Weliver
CSS INTRODUCTION SLIDES WITH HTML CODE.pdf
Web technologies-course 03.pptx
Basic css
Cascading Style Sheets for web browser.pptx
Module 2 CSS . cascading style sheet and its uses
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx
Unit 2-CSS & Bootstrap.ppt
uptu web technology unit 2 Css
Intro to HTML and CSS - Class 2 Slides
Web Design, Lesson Plan: Classes and IDs
Lecture 3CSS part 1.pptx
8--CSS-Classes-and-IDs.pdf for second to college
CSS Presentation Notes.pptx
Learning CSS for beginners.ppt all that are but
CSS Training in Bangalore
Ad

More from ASIT (20)

PPTX
Asit education student review
PPTX
ASIT EDUCATION STUDENT REVIEWS
PPTX
Asit Education
PPTX
Asit Education Student Reviews
PPTX
Asit education Student review
PPTX
ASIT EDUCATION REVIEW
PPTX
Asit Never Cheats Unemployes
PPTX
Latest News on Amc Square Asit
PPTX
Asit amc never cheats students
PPTX
News on AMC Square ASIT
PPTX
News on Asit Amc
PPTX
Time Management
PPTX
learn Ruby at ASIT
PPTX
introduction to Mongodb
PPTX
introduction to hadoop
PPTX
ASIT REVIEWS
PPTX
ASIT REVIEWS
PPTX
Learn REST API at ASIT
PPTX
Learn C LANGUAGE at ASIT
PPTX
Learn Advanced JAVA at ASIT
Asit education student review
ASIT EDUCATION STUDENT REVIEWS
Asit Education
Asit Education Student Reviews
Asit education Student review
ASIT EDUCATION REVIEW
Asit Never Cheats Unemployes
Latest News on Amc Square Asit
Asit amc never cheats students
News on AMC Square ASIT
News on Asit Amc
Time Management
learn Ruby at ASIT
introduction to Mongodb
introduction to hadoop
ASIT REVIEWS
ASIT REVIEWS
Learn REST API at ASIT
Learn C LANGUAGE at ASIT
Learn Advanced JAVA at ASIT

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
master seminar digital applications in india
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Classroom Observation Tools for Teachers
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pharma ospi slides which help in ospi learning
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
master seminar digital applications in india
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
O5-L3 Freight Transport Ops (International) V1.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
TR - Agricultural Crops Production NC III.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Week 4 Term 3 Study Techniques revisited.pptx
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Final Presentation General Medicine 03-08-2024.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table

Css basics

  • 1. CSS Basics Style and format your web site using CSS
  • 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.  Elements are declared with the element (HTML) tag; styles for the element are wrapped with curly brackets: h1 { }  IDs are declared with a pound sign and the ID name; styles for the ID are wrapped with curly brackets: #title { }  Classes are declared with a period and the class name; styles for the class are wrapped with curly brackets: .bodytext { }
  • 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: <p style=“font-size: 14px;”>Lorem ipsum…</p>
  • 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 only want the styles from one class to apply to this paragraph. We’re adding a class and an ID to this paragraph; we want the styles from both to be applied to it.
  • 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. 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).
  • 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. 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.
  • 21. We also provide classroom and online training classes For More Details www.asit.amcsquare.com Wise Machines India Pvt Ltd #360, Sri Sai Padma Arcade, Varthur Main Road, Ramagondanahalli, Whitefiled ,Bangalore – 560066. We also having Branches in Hyderabad & Chennai