SlideShare una empresa de Scribd logo
1 de 64
Descargar para leer sin conexión
CSS Foundations, pt 2
22-3375 Web Design I // Columbia College Chicago
Review

What is css and how it’s relationship to your html files
Three different approaches to applying your css to the html
How the browser interprets the “cascade” of style rules
How to write CSS rules
Understand basic css properties for text styling
How to add class and id selectors to your html for more styling control
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 is
to keep all your styles in a separate css document.
Linked stylesheets can be applied across multiple
documents and sites.
Internal (embedded)



<head>

<style> p {color: red} </style>

</head>


You can add styles directly into your html page
using the “style” element in the <head> of
your 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 html
markup using the “style” attribute on opening
tag of your element. This is called an “inline”
style.
Inline styles apply ONLY to that specific
instance of the element.
Best Practice

In most cases you should use the external method of adding
styles to your html page.
Writing the css in the <head> of your document is acceptable
if you definitely only want to apply the styles to a single page.
However, adding your styles “inline” — inside a html starting
tag, e.g. <p style=”font-size: 14px”> — should be avoided.


Class Exercise
!

!

download class tutorial files
create new css file in ‘review’ folder
link to the css file from review.html file


CSS Selectors
p

Type (element)

#

ID

.

Class

Type (element) Selectors



body {declaration}

p {declaration}

h1 {declaration}

ul {declaration}


The simplest selector is the type selector, which
targets an html element by name.
The essential selector types (elements)

Primary

Structure

Body

Elements

Formatting

Elements

html

p

em

body

br

i

h1 – h6

strong

ul

b

ol

q

a

blockquote

img

span

div
div elements

Div elements allow you to group a set of
elements together in one block-level element.
!




<div id=”head”>
<a bunch of elements></>
</div>

span elements

span elements are the inline equivalent of divs.
!

<p>Here is some text <span class=”red-text”>
with a span</span> added.</p>



Spans are the equivalent of ‘character’ styles 

in InDesign.

type selectors vs IDs & Classes


Type selectors use the tag names that are
built into HTML.




IDs and classes use names that you define, and
are added to html elements to make them
more specific.

ID Selectors



#logo {declaration}"
CSS



<img id=”logo” src=”” alt=””>

HTML

An ID is an html attribute that is added to your
html markup. You reference that ID in your css
with a hash.
Class Selectors



.ingredients {declaration}"
CSS



<ul class=”ingredients”>

HTML

A class is an html attribute that is added to your
html markup. You reference that ID in your css
with a period.
IDs vs Classes

The most important difference between IDs
and classes is that there can be only one ID
on a page, but multiple classes.
An ID is more specific than a class.
An element can have both an ID and
multiple classes.
IDs vs Classes


ID: #344-34-4344
Class: Male
Class: Student

ID: #123-54-9877
Class: Female
Class: Student
Descendant Selectors

CSS


#sidebar .author {declaration}"
HTML


<div id=”sidebar”>

<p class=”author”></p>

</div>




A space between two selectors indicates a
descendant selector. In the example above, the
style is targeted to an element with the class
“author” inside the id “sidebar”.
Multiple classes

CSS


.ingredients.time {declaration}"
HTML


<div class=”ingredients time”>

<h1></h1>

</div>




Elements can have multiple classes, giving you
more control. The are written in the CSS in the
exact order they appear in the html, with no
spaces.
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. While
an element can have only one id, it can have
multiple classes.
Class Exercise
!

Copy the following values from another site:


The Box Model:

Defining the dimensions
There are five basic properties for defining your “boxes”:

display
width and height
padding
margins
border

CSS Box Model
All HTML elements can be
considered as boxes or
blocks. In CSS, the term
"box model" is used when
talking about design and
layout.
The CSS box model is
essentially a box that wraps
around HTML elements,
and it consists of: margins,
borders, padding, and the
actual content.

!

Inspect Element 3d view in Firefox
Total dimensions
The actual width or height of
any object is the total of the
content width, padding,
borders, and margins.
.size-me {

width: 200px; 

padding: 10px;

border: 2px;

margin: 20px;

}"

