Movatterモバイル変換


[0]ホーム

URL:


Shawn  Calvert, profile picture
Uploaded byShawn Calvert
2,124 views

CSS Foundations, pt 1

The document provides an overview of CSS foundations including the three layers of web design, what CSS is, CSS syntax, selectors, applying styles, and the cascade. It discusses the structure, style, and behavior layers and how CSS is used to control presentation. Key points covered include the different ways to add CSS rules, CSS selectors like type, ID, class, and descendant selectors, and how specificity and inheritance apply styles. It also reviews CSS properties for styling text, lists, and links.

Embed presentation

Downloaded 68 times
CSS Foundations, pt 122-3375 Web Design I // Columbia College Chicago
For Starters!!Post assignment and blog postReview student blog postsInstructor review of Assign 3HTML refresher exercise!!
Skills learned so far
how to create a web directory and link between filesCode a basic webpage from scratchhow to mark up different types of content with appropriate HTML tagshow to use basic HTML attributes to create links and web imageshow to set up a site domain, server host and install a wordpress site
Three layers of web design:
Structure, Style, Behavior
Three layers of web design
Three layers of web design
Three layers of web design
BEHAVIORJavascriptPRESENTATIONCSSImagerySTRUCTUREHTML markupSite planningThree layers of web design
What is CSS?
Cascading
+
Style Sheet
Stylesheet
A stylesheet is a set of rules defining
how an html element will be “presented”in the browser.These rules are targeted to specificelements in the html document.

The concept is very similar to how you create stylesheets in InDesign.
Cascading
Most pages will have multiple stylesheetsthat define different styles to the sameelements.The cascade defines an ordered sequenceof style sheets where rules in later sheetshave greater precedence than earlierones.

low importanceClient (user) stylesheet
Linked stylesheet
high importanceEmbedded stylesheet
Inline Styles

Stylesheet 1
make the paragraph 16px, Verdana, red
Stylesheet 2
make the paragraph blue
16px, Verdana, blue

How to add css to your document
There are 2 basic ways to add styles to your html page:
External (linked)
<head>Internal

External
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
Except in special circumstances, best practice isto keep all your styles in a separate css document.Linked stylesheets can be applied across multipledocuments and sites.
Internal (embedded)
<head>
<style> p {color: red} </style>
</head>
You can add styles directly into your html pageusing the “style” element in the <head> ofyour document.Embedded styles apply ONLY to that 
html document.
Internal (inline)
<p style=”color: red”>Red Text</tag>
You can add styles directly into your htmlmarkup using the “style” attribute on openingtag of your element. This is called an “inline”style.Inline styles apply ONLY to that specificinstance of the element.
Best Practice
In most cases you should use the external method of addingstyles to your html page.Writing the css in the <head> of your document is acceptableif you definitely only want to apply the styles to a single page.However, adding your styles “inline” — inside a html startingtag, e.g. <p style=”font-size: 14px”> — should be avoided.

CSS SyntaxSyntax = the rules for how to write the language

Three terms for describing your styles:CSS ruleCSS selectorCSS declaration

CSS Rule
selector {property: value;}
declaration
Every style is defined by a selector and 
a declaration. The declaration contains at leastone property/value pair.Together they arecalled a CSS Rule.
CSS Selectorbody
{font-family:Arial, Helvetica}"p {color: #666666}"h1 {font-size: 24px}"a {color: blue}
The selector associates css rules with 
HTML elements.
CSS Selectorp {
color: red
}


The selector is typed in front of the declaration,with a space separating it and the openingcurly-bracket (aka curly-brace).Typically, extra spaces and returns are added asshown for the sake of readability.
CSS Selector
h1,h2,h3,h4 {
font-weight: bold
}

You can apply styles to multiple selectors in thesame rule by separating the selectors withcommas.
CSS Declaration
p {
property: value
}

The declaration is always defined in a property/value pair. The two are separated by a colon.How you define the properties will affect howHTML elements are displayed.
CSS Declaration
p {
font-family: Arial, sans-serif;
font-size: 14px;
color: #666666;
}

You can apply multiple declarations to aselector(s) by separating the delcarations withsemi-colons.
CSS Selectors
pType (element)#ID.ClassDescendant

Type (element) Selectors
body {declaration}
p {declaration}
h1 {declaration}
ul {declaration}
The simplest selector is the type selector, whichtargets an html element by name.
The essential selector types (elements)
Primary
StructureBody
ElementsFormatting
Elementshtmlpembodybrih1 – h6strongulbolqablockquoteimgspandiv
Type selectors vs ID & Class selectors
Type selectors use the tag names that arebuilt into HTML.
ID and class selectors use names that youdefine, and are added to html elementsto make them more specific.