The actual width: 254px
content: 200px

padding-left: 10px

padding-right: 10px

border-right: 2px

border-left: 2px

margin-right: 20px

margin-left: 20px

Display property
By default, certain elements in your html have a display
property of inline or block.
Block elements takes up the full width available, and forces a
line above and below. Examples include <p>, <div>, <ul>,
<blockquote> and all headers. 


<div></div>
<p></p>
<ul></ul>
Display property
Inline elements can be inserted within block elements or
other inline elements and do no create additional space or
line breaks. Examples include <img>, <em>, <strong>,
<a>, and <span>. 


<p>
<p></p>
<p></p>

<a></a>

</p>
Display property
There are four values that you can give to the display property:
display: block;
display: inline;
display: inline-block;
display: none

!
Inline-block is a special value that allows an element to stay inline
with its containing element, but allows you to control it’s
dimensions as if it were a block element.
display: none removes the element. 

Display property
For example, by default, a <li> element is set to display: block. If
we change that value in our css to:
li {display: inline-block;}
Then this:

Changes to this:


<ul>

<ul>

<li>

</li>

<li>

</li>

<ul>

<li>
<ul>

</li>

<li>

</li>
Class Exercise
!

1 Inline and Block


Class Exercise
!

2 Borders and Margins


Defining dimension: width and height
You can set the width and height of any element that has a
display property of block or inline-block.
As with type, you can set dimension in pixels (px), ems, or
percentage (%). Setting any width with pixels is referred to as
fixed-width, and setting width in ems or percentages is
referred to as flexible-width.
.size-me {

width: 200px; 

height: 200px;

}

!
!
Defining dimension: min- and maxInstead of absolutely defining the width and height of your
elements, you can set minimum and maximum widths and
heights.
This allows you to resize elements based on the browser or
their parent elements. The idea of creating flexible content
that adjusts to the user’s browser/device is at the core of
what is referred to as responsive design.
.size-me {

min-width: 200px; 

max-width: 100px;

}"
Defining dimension: min-width and max-width

!
!
!
Defining dimension: min-width and max-width

!
!
!
Defining padding & margins
You can set the padding and margin properties of any
element in css.
Margin and padding dimensions can be also pixels (px),
ems, or percentage (%).
.space-me {

padding: 10px; 

margin-bottom: 20px;

}

!
!
!
Defining padding & margins
While you can add padding and margins to inline
elements, not all of your properties will apply (vertical
spacing, see below).

!
!
!
Collapsing margins

When two or more
margins collapse, the
resulting margin width
is the maximum of the
collapsing margins'
widths.
In the example below,
box1 has a taller
margin than box2, so
only that margin will
be used (not added
together).
!
!
CSS Shorthand

When setting sizes for padding,
margins and borders, instead of this:
.box {

padding-top: 10px; 

padding-right: 15px;

padding-bottom: 10px; 

padding-left: 15px;

}

1
4

2

Use this:
.box {

padding: 10px 15px 10px 15px;

}"

The values start at the top and go
around the element clockwise.
!

3
CSS Shorthand

If your top/bottom and left/right
values are the same, you can shorten
the declaration even more:
.box {

padding: 10px 15px;

}"

Where the first value is for the top and
bottom, and the second is for left and
right.
!

!

1
2

2
1
Defining borders
You can create a border around any element with css;
you can create the same border on each side, or
customize the color, width and border style of each side.

!
There are 3 properties to define with each border: 

border-width: 1px;
border-style: solid; (dotted, dashed, etc)
border color: #666666;

!
!
!
CSS Shorthand

Borders can also be shortened, from this:
.box {

border-width: 1px;

border-style: solid;

border-color: #888888

}"

to this:
.box {

border: 1px solid #888888;

}"

Note that there is only a single space between each value, and
they should follow the order shown above.

!
Defining borders


h3 {

border-bottom: 1px solid #444444;

}

!
!
Class Exercise
!

3 Centered, Fixed-Width Page


The Box Model:

Positioning
There are four basic declarations 

you can use to position your boxes:

float: left (or right)
position: relative
position: fixed
position: absolute

position: static
Static positioning is the default – this is referred to as the
“normal flow”.
block boxes are positioned on a page one after the
other (in the order they're written in the HTML). They
start in the upper left of the containing box and stack
from top to bottom. The distance between each box is
defined by the margins with top and bottom margins
collapsing into one another.

!
!

<div id=”header”></div>

! <div id=”content”></div>
<ul id=”sidebar-nav”></ul>
float
A floated element takes the element out of the normal
flow and moves it to the far right or left of the containing
element. Existing content will then flow around it.
Floated elements should always have at least a width
property.
.photo {

float: left;

max-width: 150px;

}"

!
!
4 Float
!



.photo {

float: left;

max-width: 150px;

}"

!
!
Class Exercise
!

5 Positioning


Positioning Properties
There are four values that you can give to the position property:

!
static Elements renders in order, as they appear in the
document flow. This is default.
relative The element is positioned relative to its static position,
so “left:20” adds 20 pixels to the element’s LEFT position.
absolute The element is positioned relative to its first positioned
(not static) ancestor element (usually, the first parent with
position:relative).




fixed The element is positioned relative to the browser window.
boxes exercise
.box {

"" width: 300px;

"" height: 300px;

"" border: 1px solid #333;

"" margin: 10px;

"" display: inline-block;

}" "
.relative {

"" position: relative;

"" top: 50px;

"" left: -50px;

}"
.fixed {

"" position: fixed;

"" bottom: 0;

"" left: 0;

}"

!
boxes exercise
.box.absolute {

"" position: relative;

}"
.box.absolute p {

"" position: absolute;

"" top: 0;

"" right: 0;

"" background: #444;

"" padding: 10px;

"" margin: 0;

"" color: #fff;

}"

!
!
!
relative
A relative positioned element moves the element out of
it’s position in the normal flow, and allows you to move it
“relative” to that location. The space taken by the
original location is retained in the flow.
.date {

position: relative;

top: 40px;

left: -105px;

}"

!
!
relative exercise
!

!
!

!
!

.date {

position: relative;

top: 40px;

left: -105px;

}"
fixed
A fixed element is taken complete out of the document
flow, and is positioned relative to the browser window.

.create-change {

position: fixed;

bottom: 40px;

right: 0;

}"

!
!
fixed exercise
!

!
!

!
!

.create-change {

position: fixed;

bottom: 40px;

right: 0;

}"
absolute
The element is positioned relative to its first positioned
(not static) ancestor element. The element and its
spacing are completely taken out of the flow. In the
example below, the “.post” parent element is given a
position value of relative, which lets us set it’s child
element “.icon” within it.

.post {

position: relative;

}"
.icon {

position: absolute;

left: -60px;

right: 0;

}"

!
!
absolute exercise
!

!
!

.post {

position: relative;

}"
.icon {

position: absolute;

left: -60px;

right: 0;

}"

!
!

Más contenido relacionado

La actualidad más candente

Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/jsKnoldus Inc.
 
Div tag presentation
Div tag presentationDiv tag presentation
Div tag presentationalyssa_lum11
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheetMichael Jhon
 
3 Layers of the Web - Part 1
3 Layers of the Web - Part 13 Layers of the Web - Part 1
3 Layers of the Web - Part 1Jeremy White
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1 beretta21
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Hatem Mahmoud
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)Ardee Aram
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesHeather Rock
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS Dave Kelly
 
Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Aditya Dwivedi
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designersSingsys Pte Ltd
 
HTML & CSS Workshop Notes
HTML & CSS Workshop NotesHTML & CSS Workshop Notes
HTML & CSS Workshop NotesPamela Fox
 

La actualidad más candente (20)

Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
 
Div tag presentation
Div tag presentationDiv tag presentation
Div tag presentation
 
HTML Email
HTML EmailHTML Email
HTML Email
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
3 Layers of the Web - Part 1
3 Layers of the Web - Part 13 Layers of the Web - Part 1
3 Layers of the Web - Part 1
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 Slides
 