Class Selectors

.ingredients {declaration}"CSS
<ul class=”ingredients”>
HTMLA class is an html attribute that is added to yourhtml markup. You reference that ID in your csswith a period.
ID Selectors

#logo {declaration}"CSS
<img id=”logo” src=”” alt=””>
HTMLAn ID is an html attribute that is added to yourhtml markup. You reference that ID in your csswith a hash.
IDs vs Classes
The most important difference between IDsand classes is that there can be only one IDon a page, but multiple classes.An ID is more specific than a class.An element can have both an ID andmultiple classes.
IDs vs Classes
ID: #344-34-4344Class: MaleClass: StudentID: #123-54-9877Class: FemaleClass: Student
Multiple classes
CSS
.ingredients.time {declaration}"HTML
<div class=”ingredients time”>
<h1></h1>
</div>

Elements can have multiple classes, giving youmore control. The are written in the CSS in theexact order they appear in the html, with nospaces.
Combining IDs and classes
CSS
#wrapper.ingredients.time {declaration}"HTML
<div id=”wrapper” class=”ingredients time”>
<h1></h1>
</div>

Elements can have both ids and classes. Whilean element can have only one id, it can havemultiple classes.
Descendant Selectors

.ingredients p {declaration}"CSS
<div class=”ingredients”>"HTML<p></p>"</div>
A descendant selector is a selector thatcombines the selectors of different elements totarget a specific element(s).
Applying Styles
The CascadeInheritanceSpecificity

The Cascade
The “cascade” part of CSS is a set of rulesfor resolving conflicts with multiple CSSrules applied to the same elements.For example, if there are two rules definingthe color or your h1 elements, the rule thatcomes last in the cascade order will“trump” the other. 

low importanceClient (user) stylesheet
Linked (external) stylesheet
high importanceEmbedded (internal) stylesheet
Inline (internal) Styles

Inheritance & Specificity
As a designer, your goal is to set an overallglobal consistent style, then add in morespecific styles as needed.You can control how and where your styles areapplied to your HTML by managing theirinheritance and specificity. 

Inheritance
Most elements will inherit many style propertiesfrom their parent elements by default. A parentis a containing element of a child.HTML"
<body>
<div>
<ul>
<li></li>
</ul>
</div>
</body>
relationship"parent of site"parent of ul and li, child of body"parent of li, child of div and body"child of ul, div, and body"


!
Inheritance
body
make the paragraph 16px, Verdana, red
p
make the paragraph blue
16px, Verdana, blue

Not all properties are inherited
Specificity
Shortly after styling your first html elements,you will find yourself wanting more control overwhere your styles are applied.This is where specificity comes in.
Specificity refers to how specific your selector isin naming an element. 

Specificity
If you have multiple styles applied to the sameelement, the browser goes with whicheverselector is more specific.

MaleMale
Student 
Male 
Student
George
Specificity
body
make the paragraph 16px, Verdana, red
p
make the paragraph blue
p.pink
make the paragraph pink
16px, Verdana, pink

Where specificity gets tricky
The basic concept of specificity is fairly simple:you target specific elements in your HTML bylisting out more of their identifiers.For example, if you want to apply a specialstyle to a paragraph, you need a “hook” in thehtml to make it different from every otherparagraph.
Where specificity gets tricky
This can get tricky in your css, because 
the more specific you make your selectors, theharder it is to manage global styles(inheritances).

Where specificity gets tricky
Make all text pink.body {color: pink}
Make all text in the element with the id“recipe” blue.#recipe {color: blue}
Make all text in the element with the class“ingredients” blue..ingredients {color: green}
Make all text in the paragraph elementwith the class “ingredients” purple.p.ingredients {color: purple}
Make all text in the paragraph elementwith the class “ingredients”, contained inthe element with the id “recipe”, grey.#recipe p.ingredients {color: grey}"
Where specificity gets tricky
HTML
<div id=”recipe”> 
<p class=”ingredients”>
<div>"CSS
body {color: pink}
#recipe {color: blue}
.ingredients {color: green}
p.ingredients {color: purple}
#recipe p.ingredients {color: grey}"!
Style Declaration: Text
Property Valuescolor: #444444;font-family: "Times New Roman", Georgia, serif;font-size: 16px; (define in px, em, or %)Style declarations are made of a property anda value. The type of value you can usedepends on the property. 