HTML & CSS Masterclass
HTML & CSS MasterclassHTML & CSS Masterclass
HTML & CSS Masterclass
 
PHP HTML CSS Notes
PHP HTML CSS  NotesPHP HTML CSS  Notes
PHP HTML CSS Notes
 
Html training slide
Html training slideHtml training slide
Html training slide
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
HTML & CSS Workshop Notes
HTML & CSS Workshop NotesHTML & CSS Workshop Notes
HTML & CSS Workshop Notes
 

Destacado

Basics of Web Navigation
Basics of Web NavigationBasics of Web Navigation
Basics of Web NavigationShawn Calvert
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to Responsive Web DesignShawn Calvert
 
10 Usability & UX Guidelines
10 Usability & UX Guidelines10 Usability & UX Guidelines
10 Usability & UX GuidelinesShawn Calvert
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQueryShawn Calvert
 
Creating Images for the Web
Creating Images for the WebCreating Images for the Web
Creating Images for the WebShawn Calvert
 
Usability and User Experience
Usability and User ExperienceUsability and User Experience
Usability and User ExperienceShawn Calvert
 
User Centered Design
User Centered DesignUser Centered Design
User Centered DesignShawn Calvert
 
Class Intro / HTML Basics
Class Intro / HTML BasicsClass Intro / HTML Basics
Class Intro / HTML BasicsShawn Calvert
 
Web Design 101
Web Design 101Web Design 101
Web Design 101T.S. Lim
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheLeslie Samuel
 

Destacado (13)

Basics of Web Navigation
Basics of Web NavigationBasics of Web Navigation
Basics of Web Navigation
 
Web Design Process
Web Design ProcessWeb Design Process
Web Design Process
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to Responsive Web Design
 
10 Usability & UX Guidelines
10 Usability & UX Guidelines10 Usability & UX Guidelines
10 Usability & UX Guidelines
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQuery
 
Creating Images for the Web
Creating Images for the WebCreating Images for the Web
Creating Images for the Web
 
Usability and User Experience
Usability and User ExperienceUsability and User Experience
Usability and User Experience
 
User Centered Design
User Centered DesignUser Centered Design
User Centered Design
 
Class Intro / HTML Basics
Class Intro / HTML BasicsClass Intro / HTML Basics
Class Intro / HTML Basics
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Web Design 101
Web Design 101Web Design 101
Web Design 101
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar a CSS Foundations, pt 2 (20)

Css basics
Css basicsCss basics
Css basics
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
CSS: How To Learn Easily
CSS: How To Learn EasilyCSS: How To Learn Easily
CSS: How To Learn Easily
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Css
CssCss
Css
 
Webpage style with CSS
Webpage style with CSSWebpage style with CSS
Webpage style with CSS
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
 
What is css
What is cssWhat is css
What is css
 
CSS
CSSCSS
CSS
 
Internet tech &amp; web prog. p4,5
Internet tech &amp; web prog.  p4,5Internet tech &amp; web prog.  p4,5
Internet tech &amp; web prog. p4,5
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
 
Web Programming-css.pptx
Web Programming-css.pptxWeb Programming-css.pptx
Web Programming-css.pptx
 
Css notes
Css notesCss notes
Css notes
 
Css
CssCss
Css
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Css
CssCss
Css
 

Más de Shawn Calvert

Web Design I Syllabus 22 3375-03
Web Design I Syllabus 22 3375-03Web Design I Syllabus 22 3375-03
Web Design I Syllabus 22 3375-03Shawn Calvert
 
HTML Foundations, part 1
HTML Foundations, part 1HTML Foundations, part 1
HTML Foundations, part 1Shawn Calvert
 
Web Design 1: Introductions
Web Design 1: IntroductionsWeb Design 1: Introductions
Web Design 1: IntroductionsShawn Calvert
 
22-3530, Photo Communications Syllabus
22-3530, Photo Communications Syllabus22-3530, Photo Communications Syllabus
22-3530, Photo Communications SyllabusShawn Calvert
 