There are 5 basic ways of identifying fonts:Web Safe Fonts
(called font-family in your text)Font-FaceService-Based Font-FaceImagessIFR/Cufon

Web-safeWeb-safe fonts are fonts likely to be present on a widerange of computer systems, and used by Web contentauthors to increase the likelihood that content will bedisplayed in their chosen font.If a visitor to a Web site does not have the specifiedfont, their browser will attempt to select a similaralternative, based on the author-specified fallbackfonts and generic families or it will use fontsubstitution defined in the visitor's operating system.
from http://www.w3schools.com/cssref/css_websafe_fonts.asp
from http://www.w3schools.com/cssref/css_websafe_fonts.asp
Font StackThe font-family property can hold several font names as a"fallback" system. If the browser does not support the firstfont, it tries the next font.Start with the font you want, and end with a generic family,to let the browser pick a similar font in the generic family,if no other fonts are available.!EXAMPLES
body {
font-family: Helvetica, Arial, sans-serif}"h1 {
“Lato”, Arial, sans-serif}"
Units of Type SizeThere are three different ways to define type sizes in css.ems
Ems are a relative unit: 1em is equal to the current font size.The default text size in browsers is 16px. So, the default sizeof 1em is 16px.px
Pixels are a an absolute unit, it sets the text to a specific sizeinstead of a size relative to the browser’s default. Except inspecial cases, you should define pixels in your css with thenumber and “px” together, no spaces: “16px”.%
Like ems, percentages are also a relative unit. It is very usefulfor layout, not usually a good idea for type sizes.
Specifying ColorThere are three different ways to define color in css.Hex Codes
This is the most common way to identify colors in CSS. Thecode gives two characters to correspond to RGB values. Thenumber always has 6 characters (#44de42), unless all fourcharacters are the same, and you can shorten it (#444).RGB
You can use a color’s RGB values with this syntax: 
p {color: rgb(34,123,125);}Color Names
There are built-in color names that you can use, that willprovide generic hues: 
p {color: rgb(34,123,125);}
Specifying Color!HexidecimalRGB
Color: white, black, greyWhite = #ffffff, or #fffBlack = #000000, or #000Greys = #111111 – #999999

Type properties to learn now:colorfont-familyfont-sizefont-weightfont-styleletter-spacingline-heighttext-aligntext-transform
Example values:color: #444444;font-family: "Times New Roman", Georgia, serif;font-size: 16px; (define in px, em, or %)font-weight: bold; (or by number, 400, 700)font-style: italic;letter-spacing: .02em;line-height: 1.6; (relative to whatever your type size is)text-align: left;
text-transform: uppercase;
Styling Lists
List stylingLinks can be styled just like any text, but havespecial properties. The most often used is “liststyle-type”, which allows you to control whetherbullets are used, and how they are styled.ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}!!!
List stylingBy default, <li> elements are block-level elements(they stack on top of each other). You can forcethem to line up in a row by changing the displayproperty to “inline.”li {
display: inline;
}!!!
Styling Links
Link statesLinks can be styled just like any text, but havespecial pseudo-classes that allow you to definetheir behavior.a {color:#FF0000;}      /* unvisited link */a:visited {color:#00FF00;}  /* visited link */a:hover {color:#FF00FF;}  /* mouse over link */a:active {color:#0000FF;}  /* selected link */When setting the style for several link states, thereare some order rules:— a:hover MUST come after a:link and a:visited— a:active MUST come after a:hover!
LinksBy default, links are underlined. You can turn this off bychanging the “text-decoration” property.In the example below, the link will only have an underlinewhen the cursor is hovering over the element.a {
color:#FF0000;
text-decoration: none;
} a:hover {
color:#00FF00;
text-decoration: underline;
} !
Class Exercise 9!

Recommended

PDF
Web Typography
PDF
Week 2-intro-html
PDF
CSS Foundations, pt 2
PDF
Web Layout
PDF
Images on the Web
PDF
Frontend Crash Course: HTML and CSS
PDF
HTML Foundations, pt 2
PDF
HTML Email
PPT
Advanced Cascading Style Sheets
PPT
Span and Div tags in HTML
PPT
Presentation on html, css
PDF
Html / CSS Presentation
ODP
Introduction of Html/css/js
PDF
Intro to HTML and CSS basics
PDF
Div tag presentation
PDF
Intro to HTML and CSS - Class 2 Slides
PDF
3 Layers of the Web - Part 1
PDF
HTML & CSS Masterclass
PPTX
Web Design Assignment 1
PDF
Class Intro / HTML Basics
DOCX
PHP HTML CSS Notes
PDF
HTML CSS Basics
PDF
HTML and CSS crash course!
PPTX
Cascading style sheet
PPTX
Introduction to web design discussing which languages is used for website des...
PPTX
(Fast) Introduction to HTML & CSS
PPTX
Introduction to HTML
PPTX
Html training slide
PDF
Basics of Web Navigation
PDF
10 Usability & UX Guidelines

More Related Content

PDF
Web Typography
PDF
Week 2-intro-html
PDF
CSS Foundations, pt 2
PDF
Web Layout
PDF
Images on the Web
PDF
Frontend Crash Course: HTML and CSS
PDF
HTML Foundations, pt 2
PDF
HTML Email
Web Typography
Week 2-intro-html
CSS Foundations, pt 2
Web Layout
Images on the Web
Frontend Crash Course: HTML and CSS
HTML Foundations, pt 2
HTML Email

What's hot

PPT
Advanced Cascading Style Sheets
PPT
Span and Div tags in HTML
PPT
Presentation on html, css
PDF
Html / CSS Presentation
ODP
Introduction of Html/css/js
PDF
Intro to HTML and CSS basics
PDF
Div tag presentation
PDF
Intro to HTML and CSS - Class 2 Slides
PDF
3 Layers of the Web - Part 1
PDF
HTML & CSS Masterclass
PPTX
Web Design Assignment 1
PDF
Class Intro / HTML Basics
DOCX
PHP HTML CSS Notes
PDF
HTML CSS Basics
PDF
HTML and CSS crash course!
PPTX
Cascading style sheet
PPTX
Introduction to web design discussing which languages is used for website des...
PPTX
(Fast) Introduction to HTML & CSS
PPTX
Introduction to HTML
PPTX
Html training slide
Advanced Cascading Style Sheets
Span and Div tags in HTML
Presentation on html, css
Html / CSS Presentation
Introduction of Html/css/js
Intro to HTML and CSS basics
Div tag presentation
Intro to HTML and CSS - Class 2 Slides
3 Layers of the Web - Part 1
HTML & CSS Masterclass
Web Design Assignment 1
Class Intro / HTML Basics
PHP HTML CSS Notes
HTML CSS Basics
HTML and CSS crash course!
Cascading style sheet
Introduction to web design discussing which languages is used for website des...
(Fast) Introduction to HTML & CSS
Introduction to HTML
Html training slide

Viewers also liked

PDF
Basics of Web Navigation
PDF
10 Usability & UX Guidelines
PDF
Introduction to Responsive Web Design
PDF
Web Design Process
PDF
Intro to Javascript and jQuery
PDF
Creating Images for the Web
PDF
Usability and User Experience
PPT
CSS for Beginners
PPT
Introduction to Cascading Style Sheets (CSS)
PPT
Introduction to CSS
PPT
CSS ppt
PPT
Chapter 1 - Web Design
PPT
Cascading Style Sheets (CSS) help
PPTX
Your Presentation is CRAP, and That's Why I Like It
PPTX
PPTX
Principles Of Effective Design
PDF
Basic css-tutorial
PDF
HTML Foundations, pt 3: Forms
PDF
Intro to jQuery
Basics of Web Navigation
10 Usability & UX Guidelines
Introduction to Responsive Web Design
Web Design Process
Intro to Javascript and jQuery
Creating Images for the Web
Usability and User Experience
CSS for Beginners
Introduction to Cascading Style Sheets (CSS)
Introduction to CSS
CSS ppt
Chapter 1 - Web Design
Cascading Style Sheets (CSS) help
Your Presentation is CRAP, and That's Why I Like It
Principles Of Effective Design
Basic css-tutorial
HTML Foundations, pt 3: Forms
Intro to jQuery

Similar to CSS Foundations, pt 1

PPT
Unit 2-CSS & Bootstrap.ppt
PDF
Chapterrr_8_Introduction to CSS.pptx.pdf
PPTX
Css types internal, external and inline (1)
PPTX
Lecture 3CSS part 1.pptx
PPTX
Web technologies-course 03.pptx
PPTX
Lecture 9 CSS part 1.pptxType Classification
PPTX
Cascading Style Sheet
PPT
css-presentation.ppt
PDF
PDF
CSCADING style sheet. Internal external inline
PDF
css-ppt.pdf
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
PPTX
Css basics
PDF
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
PPTX
CSS Fundamentals: selectors and Properties
PPTX
Introduction to CSS
PDF
4. Web Technology CSS Basics-1
PPTX
Web Development - Lecture 5
PPTX
CSS ppt of cascading Style sheet for beginners.pptx
Unit 2-CSS & Bootstrap.ppt
Chapterrr_8_Introduction to CSS.pptx.pdf
Css types internal, external and inline (1)
Lecture 3CSS part 1.pptx
Web technologies-course 03.pptx
Lecture 9 CSS part 1.pptxType Classification
Cascading Style Sheet
css-presentation.ppt
CSCADING style sheet. Internal external inline
css-ppt.pdf
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Css basics
ch-hguygureehuvnvdfduyertiuhrnhduuyfjh3.pdf
CSS Fundamentals: selectors and Properties
Introduction to CSS
4. Web Technology CSS Basics-1
Web Development - Lecture 5
CSS ppt of cascading Style sheet for beginners.pptx

More from Shawn Calvert

PDF
User Centered Design
PDF
Web Design I Syllabus 22 3375-03
PDF
HTML Foundations, part 1
PDF
Web Design 1: Introductions
PDF
22-3530, Photo Communications Syllabus
PDF
An Overview of Stock Photography
PDF
Color Photography
PDF
PSA posters
PDF
Composition & Light
PDF
of Pixels and Bits
PDF
Camera basics
PDF
Typography I syllabus
User Centered Design
Web Design I Syllabus 22 3375-03
HTML Foundations, part 1
Web Design 1: Introductions
22-3530, Photo Communications Syllabus
An Overview of Stock Photography
Color Photography
PSA posters
Composition & Light
of Pixels and Bits
Camera basics
Typography I syllabus

Recently uploaded

PPTX
How to Configure Push & Pull Rule in Odoo 18 Inventory
DOCX
Mobile applications Devlopment ReTest year 2025-2026
PDF
The Tale of Melon City poem ppt by Sahasra
PDF
Scalable-MADDPG-Based Cooperative Target Invasion for a Multi-USV System.pdf
PDF
M.Sc. Nonchordates Complete Syllabus PPT | All Important Topics Covered
PPTX
TAMIS & TEMS - HOW, WHY and THE STEPS IN PROCTOLOGY
PDF
Toward Massive, Ultrareliable, and Low-Latency Wireless Communication With Sh...
PPTX
How to Manage Line Discounts in Odoo 18 POS
PDF
FAMILY ASSESSMENT FORMAT - CHN practical
PPTX
Accounting Skills Paper-II (Registers of PACs and Credit Co-operative Societies)
PPTX
ICH Harmonization A Global Pathway to Unified Drug Regulation.pptx
PPTX
The Cell & Cell Cycle-detailed structure and function of organelles.pptx
PPTX
Unit I — Introduction to Anatomical Terms and Organization of the Human Body
PDF
1ST APPLICATION FOR ANNULMENT (4)8787666.pdf
PDF
All Students Workshop 25 Yoga Wellness by LDMMIA
PDF
Projecte de la porta d'i5B: Els animals marins
PPTX
York "Collaboration for Research Support at U-M Library"
PDF
Unit-III pdf (Basic listening Skill, Effective Writing Communication & Writin...
PDF
Projecte de la porta de primer B: L'antic Egipte
PDF
NAVIGATE PHARMACY CAREER OPPORTUNITIES.pdf
How to Configure Push & Pull Rule in Odoo 18 Inventory
Mobile applications Devlopment ReTest year 2025-2026
The Tale of Melon City poem ppt by Sahasra
Scalable-MADDPG-Based Cooperative Target Invasion for a Multi-USV System.pdf
M.Sc. Nonchordates Complete Syllabus PPT | All Important Topics Covered
TAMIS & TEMS - HOW, WHY and THE STEPS IN PROCTOLOGY
Toward Massive, Ultrareliable, and Low-Latency Wireless Communication With Sh...
How to Manage Line Discounts in Odoo 18 POS
FAMILY ASSESSMENT FORMAT - CHN practical
Accounting Skills Paper-II (Registers of PACs and Credit Co-operative Societies)
ICH Harmonization A Global Pathway to Unified Drug Regulation.pptx
The Cell & Cell Cycle-detailed structure and function of organelles.pptx
Unit I — Introduction to Anatomical Terms and Organization of the Human Body
1ST APPLICATION FOR ANNULMENT (4)8787666.pdf
All Students Workshop 25 Yoga Wellness by LDMMIA
Projecte de la porta d'i5B: Els animals marins
York "Collaboration for Research Support at U-M Library"
Unit-III pdf (Basic listening Skill, Effective Writing Communication & Writin...
Projecte de la porta de primer B: L'antic Egipte
NAVIGATE PHARMACY CAREER OPPORTUNITIES.pdf

CSS Foundations, pt 1

  • 1.
    CSS Foundations, pt122-3375 Web Design I // Columbia College Chicago
  • 2.
    For Starters!!Post assignmentand blog postReview student blog postsInstructor review of Assign 3HTML refresher exercise!!
  • 3.
    Skills learned sofar
how to create a web directory and link between filesCode a basic webpage from scratchhow to mark up different types of content with appropriate HTML tagshow to use basic HTML attributes to create links and web imageshow to set up a site domain, server host and install a wordpress site
  • 12.
    Three layers ofweb design:
Structure, Style, Behavior
  • 13.
    Three layers ofweb design
  • 14.
    Three layers ofweb design
  • 15.
    Three layers ofweb design
  • 16.
  • 17.
  • 18.
  • 19.
    Stylesheet
A stylesheet isa set of rules defining
how an html element will be “presented”in the browser.These rules are targeted to specificelements in the html document.

  • 20.
    The concept isvery similar to how you create stylesheets in InDesign.
  • 21.
    Cascading
Most pages willhave multiple stylesheetsthat define different styles to the sameelements.The cascade defines an ordered sequenceof style sheets where rules in later sheetshave greater precedence than earlierones.

  • 22.
    low importanceClient (user)stylesheet
Linked stylesheet
high importanceEmbedded stylesheet
Inline Styles

  • 23.
    Stylesheet 1
make theparagraph 16px, Verdana, red
Stylesheet 2
make the paragraph blue
16px, Verdana, blue

  • 25.
    How to addcss to your document
  • 26.
    There are 2basic ways to add styles to your html page:
External (linked)
<head>Internal

  • 27.
    External
<head>
<link rel="stylesheet" type="text/css"href="stylesheet.css">
</head>
Except in special circumstances, best practice isto keep all your styles in a separate css document.Linked stylesheets can be applied across multipledocuments and sites.
  • 28.
    Internal (embedded)
<head>
<style> p{color: red} </style>
</head>
You can add styles directly into your html pageusing the “style” element in the <head> ofyour document.Embedded styles apply ONLY to that 
html document.
  • 29.
    Internal (inline)
<p style=”color:red”>Red Text</tag>
You can add styles directly into your htmlmarkup using the “style” attribute on openingtag of your element. This is called an “inline”style.Inline styles apply ONLY to that specificinstance of the element.
  • 31.
    Best Practice
In mostcases you should use the external method of addingstyles to your html page.Writing the css in the <head> of your document is acceptableif you definitely only want to apply the styles to a single page.However, adding your styles “inline” — inside a html startingtag, e.g. <p style=”font-size: 14px”> — should be avoided.

  • 32.
    CSS SyntaxSyntax =the rules for how to write the language

  • 33.
    Three terms fordescribing your styles:CSS ruleCSS selectorCSS declaration

  • 34.
    CSS Rule
selector {property:value;}
declaration
Every style is defined by a selector and 
a declaration. The declaration contains at leastone property/value pair.Together they arecalled a CSS Rule.
  • 35.
    CSS Selectorbody
{font-family:Arial, Helvetica}"p{color: #666666}"h1 {font-size: 24px}"a {color: blue}
The selector associates css rules with 
HTML elements.
  • 36.
    CSS Selectorp {
color:red
}


The selector is typed in front of the declaration,with a space separating it and the openingcurly-bracket (aka curly-brace).Typically, extra spaces and returns are added asshown for the sake of readability.
  • 37.
    CSS Selector
h1,h2,h3,h4 {
font-weight:bold
}

You can apply styles to multiple selectors in thesame rule by separating the selectors withcommas.
  • 38.
    CSS Declaration
p {
property:value
}

The declaration is always defined in a property/value pair. The two are separated by a colon.How you define the properties will affect howHTML elements are displayed.
  • 39.
    CSS Declaration
p {
font-family:Arial, sans-serif;
font-size: 14px;
color: #666666;
}

You can apply multiple declarations to aselector(s) by separating the delcarations withsemi-colons.
  • 41.
  • 42.
  • 43.
    Type (element) Selectors
body{declaration}
p {declaration}
h1 {declaration}
ul {declaration}
The simplest selector is the type selector, whichtargets an html element by name.
  • 44.
    The essential selectortypes (elements)
Primary
StructureBody
ElementsFormatting
Elementshtmlpembodybrih1 – h6strongulbolqablockquoteimgspandiv
  • 45.
    Type selectors vsID & Class selectors
Type selectors use the tag names that arebuilt into HTML.
ID and class selectors use names that youdefine, and are added to html elementsto make them more specific.

  • 46.
    Class Selectors

.ingredients {declaration}"CSS
<ulclass=”ingredients”>
HTMLA class is an html attribute that is added to yourhtml markup. You reference that ID in your csswith a period.
  • 47.
    ID Selectors

#logo {declaration}"CSS
<imgid=”logo” src=”” alt=””>
HTMLAn ID is an html attribute that is added to yourhtml markup. You reference that ID in your csswith a hash.
  • 48.
    IDs vs Classes
Themost important difference between IDsand classes is that there can be only one IDon a page, but multiple classes.An ID is more specific than a class.An element can have both an ID andmultiple classes.
  • 49.
    IDs vs Classes
ID:#344-34-4344Class: MaleClass: StudentID: #123-54-9877Class: FemaleClass: Student
  • 50.
    Multiple classes
CSS
.ingredients.time {declaration}"HTML
<divclass=”ingredients time”>
<h1></h1>
</div>

Elements can have multiple classes, giving youmore control. The are written in the CSS in theexact order they appear in the html, with nospaces.
  • 51.
    Combining IDs andclasses
CSS
#wrapper.ingredients.time {declaration}"HTML
<div id=”wrapper” class=”ingredients time”>
<h1></h1>
</div>

Elements can have both ids and classes. Whilean element can have only one id, it can havemultiple classes.
  • 52.
    Descendant Selectors

.ingredients p{declaration}"CSS
<div class=”ingredients”>"HTML<p></p>"</div>
A descendant selector is a selector thatcombines the selectors of different elements totarget a specific element(s).
  • 54.
  • 55.
  • 56.
    The Cascade
The “cascade”part of CSS is a set of rulesfor resolving conflicts with multiple CSSrules applied to the same elements.For example, if there are two rules definingthe color or your h1 elements, the rule thatcomes last in the cascade order will“trump” the other. 

  • 57.
    low importanceClient (user)stylesheet
Linked (external) stylesheet
high importanceEmbedded (internal) stylesheet
Inline (internal) Styles

  • 58.
    Inheritance & Specificity
Asa designer, your goal is to set an overallglobal consistent style, then add in morespecific styles as needed.You can control how and where your styles areapplied to your HTML by managing theirinheritance and specificity. 

  • 59.
    Inheritance
Most elements willinherit many style propertiesfrom their parent elements by default. A parentis a containing element of a child.HTML"
<body>
<div>
<ul>
<li></li>
</ul>
</div>
</body>
relationship"parent of site"parent of ul and li, child of body"parent of li, child of div and body"child of ul, div, and body"


!
  • 60.
    Inheritance
body
make the paragraph16px, Verdana, red
p
make the paragraph blue
16px, Verdana, blue

  • 61.
    Not all propertiesare inherited
  • 63.
    Specificity
Shortly after stylingyour first html elements,you will find yourself wanting more control overwhere your styles are applied.This is where specificity comes in.
Specificity refers to how specific your selector isin naming an element. 

  • 64.
    Specificity
If you havemultiple styles applied to the sameelement, the browser goes with whicheverselector is more specific.

MaleMale
Student 
Male 
Student
George
  • 65.
    Specificity
body
make the paragraph16px, Verdana, red
p
make the paragraph blue
p.pink
make the paragraph pink
16px, Verdana, pink

  • 66.
    Where specificity getstricky
The basic concept of specificity is fairly simple:you target specific elements in your HTML bylisting out more of their identifiers.For example, if you want to apply a specialstyle to a paragraph, you need a “hook” in thehtml to make it different from every otherparagraph.
  • 67.
    Where specificity getstricky
This can get tricky in your css, because 
the more specific you make your selectors, theharder it is to manage global styles(inheritances).
  • 68.
    
Where specificity getstricky
Make all text pink.body {color: pink}
Make all text in the element with the id“recipe” blue.#recipe {color: blue}
Make all text in the element with the class“ingredients” blue..ingredients {color: green}
Make all text in the paragraph elementwith the class “ingredients” purple.p.ingredients {color: purple}
Make all text in the paragraph elementwith the class “ingredients”, contained inthe element with the id “recipe”, grey.#recipe p.ingredients {color: grey}"
  • 69.
    Where specificity getstricky
HTML
<div id=”recipe”> 
<p class=”ingredients”>
<div>"CSS
body {color: pink}
#recipe {color: blue}
.ingredients {color: green}
p.ingredients {color: purple}
#recipe p.ingredients {color: grey}"!
  • 71.
  • 72.
    Property Valuescolor: #444444;font-family:"Times New Roman", Georgia, serif;font-size: 16px; (define in px, em, or %)Style declarations are made of a property anda value. The type of value you can usedepends on the property. 

  • 73.
    There are 5basic ways of identifying fonts:Web Safe Fonts
(called font-family in your text)Font-FaceService-Based Font-FaceImagessIFR/Cufon

  • 74.
    Web-safeWeb-safe fonts arefonts likely to be present on a widerange of computer systems, and used by Web contentauthors to increase the likelihood that content will bedisplayed in their chosen font.If a visitor to a Web site does not have the specifiedfont, their browser will attempt to select a similaralternative, based on the author-specified fallbackfonts and generic families or it will use fontsubstitution defined in the visitor's operating system.
  • 75.
  • 76.
  • 77.
    Font StackThe font-familyproperty can hold several font names as a"fallback" system. If the browser does not support the firstfont, it tries the next font.Start with the font you want, and end with a generic family,to let the browser pick a similar font in the generic family,if no other fonts are available.!EXAMPLES
body {
font-family: Helvetica, Arial, sans-serif}"h1 {
“Lato”, Arial, sans-serif}"
  • 78.
    Units of TypeSizeThere are three different ways to define type sizes in css.ems
Ems are a relative unit: 1em is equal to the current font size.The default text size in browsers is 16px. So, the default sizeof 1em is 16px.px
Pixels are a an absolute unit, it sets the text to a specific sizeinstead of a size relative to the browser’s default. Except inspecial cases, you should define pixels in your css with thenumber and “px” together, no spaces: “16px”.%
Like ems, percentages are also a relative unit. It is very usefulfor layout, not usually a good idea for type sizes.
  • 79.
    Specifying ColorThere arethree different ways to define color in css.Hex Codes
This is the most common way to identify colors in CSS. Thecode gives two characters to correspond to RGB values. Thenumber always has 6 characters (#44de42), unless all fourcharacters are the same, and you can shorten it (#444).RGB
You can use a color’s RGB values with this syntax: 
p {color: rgb(34,123,125);}Color Names
There are built-in color names that you can use, that willprovide generic hues: 
p {color: rgb(34,123,125);}
  • 80.
  • 81.
    Color: white, black,greyWhite = #ffffff, or #fffBlack = #000000, or #000Greys = #111111 – #999999

  • 84.
    Type properties tolearn now:colorfont-familyfont-sizefont-weightfont-styleletter-spacingline-heighttext-aligntext-transform
  • 85.
    Example values:color: #444444;font-family:"Times New Roman", Georgia, serif;font-size: 16px; (define in px, em, or %)font-weight: bold; (or by number, 400, 700)font-style: italic;letter-spacing: .02em;line-height: 1.6; (relative to whatever your type size is)text-align: left;
text-transform: uppercase;
  • 87.
  • 88.
    List stylingLinks canbe styled just like any text, but havespecial properties. The most often used is “liststyle-type”, which allows you to control whetherbullets are used, and how they are styled.ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}!!!
  • 89.
    List stylingBy default,<li> elements are block-level elements(they stack on top of each other). You can forcethem to line up in a row by changing the displayproperty to “inline.”li {
display: inline;
}!!!
  • 91.
  • 92.
    Link statesLinks canbe styled just like any text, but havespecial pseudo-classes that allow you to definetheir behavior.a {color:#FF0000;}      /* unvisited link */a:visited {color:#00FF00;}  /* visited link */a:hover {color:#FF00FF;}  /* mouse over link */a:active {color:#0000FF;}  /* selected link */When setting the style for several link states, thereare some order rules:— a:hover MUST come after a:link and a:visited— a:active MUST come after a:hover!
  • 93.
    LinksBy default, linksare underlined. You can turn this off bychanging the “text-decoration” property.In the example below, the link will only have an underlinewhen the cursor is hovering over the element.a {
color:#FF0000;
text-decoration: none;
} a:hover {
color:#00FF00;
text-decoration: underline;
} !
  • 94.

[8]ページ先頭

©2009-2025 Movatter.jp