An Overview of Stock Photography
An Overview of Stock PhotographyAn Overview of Stock Photography
An Overview of Stock PhotographyShawn Calvert
 
Typography I syllabus
Typography I syllabusTypography I syllabus
Typography I syllabusShawn Calvert
 

Más de Shawn Calvert (11)

Web Design I Syllabus 22 3375-03
Web Design I Syllabus 22 3375-03Web Design I Syllabus 22 3375-03
Web Design I Syllabus 22 3375-03
 
HTML Foundations, part 1
HTML Foundations, part 1HTML Foundations, part 1
HTML Foundations, part 1
 
Web Design 1: Introductions
Web Design 1: IntroductionsWeb Design 1: Introductions
Web Design 1: Introductions
 
22-3530, Photo Communications Syllabus
22-3530, Photo Communications Syllabus22-3530, Photo Communications Syllabus
22-3530, Photo Communications Syllabus
 
An Overview of Stock Photography
An Overview of Stock PhotographyAn Overview of Stock Photography
An Overview of Stock Photography
 
Color Photography
Color PhotographyColor Photography
Color Photography
 
PSA posters
PSA postersPSA posters
PSA posters
 
Composition & Light
Composition & LightComposition & Light
Composition & Light
 
of Pixels and Bits
of Pixels and Bitsof Pixels and Bits
of Pixels and Bits
 
Camera basics
Camera basics Camera basics
Camera basics
 
Typography I syllabus
Typography I syllabusTypography I syllabus
Typography I syllabus
 

Último

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Último (20)

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

CSS Foundations, pt 2

  • 1. CSS Foundations, pt 2 22-3375 Web Design I // Columbia College Chicago
  • 2. Review
 What is css and how it’s relationship to your html files Three different approaches to applying your css to the html How the browser interprets the “cascade” of style rules How to write CSS rules Understand basic css properties for text styling How to add class and id selectors to your html for more styling control
  • 3. How to add css to your document
  • 4. There are 2 basic ways to add styles to your html page:
 External (linked)
 <head> Internal

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

  • 9. Class Exercise ! ! download class tutorial files create new css file in ‘review’ folder link to the css file from review.html file 

  • 12. Type (element) Selectors 
 body {declaration}
 p {declaration}
 h1 {declaration}
 ul {declaration}
 The simplest selector is the type selector, which targets an html element by name.
  • 13. The essential selector types (elements)
 Primary
 Structure Body
 Elements Formatting
 Elements html p em body br i h1 – h6 strong ul b ol q a blockquote img span div
  • 14. div elements
 Div elements allow you to group a set of elements together in one block-level element. ! 
 <div id=”head”> <a bunch of elements></> </div>

  • 15. span elements
 span elements are the inline equivalent of divs. ! <p>Here is some text <span class=”red-text”> with a span</span> added.</p> 
 Spans are the equivalent of ‘character’ styles 
 in InDesign.

  • 16. type selectors vs IDs & Classes
 Type selectors use the tag names that are built into HTML. 
 IDs and classes use names that you define, and are added to html elements to make them more specific.

  • 17. ID Selectors
 
 #logo {declaration}" CSS 
 <img id=”logo” src=”” alt=””>
 HTML An ID is an html attribute that is added to your html markup. You reference that ID in your css with a hash.
  • 18. Class Selectors
 
 .ingredients {declaration}" CSS 
 <ul class=”ingredients”>
 HTML A class is an html attribute that is added to your html markup. You reference that ID in your css with a period.
  • 19. IDs vs Classes
 The most important difference between IDs and classes is that there can be only one ID on a page, but multiple classes. An ID is more specific than a class. An element can have both an ID and multiple classes.
  • 20. IDs vs Classes
 ID: #344-34-4344 Class: Male Class: Student ID: #123-54-9877 Class: Female Class: Student
  • 21. Descendant Selectors
 CSS
 #sidebar .author {declaration}" HTML
 <div id=”sidebar”>
 <p class=”author”></p>
 </div>
 
 A space between two selectors indicates a descendant selector. In the example above, the style is targeted to an element with the class “author” inside the id “sidebar”.
  • 22. Multiple classes
 CSS
 .ingredients.time {declaration}" HTML
 <div class=”ingredients time”>
 <h1></h1>
 </div>
 
 Elements can have multiple classes, giving you more control. The are written in the CSS in the exact order they appear in the html, with no spaces.
  • 23. 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. While an element can have only one id, it can have multiple classes.
  • 24. Class Exercise ! Copy the following values from another site: 

  • 25. The Box Model:
 Defining the dimensions
  • 26. There are five basic properties for defining your “boxes”: display width and height padding margins border

  • 27. CSS Box Model All HTML elements can be considered as boxes or blocks. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content. ! Inspect Element 3d view in Firefox
  • 28. Total dimensions The actual width or height of any object is the total of the content width, padding, borders, and margins. .size-me {
 width: 200px; 
 padding: 10px;
 border: 2px;
 margin: 20px;
 }" The actual width: 254px content: 200px
 padding-left: 10px
 padding-right: 10px
 border-right: 2px
 border-left: 2px
 margin-right: 20px
 margin-left: 20px

  • 29. Display property By default, certain elements in your html have a display property of inline or block. Block elements takes up the full width available, and forces a line above and below. Examples include <p>, <div>, <ul>, <blockquote> and all headers. 
 <div></div> <p></p> <ul></ul>
  • 30. Display property Inline elements can be inserted within block elements or other inline elements and do no create additional space or line breaks. Examples include <img>, <em>, <strong>, <a>, and <span>. 
 <p> <p></p> <p></p> <a></a> </p>
  • 31. Display property There are four values that you can give to the display property: display: block; display: inline; display: inline-block; display: none ! Inline-block is a special value that allows an element to stay inline with its containing element, but allows you to control it’s dimensions as if it were a block element. display: none removes the element. 

  • 32. Display property For example, by default, a <li> element is set to display: block. If we change that value in our css to: li {display: inline-block;} Then this: Changes to this:
 <ul> <ul> <li> </li> <li> </li> <ul> <li> <ul> </li> <li> </li>
  • 33. Class Exercise ! 1 Inline and Block 

  • 34. Class Exercise ! 2 Borders and Margins 

  • 35. Defining dimension: width and height You can set the width and height of any element that has a display property of block or inline-block. As with type, you can set dimension in pixels (px), ems, or percentage (%). Setting any width with pixels is referred to as fixed-width, and setting width in ems or percentages is referred to as flexible-width. .size-me {
 width: 200px; 
 height: 200px;
 } ! !
  • 36. Defining dimension: min- and maxInstead of absolutely defining the width and height of your elements, you can set minimum and maximum widths and heights. This allows you to resize elements based on the browser or their parent elements. The idea of creating flexible content that adjusts to the user’s browser/device is at the core of what is referred to as responsive design. .size-me {
 min-width: 200px; 
 max-width: 100px;
 }"
  • 37. Defining dimension: min-width and max-width ! ! !
  • 38. Defining dimension: min-width and max-width ! ! !
  • 39. Defining padding & margins You can set the padding and margin properties of any element in css. Margin and padding dimensions can be also pixels (px), ems, or percentage (%). .space-me {
 padding: 10px; 
 margin-bottom: 20px;
 } ! ! !
  • 40. Defining padding & margins While you can add padding and margins to inline elements, not all of your properties will apply (vertical spacing, see below). ! ! !
  • 41. Collapsing margins
 When two or more margins collapse, the resulting margin width is the maximum of the collapsing margins' widths. In the example below, box1 has a taller margin than box2, so only that margin will be used (not added together). ! !
  • 42. CSS Shorthand
 When setting sizes for padding, margins and borders, instead of this: .box {
 padding-top: 10px; 
 padding-right: 15px;
 padding-bottom: 10px; 
 padding-left: 15px;
 } 1 4 2 Use this: .box {
 padding: 10px 15px 10px 15px;
 }" The values start at the top and go around the element clockwise. ! 3
  • 43. CSS Shorthand
 If your top/bottom and left/right values are the same, you can shorten the declaration even more: .box {
 padding: 10px 15px;
 }" Where the first value is for the top and bottom, and the second is for left and right. ! ! 1 2 2 1
  • 44. Defining borders You can create a border around any element with css; you can create the same border on each side, or customize the color, width and border style of each side. ! There are 3 properties to define with each border: 
 border-width: 1px; border-style: solid; (dotted, dashed, etc) border color: #666666; ! ! !
  • 45. CSS Shorthand
 Borders can also be shortened, from this: .box {
 border-width: 1px;
 border-style: solid;
 border-color: #888888
 }" to this: .box {
 border: 1px solid #888888;
 }" Note that there is only a single space between each value, and they should follow the order shown above. !
  • 46. Defining borders 
 h3 {
 border-bottom: 1px solid #444444;
 } ! !
  • 47. Class Exercise ! 3 Centered, Fixed-Width Page 

  • 49. There are four basic declarations 
 you can use to position your boxes: float: left (or right) position: relative position: fixed position: absolute

  • 50. position: static Static positioning is the default – this is referred to as the “normal flow”. block boxes are positioned on a page one after the other (in the order they're written in the HTML). They start in the upper left of the containing box and stack from top to bottom. The distance between each box is defined by the margins with top and bottom margins collapsing into one another. ! ! <div id=”header”></div> ! <div id=”content”></div> <ul id=”sidebar-nav”></ul>
  • 51.
  • 52.
  • 53. float A floated element takes the element out of the normal flow and moves it to the far right or left of the containing element. Existing content will then flow around it. Floated elements should always have at least a width property. .photo {
 float: left;
 max-width: 150px;
 }" ! !
  • 54. 4 Float ! 
 .photo {
 float: left;
 max-width: 150px;
 }" ! !
  • 56. Positioning Properties There are four values that you can give to the position property: ! static Elements renders in order, as they appear in the document flow. This is default. relative The element is positioned relative to its static position, so “left:20” adds 20 pixels to the element’s LEFT position. absolute The element is positioned relative to its first positioned (not static) ancestor element (usually, the first parent with position:relative). 
 fixed The element is positioned relative to the browser window.
  • 57. boxes exercise .box {
 "" width: 300px;
 "" height: 300px;
 "" border: 1px solid #333;
 "" margin: 10px;
 "" display: inline-block;
 }" " .relative {
 "" position: relative;
 "" top: 50px;
 "" left: -50px;
 }" .fixed {
 "" position: fixed;
 "" bottom: 0;
 "" left: 0;
 }" !
  • 58. boxes exercise .box.absolute {
 "" position: relative;
 }" .box.absolute p {
 "" position: absolute;
 "" top: 0;
 "" right: 0;
 "" background: #444;
 "" padding: 10px;
 "" margin: 0;
 "" color: #fff;
 }" ! ! !
  • 59. relative A relative positioned element moves the element out of it’s position in the normal flow, and allows you to move it “relative” to that location. The space taken by the original location is retained in the flow. .date {
 position: relative;
 top: 40px;
 left: -105px;
 }" ! !
  • 60. relative exercise ! ! ! ! ! .date {
 position: relative;
 top: 40px;
 left: -105px;
 }"
  • 61. fixed A fixed element is taken complete out of the document flow, and is positioned relative to the browser window.
 .create-change {
 position: fixed;
 bottom: 40px;
 right: 0;
 }" ! !
  • 62. fixed exercise ! ! ! ! ! .create-change {
 position: fixed;
 bottom: 40px;
 right: 0;
 }"
  • 63. absolute The element is positioned relative to its first positioned (not static) ancestor element. The element and its spacing are completely taken out of the flow. In the example below, the “.post” parent element is given a position value of relative, which lets us set it’s child element “.icon” within it.
 .post {
 position: relative;
 }" .icon {
 position: absolute;
 left: -60px;
 right: 0;
 }" ! !
  • 64. absolute exercise ! ! ! .post {
 position: relative;
 }" .icon {
 position: absolute;
 left: -60px;
 right: 0;
 }" ! !