SlideShare une entreprise Scribd logo
1  sur  68
The Basics of
Cascading Style Sheets (CSS)
CSS
1. What is CSS?
2. CSS & HTML
3. The Box Model
4. Style Sheet Implementation
5. CSS Rule Structure
6. HTML & DIVs
7. Common CSS properties
8. CSS Cascade and Inheritance
9. Resources
The Purpose of CSS
If HTML is the content and meaning
➡CSS helps to convey that meaning
Allows developers to separate the content
from layout and design
Content and design inherently different in
nature
➡ Change in content does not require change in
design
What is CSS?
CSS stands for
Cascading Style Sheet.
Typical CSS file is a text
file with an extention.css
and contains a series of
commands or rules.
These rules tell the
HTML how to display.
*To create a style sheet, create a file
using Notepad (PC) or Text Edit
(Mac), save it as a .css document and
start writing the CSS code (see right).
/* Styles for sitename.com*/
body {
font-family:Arial;
background: #000;
}
#container {
text-align:left;
width:1020px;
}
#header {
height:232px;
}
#footer {
width: 100%;
padding: 0 10px;
margin-bottom: 10px;
}
And so on….
Style.css
CSS Benefits
• Separates structure from presentation
• Provides advanced control of presentation
• Easy maintenance of multiple pages
• Faster page loading
• Better accessibility for disabled users
• Easy to learn
Need:
• An external style sheet has many advantages. Keeping the
styles separate from your HTML content:
• Helps avoid duplication
• Makes maintenance easier
• Allows you to make a site-wide change in one place
• CSS Saves Your Time in designing
• CSS Saves Your Visitors Time
• CSS Gives You Design Flexibility
• Separation of content and display
• More options for displaying content
• Efficiency
 A CSS (cascading style sheet) file allows you to separate
your web sites (X)HTML content from it’s style.
 All of the presentation (fonts, colors, background, borders,
text formatting, link effects & so on…) are accomplished
within a CSS.
HTML Without CSS
Without CSS, HTML
elements typically flow from
top to bottom of the page
and position themselves to
the left by default.
With CSS help, we can
create containers or DIVs to
better organize content and
make a Web page visually
appealing.
HTML & CSS
• HTML and CSS work together to produce
beautiful and functional Web sites
• HTML = structure
• CSS = style
The Box Model
CSS works on the
box model. A
typical Web page
consists of many
boxes joined
together from top
to bottom. These
boxes can be
stacked, nested,
and can float.
Header
Navigation
Content
Footer
Typical Web Page (Browser)
header
footer
mainmenu
Container
USING the CSS, either internally or externally.
• Internal Stylesheet
– this way you are simply placing the CSS code within the <head></head> tags of each
(X)HTML file you want to style with the CSS.
– This method can be good if you need to style only one page, or if you want different
pages to have varying styles.
• External Stylesheet
– An external CSS file can be created with any text or HTML editor such
as “Notepad” or “Dreamweaver”.
– A CSS file contains no (X)HTML, only CSS. You simply save it with
the .css file extension.
– You can link to the file externally by placing one of the following links
in the head section of every (X)HTML file you want to style with the
CSS file.
• By using an external style sheet, all of your (X)HTML files link
to one CSS file in order to style the pages.
• This means, that if you need to alter the design of all your pages,
you only need to edit one .css file to make global changes to
your entire website.
Here are a few reasons this is better.
•Easier Maintenance
•Reduced File Size
•Reduced Bandwidth
•Improved Flexibility
Attaching a Style Sheet
Attach a style sheet to a page by adding the code to the <head>
section of the HTML page. There are 3 ways to attach CSS to a page:
1. External Style Sheet: Best used to control styling on multiple pages.
<link rel="stylesheet" type="text/css"
media="all" href="css/styles.css" />
2. Internal Style Sheet: Best used to control styling on one page.
<style type=“text/css”>
h1 {color: red)
</style>
3. Inline Style Sheet*: CSS is not attached in the <header> but is used
directly within HTML tags.
<p style=“color: red”>Some Text</p>
CSS Rule Structure
A CSS RULE is made up of a selector and a
declaration.
A declaration consists of property and value.
selector {property: value;}
declaration
Selectors
body { property: value; }
h1 { property: value; }
em { property: value; }
p { property: value; }
A selector, here in green, is often an element of
HTML.
Properties and Values
body {background: purple;}
h1 {color: green; }
h2 {font-size: large;}
p {color: #ff0000;} /*hexadecimal for
red*/
body {
background: purple;
color: green;
}
Properties and values tell an HTML element how to display.
*CSS code can be written in a
linear format (above) or in a block
format (below).
Grouping Selectors
h1 {color: black;}
h1 {font-weight: bold;}
h1 {background: white;}
h1 {
color: black;
font-weight: bold;
background: white;
}
Group the same selector with different declarations
together on one line.
Example of grouping selectors (both are correct):
Grouping Selectors
Group different selectors with the same declaration on
one line.
h1 {color: yellow;}
h2 {color: yellow;}
h3 {color: yellow;}
h1, h2, h3 {color: yellow;}
Example of grouping selectors (both are correct):
Comments in CSS
• Explain the purpose of the coding
• Help others read and understand the code
• Serve as a reminder to you for what it all means
• Starts with /*and ends with*/
p {color: #ff0000;} /*Company Branding*/
Paragraph
• CSS code that does something HTML alone
could never do right… to indent every
paragraph automatically.
• Here's the CSS code:
• p { text-indent: 3em; }
Working with Paragraph
• p { text-indent: 3em; }
• Then, right before your </head> tag in each page add a line similar
to this:
• <link rel="stylesheet" type="text/css" href="main.css"
title="Default">
• This will link a new style sheet, location main.css, to each page.
The title field is optional.
Import
• Then, in those 2 special pages, you place the normal CSS link, but
you'll add special code,@import, to add the extra color.
– <link rel="stylesheet" type="text/css" href="main.css"
title="Default">
<style type="text/css">
<!--
@import url(coolblue.css);
--></style>
Basis overview
• Those are the basics. Let's review the ways you can include a style
sheet:
• Write it inline inside each and every tag
• Place a <style> </style> at the beginning of the web page
• Dedicate and link a CSS file and write it inside that file
• use @import to include it as portion of a page's CSS
Exercise 1
• Use <style> to make all paragraphs have 10 spaces indentation
(hint: 6em) and make the text red. Hint: Combine both into one
line of code using the ; separator. Remember to create a
paragraph in the <body> to see the style in action! Generic text
below.
» This is the first paragraph
with the red text and large indent.
» This is the second paragraph
with the red text and large indent.
Solution<html>
<head>
<style type="text/css">
<!--
p { text-indent: 6em; color: red; }
--></style>
</head>
<body>
<p>This is the first paragraph<br>
with the red text and large indent.</p>
<p>This is the second paragraph<br>
with the red text and large indent.</p>
</body>
</head>
</html>
Headers
• If you want to make all H1, H2, and H3 red, and all
H4, H5, H6 yellow, your style could look like this:
• h1, h2, h3 { color: red; }
h4, h5, h6 { color: yellow; }
• You can use the comma to say you want to define a
style for multiple selectors at the same time.
• You can set a style for nearly all HTML elements.
Selector a class of a current
element
• Every paragraph is now indented. But what if you want a few
paragraphs without an indent? We can define an extra selector.
• You can pick a name for these, I'm going to call minenoindent.
Here's the original code with an added noindent selector:
• p { text-indent: 3em; }
p.noindent { text-indent: 0em; }
• This says that any p that are part of a class called noindent should
use 0em indentation. To call that in code, we use class.
• A normal paragraph looks like this:
<p> I'm using a style with an indent. </p>
Normal paragraph
• A normal paragraph looks like this:
<p> I'm using a style with an indent. </p>
• I'm using a style with an indent.
• A paragraph with the noindent looks like this:
<p class="noindent"> I'm using a style without an indent. </p>
• We using a style without an indent.
• If you are going to only indent some paragraphs, but you probably won't
indent most, you can just define a special paragraph called indent.
p.indent { text-indent: 3em; }
• If that's our only style, regular <p> </p> will have no indent, while <p
class="indent"> </p> will have a 3em indentation.
This h1 has an indent.
• Imagine a selector .g, defined as { color: green;
}. Every time you use class="g" in an element
the text color would be shown in green.
• ID selectors are used for special formatting
of only a few elements. ID selectors use
a # instead of a .. Imagine 3 paragraphs, we'll
call them par1, par2, par3. We'll make one red,
one orange, and one blue.
This h1 has an indent con’t
• We could use these styles:
• p#par1 { color: red; }
p#par2 { color: orange; }
p#par3 { color: blue; }
<p id="par1">I'm in red</p>
<p id="par2">I'm in orange</p>
<p id="par3">I'm in blue</p>
• ID Selectors can also be element-less:
• #par1 { color: red; }
• ...would apply to all tags that specify id="par1".
PSEUDO-ELEMENTS
• There are two important pseudo-elements that are built into CSS
capable web browsers. (There are also common pseudo-classes
which you'll learn in the links chapter.)
• These two elements are :first-letter and :first-line. Notice that
pseudo-elements are defined with a : instead of a . or # (this is
because they have special meanings to a web browser).
• Here's a silly example for each: Imagine you want the first letter
of each paragraph to be red, or the first-line of each paragraph to
be green.
• p:first-letter { color: red; }
p:first-line { color: green; }
CSS Background, Image and Color
Styles
• You are probably familiar with the <body> tag. A
typical <body> tag looks something like this:
• <body background="graphic.jpg" text="#FFFFFF"
bgcolor="#000000">
• To convert that into CSS, it looks like this:
• body { background-image: url(graphic.jpg);
color: #FFFFFF; background-color: #000000; }
Con’t
• Big deal right?
• But CSS adds some special features. One of the most important
is thebackground-repeat property.
• It has these values: repeat, repeat-x, repeat-y, or no-repeat. A
regular web page has a default of background-repeat: repeat,
which means the image is repeated both horizontally and
vertically. With CSS, you can set the background to repeat
horizontally (repeat-x), repeat vertically (repeat-y), or not repeat
at all (no-repeat).
Images con’t
• We can edit the style mentioned above to have the body's
background never repeat by adding background-repeat: no-
repeat:
• body { background-image: url(graphic.jpg);
color: #FFFFFF; background-color: #000000;
background-repeat: no-repeat; }
• If you want to include the repeat in your standard background
tag (for example, if are not using CSS for the rest of your page),
you can add style="background-repeat: no-repeat;", so it looks
like this:
• <body background="graphic.jpg" text="#FFFFFF"
bgcolor="#000000" style="background-repeat: no-repeat;">
There are two more important
background
• properties: background-attachment andbackground-position.
• background-attachment merely allows you to decide if you want
the background to scroll or not. If you want it to scroll,
use background-attachment: scroll. If you want it to not scroll,
use background-attachment: fixed.
• background-position allows you to position the background. It
takes two values, the first is the the vertical position
(in px [pixels], % [percent], or top, center, bottom) and the second
value is the horizontal position (in px [pixels], % [percent],
or left, center, right).
Key features
• If you want a background to be at the top right,
use: background-position: top right. If you want
it to be at the bottom center, use background-
position: bottom center. This is typically most
useful used with background-repeat: no repeat.
Key Con’t
• As you can see, the coding for the background can get pretty
long. CSS lets you combine it all into a single property
statement, known as background. It follows this format:
• background: background-color || background-image ||
background-repeat || background-attachment || background-
position
• If you want a background color of white, a background
image lightpattern.jpg, the background to never repeat, and
never scroll, you could use:
• body { background: #FFFFFF url(lightpattern.jpg) no-repeat
fixed; }
Key Con’t
• Remember, you'll also need to set the text color, so add color: #000000 (if
you want black text)
• body { background: #FFFFFF url(lightpattern.jpg) no-repeat fixed; color:
#000000; }
• Notice that the browser is smart enough to realize that a value (in this case:
background-position) is missing and it ignores that value.
• Always set a text and bgcolor in <body> for full browser compatibility.
Try a background with an element other than
body. A good candidate is the p
• la la la la
•
• <html>
• <head>
• <style type="text/css">
• <!--
• body { background: #EEEEEE url(/graphx/back.jpg) repeat-y scroll; }
• --></style>
• </head>
• <body>la la la la
• </body>
• </html>
• <html><head><style type="text/css"><!-- body { background: #FFFFFF
url(/graphx/coddsite.gif) no-repeat fixed center left; }--
></style></head><body></body></html>
Typical Web Page (Browser)
header
footer
mainmenu
Container
Typical Web Page (HTML)
<div id=“container”>
<div id=“header”>Insert Title</div>
<div id=“main">content
<div id=“menu”>content</div>
</div>
<div id=“footer”>content</div>
</div>
Typical HTML Web page is made up of containers (boxes)
or DIVs. Each DIV is assigned an ID or a Class.
Typical Web Page (CSS)
#container {property: value;}
#menu {property: value;}
#main {property: value;}
#footer {property: value;}
The CSS file uses the same DIV/ID/Class names as the
HTML and uses them to style the elements.
IDs and Classes
• IDs (#) are unique and can only be used once on the page
• Classes (.) can be used as many times as needed
HTML Code:
<h1 id=“mainHeading”>Names</h1>
<p class=“name”>Joe</p>
CSS Code:
#mainHeading {color: green}
.name {color: red}
CSS Box Properties
• Background-color
• Width
• Padding
• Margin
• Border-width
• Border-color
• Border-style
HTML CSS
div id=“header”
div id=“footer”
div id=“content”
#content {
background-color: #ccc;
margin-bottom: 10px;
border: 1px dashed blue;
color: #fff;
width: auto;
}
The <div> tag
• The <div> tag is nothing more than a container unit that
encapsulates other page elements and divides the HTML
document into sections.
• Web developers use <div> elements to group together HTML
elements and apply CSS styles to many elements at once. For
instance, by wrapping a set of paragraph elements into a <div>
element, the we can take advantage of CSS styles and apply a
font to all paragraphs at once by applying a font style to the
<div> tag instead of coding the same style for each paragraph
element.
Common CSS Layout Properties
• Width
• Height
• Float
• Clear
• Border
• Padding
• Margin
width
height
padding
margin
border
Width & Height
div id=“box”
#box {width=“50px”}
#box {width=“50em”}
#box {width=“100%”}
#box {width=“auto”}
Width and height define the width and height of an element.
#box {height=“auto”}
*Width and height can be specified
in pixels, ems, percentages or set to
auto
Float: (left, right)
Float property makes elements float to the right or
left of the screen, positioned where they are in the
HTML. Floating allows word wrapping.
div id=“box”
Here is some text which
wraps around the box
floated to the left.
#box {float:left; margin-right: 10px;}
Clear: (left, right, both)
#box3 { background-color: white; border:
1px solid #000; clear: both;}
When elements are floated, they wrap around each other to
form a “caravan.” The clear property detaches an element
from the “caravan” and allows it to start on a new line.
div id=“box1” div id=“box2”
div id=“box3”
Border (top, right, bottom, left)
#box {
border-color: red;
border-style: dotted;
border-width: 2px;
div id=“box”
#box {
border: red dotted 1px;
}
#box {
border-top: red dotted 1px;
border-bottom: red dotted 1px;
border-left: red dotted 1px;
border-right: red dotted 1px;
}
You can define the entire border or
only the top, bottom, left, or right. You
can also define the border using one
declaration. The code could be any of
the following:
Padding (top, right, bottom, left)
Padding is the space between the text/content and the border. You can use
padding for all around the element or specify each side of the rectangle
separately.
The code could be any of the following:
padding: 10px;
Padding: 10px 10px;
padding: 10px 10px 10px 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-top: 10px;
div id=“box”
padding
Margin (top, right, bottom, left)
Margin is the space outside the text/content and the border. You can use
margin for all around the element or specify each side of the rectangle
separately.
The code could be any of the following:
margin: 10px;
or
margin: 10px 10px;
or
margin: 10px 10px 10px 10px;
or
margin-left: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-top: 10px;
margin
div id=“box”
Text Properties
.mainHeading {
color: red;
letter-spacing: 5px;
text-transform: uppercase;
word-spacing: 15px;
text-align: left;
font-family: Times;
text-decoration: underline;
font-size: 12px;
font-style: italic;
font-weight: bold;
}
M A I N H E A D I N G
Gravida lacinia velit.
Vivamus tortor enim,
tincidunt at, pellentesque ut,
iaculis eu, quam.
To style the main heading in
the paragraph above, we assigned
a class the HTML tag.
<h3 class=“mainHeading”>Main Heading</h3>
CSS Colors
• White
• Black
• Blue
• Fuchsia
• Gray
• Green
• Lime
• Aqua
• #ffffff
• #fff
• #cccf0f3
Standard Hexadecimal
Styling Links
a:link {color: red; text-decoration:
none;border-bottom: 1px dashed red;
background: white;}
a:visited {color: yellow;}
a:active {color: green;}
a:hover {color: orange;}
The links property defines how inactive, hovered,
active, and visited link states appear to the user.
Including Images
Properties for working with images include:
• Background-image
• Background-repeat
• Background-position
• Background-attachment
Layering
Background colors
and images are
layered like sheets
of paper one on top
of the other.
#bg {background:url(leaves.jpg) no-repeat top left}
#main {background-color: red}
#box {background-color: yellow}
div id=“bg”
div id=“main”
div id=“box”
Background-Image
li {
background-image:url(flower.jpg);
padding-left: 10px;
}
Background images and colors are layered.
If not transparent, the last one listed in the
CSS file is visible.
The background-image property sets an image
in the background of an element.
Background-Repeat
li {
background-image:url(flower.jpg);
background-repeat:no-repeat;
}
Possible Values >
The background-repeat property sets an
image in the background of an element and
tiles, or repeats, it. Tiling is the default.
• repeat
• repeat-x (horizontal)
• repeat-y (vertical)
• no-repeat
Image Positioning
The background-position
property positions the image
using either combined
keywords (top, bottom, left,
right, and center); length
values; or percentage values.
The background-
attachment property
fixes or scrolls an
image in the browser
window. Values include
fixed and scroll.
background-position: right top;
/*can also use number values*/
background-attachment: fixed;
/*can also use ‘scroll’*/
left
top
center
top
left
bottom
center
bottom
right
bottom
The Power of Cascade
When multiple styles or style sheets are used, they start to
cascade and sometimes compete with one another due to CSS’s
inheritance feature. Any tag on the page could potentially be
affected by any of the tags surrounded by it.
So, which one wins? Nearest Ancestor Wins.
1. Inline style or directly applied style
2. The last style sheet declared in the <header> section
Saving Time with Inheritance
In a nutshell, inheritance (not the money you get from your
grandma) is the process by which CSS properties applied to one
tag are passed on to nested tags.
For example, the paragraph tag will inherit the same styling as
the body tag because <p> is always located inside <body>.
<body style=“font-family: Arial”>
<p>This text will be Arial as well</p>
</body>
So, instead of styling each paragraph separately, you can define the font
color in the <body>, and everything inside will have that color.
Resources
• http://www.w3schools.com/css/css_reference.asp (list of all CSS properties)
• http://www.w3schools.com/css/
• http://www.glish.com/css/
• http://www.html.net/tutorials/css/
• http://blog.html.it/layoutgala/
Great Book
“CSS: The Missing Manual” - by David Sawyer McFarland
Thank You
I hope you enjoyed this presentation and learned
some basic CSS. I hope this will help with
creating beautiful and functional Web sites.

Contenu connexe

Tendances

Tendances (20)

Html and css
Html and cssHtml and css
Html and css
 
Html basics
Html basicsHtml basics
Html basics
 
Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSS
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
 
Html Intro2
Html Intro2Html Intro2
Html Intro2
 
Css ppt
Css pptCss ppt
Css ppt
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Basic Html Knowledge for students
Basic Html Knowledge for studentsBasic Html Knowledge for students
Basic Html Knowledge for students
 
Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
 
CSS
CSSCSS
CSS
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
Eye catching HTML BASICS tips: Learn easily
Eye catching HTML BASICS tips: Learn easilyEye catching HTML BASICS tips: Learn easily
Eye catching HTML BASICS tips: Learn easily
 
Html
HtmlHtml
Html
 
Html and css presentation
Html and css presentationHtml and css presentation
Html and css presentation
 
Html
HtmlHtml
Html
 
Css
CssCss
Css
 
Html ppt
Html pptHtml ppt
Html ppt
 

Similaire à Css Basics

Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for cssshabab shihan
 
Css introduction
Css introductionCss introduction
Css introductionSridhar P
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfelayelily
 
Css tutorial
Css tutorialCss tutorial
Css tutorialvedaste
 
Html Styles-CSS
Html Styles-CSSHtml Styles-CSS
Html Styles-CSSispkosova
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmitha273566
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8RohanMistry15
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmithaps4
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2Gheyath M. Othman
 
Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptxDaniyalSardar
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptxMattMarino13
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2Sónia
 

Similaire à Css Basics (20)

Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for css
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Css introduction
Css introductionCss introduction
Css introduction
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
CSS
CSSCSS
CSS
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdf
 
Lecture-6.pptx
Lecture-6.pptxLecture-6.pptx
Lecture-6.pptx
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 
Html Styles-CSS
Html Styles-CSSHtml Styles-CSS
Html Styles-CSS
 
Css
CssCss
Css
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
CSS
CSSCSS
CSS
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2
 
Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptx
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
 

Plus de Jay Patel

Design step for making slot antenna in HFSS
Design step for making slot antenna in HFSSDesign step for making slot antenna in HFSS
Design step for making slot antenna in HFSSJay Patel
 
Introduction to web20
Introduction to web20Introduction to web20
Introduction to web20Jay Patel
 
Mean square error
Mean square errorMean square error
Mean square errorJay Patel
 
Internet server components
Internet server componentsInternet server components
Internet server componentsJay Patel
 
Fractal Antenna
Fractal AntennaFractal Antenna
Fractal AntennaJay Patel
 
TLS in manet
TLS in manetTLS in manet
TLS in manetJay Patel
 
Continuous Random variable
Continuous Random variableContinuous Random variable
Continuous Random variableJay Patel
 
Global positioning system
Global positioning systemGlobal positioning system
Global positioning systemJay Patel
 
Net Nutrality
Net NutralityNet Nutrality
Net NutralityJay Patel
 
Energy density in electrostatic field
Energy density in electrostatic field Energy density in electrostatic field
Energy density in electrostatic field Jay Patel
 
different marketing concept
different marketing conceptdifferent marketing concept
different marketing conceptJay Patel
 
slew rate in opamp
slew rate in opampslew rate in opamp
slew rate in opampJay Patel
 
synathesized function generator
synathesized function generatorsynathesized function generator
synathesized function generatorJay Patel
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Jay Patel
 
Tracking in receivers
Tracking in receiversTracking in receivers
Tracking in receiversJay Patel
 
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...Jay Patel
 

Plus de Jay Patel (17)

Java script
Java scriptJava script
Java script
 
Design step for making slot antenna in HFSS
Design step for making slot antenna in HFSSDesign step for making slot antenna in HFSS
Design step for making slot antenna in HFSS
 
Introduction to web20
Introduction to web20Introduction to web20
Introduction to web20
 
Mean square error
Mean square errorMean square error
Mean square error
 
Internet server components
Internet server componentsInternet server components
Internet server components
 
Fractal Antenna
Fractal AntennaFractal Antenna
Fractal Antenna
 
TLS in manet
TLS in manetTLS in manet
TLS in manet
 
Continuous Random variable
Continuous Random variableContinuous Random variable
Continuous Random variable
 
Global positioning system
Global positioning systemGlobal positioning system
Global positioning system
 
Net Nutrality
Net NutralityNet Nutrality
Net Nutrality
 
Energy density in electrostatic field
Energy density in electrostatic field Energy density in electrostatic field
Energy density in electrostatic field
 
different marketing concept
different marketing conceptdifferent marketing concept
different marketing concept
 
slew rate in opamp
slew rate in opampslew rate in opamp
slew rate in opamp
 
synathesized function generator
synathesized function generatorsynathesized function generator
synathesized function generator
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
 
Tracking in receivers
Tracking in receiversTracking in receivers
Tracking in receivers
 
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...
Parson’s Turbine and condition for maximum efficiency of Parson’s reaction Tu...
 

Dernier

Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxeditsforyah
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationMarko4394
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 

Dernier (17)

Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentation
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 

Css Basics

  • 1. The Basics of Cascading Style Sheets (CSS)
  • 2. CSS 1. What is CSS? 2. CSS & HTML 3. The Box Model 4. Style Sheet Implementation 5. CSS Rule Structure 6. HTML & DIVs 7. Common CSS properties 8. CSS Cascade and Inheritance 9. Resources
  • 3. The Purpose of CSS If HTML is the content and meaning ➡CSS helps to convey that meaning Allows developers to separate the content from layout and design Content and design inherently different in nature ➡ Change in content does not require change in design
  • 4. What is CSS? CSS stands for Cascading Style Sheet. Typical CSS file is a text file with an extention.css and contains a series of commands or rules. These rules tell the HTML how to display. *To create a style sheet, create a file using Notepad (PC) or Text Edit (Mac), save it as a .css document and start writing the CSS code (see right). /* Styles for sitename.com*/ body { font-family:Arial; background: #000; } #container { text-align:left; width:1020px; } #header { height:232px; } #footer { width: 100%; padding: 0 10px; margin-bottom: 10px; } And so on…. Style.css
  • 5. CSS Benefits • Separates structure from presentation • Provides advanced control of presentation • Easy maintenance of multiple pages • Faster page loading • Better accessibility for disabled users • Easy to learn
  • 6. Need: • An external style sheet has many advantages. Keeping the styles separate from your HTML content: • Helps avoid duplication • Makes maintenance easier • Allows you to make a site-wide change in one place • CSS Saves Your Time in designing • CSS Saves Your Visitors Time • CSS Gives You Design Flexibility • Separation of content and display • More options for displaying content • Efficiency
  • 7.  A CSS (cascading style sheet) file allows you to separate your web sites (X)HTML content from it’s style.  All of the presentation (fonts, colors, background, borders, text formatting, link effects & so on…) are accomplished within a CSS.
  • 8. HTML Without CSS Without CSS, HTML elements typically flow from top to bottom of the page and position themselves to the left by default. With CSS help, we can create containers or DIVs to better organize content and make a Web page visually appealing.
  • 9. HTML & CSS • HTML and CSS work together to produce beautiful and functional Web sites • HTML = structure • CSS = style
  • 10. The Box Model CSS works on the box model. A typical Web page consists of many boxes joined together from top to bottom. These boxes can be stacked, nested, and can float. Header Navigation Content Footer
  • 11. Typical Web Page (Browser) header footer mainmenu Container
  • 12. USING the CSS, either internally or externally. • Internal Stylesheet – this way you are simply placing the CSS code within the <head></head> tags of each (X)HTML file you want to style with the CSS. – This method can be good if you need to style only one page, or if you want different pages to have varying styles.
  • 13. • External Stylesheet – An external CSS file can be created with any text or HTML editor such as “Notepad” or “Dreamweaver”. – A CSS file contains no (X)HTML, only CSS. You simply save it with the .css file extension. – You can link to the file externally by placing one of the following links in the head section of every (X)HTML file you want to style with the CSS file.
  • 14. • By using an external style sheet, all of your (X)HTML files link to one CSS file in order to style the pages. • This means, that if you need to alter the design of all your pages, you only need to edit one .css file to make global changes to your entire website.
  • 15. Here are a few reasons this is better. •Easier Maintenance •Reduced File Size •Reduced Bandwidth •Improved Flexibility
  • 16. Attaching a Style Sheet Attach a style sheet to a page by adding the code to the <head> section of the HTML page. There are 3 ways to attach CSS to a page: 1. External Style Sheet: Best used to control styling on multiple pages. <link rel="stylesheet" type="text/css" media="all" href="css/styles.css" /> 2. Internal Style Sheet: Best used to control styling on one page. <style type=“text/css”> h1 {color: red) </style> 3. Inline Style Sheet*: CSS is not attached in the <header> but is used directly within HTML tags. <p style=“color: red”>Some Text</p>
  • 17. CSS Rule Structure A CSS RULE is made up of a selector and a declaration. A declaration consists of property and value. selector {property: value;} declaration
  • 18. Selectors body { property: value; } h1 { property: value; } em { property: value; } p { property: value; } A selector, here in green, is often an element of HTML.
  • 19. Properties and Values body {background: purple;} h1 {color: green; } h2 {font-size: large;} p {color: #ff0000;} /*hexadecimal for red*/ body { background: purple; color: green; } Properties and values tell an HTML element how to display. *CSS code can be written in a linear format (above) or in a block format (below).
  • 20. Grouping Selectors h1 {color: black;} h1 {font-weight: bold;} h1 {background: white;} h1 { color: black; font-weight: bold; background: white; } Group the same selector with different declarations together on one line. Example of grouping selectors (both are correct):
  • 21. Grouping Selectors Group different selectors with the same declaration on one line. h1 {color: yellow;} h2 {color: yellow;} h3 {color: yellow;} h1, h2, h3 {color: yellow;} Example of grouping selectors (both are correct):
  • 22. Comments in CSS • Explain the purpose of the coding • Help others read and understand the code • Serve as a reminder to you for what it all means • Starts with /*and ends with*/ p {color: #ff0000;} /*Company Branding*/
  • 23. Paragraph • CSS code that does something HTML alone could never do right… to indent every paragraph automatically. • Here's the CSS code: • p { text-indent: 3em; }
  • 24. Working with Paragraph • p { text-indent: 3em; } • Then, right before your </head> tag in each page add a line similar to this: • <link rel="stylesheet" type="text/css" href="main.css" title="Default"> • This will link a new style sheet, location main.css, to each page. The title field is optional.
  • 25. Import • Then, in those 2 special pages, you place the normal CSS link, but you'll add special code,@import, to add the extra color. – <link rel="stylesheet" type="text/css" href="main.css" title="Default"> <style type="text/css"> <!-- @import url(coolblue.css); --></style>
  • 26. Basis overview • Those are the basics. Let's review the ways you can include a style sheet: • Write it inline inside each and every tag • Place a <style> </style> at the beginning of the web page • Dedicate and link a CSS file and write it inside that file • use @import to include it as portion of a page's CSS
  • 27. Exercise 1 • Use <style> to make all paragraphs have 10 spaces indentation (hint: 6em) and make the text red. Hint: Combine both into one line of code using the ; separator. Remember to create a paragraph in the <body> to see the style in action! Generic text below. » This is the first paragraph with the red text and large indent. » This is the second paragraph with the red text and large indent.
  • 28. Solution<html> <head> <style type="text/css"> <!-- p { text-indent: 6em; color: red; } --></style> </head> <body> <p>This is the first paragraph<br> with the red text and large indent.</p> <p>This is the second paragraph<br> with the red text and large indent.</p> </body> </head> </html>
  • 29. Headers • If you want to make all H1, H2, and H3 red, and all H4, H5, H6 yellow, your style could look like this: • h1, h2, h3 { color: red; } h4, h5, h6 { color: yellow; } • You can use the comma to say you want to define a style for multiple selectors at the same time. • You can set a style for nearly all HTML elements.
  • 30. Selector a class of a current element • Every paragraph is now indented. But what if you want a few paragraphs without an indent? We can define an extra selector. • You can pick a name for these, I'm going to call minenoindent. Here's the original code with an added noindent selector: • p { text-indent: 3em; } p.noindent { text-indent: 0em; } • This says that any p that are part of a class called noindent should use 0em indentation. To call that in code, we use class. • A normal paragraph looks like this: <p> I'm using a style with an indent. </p>
  • 31. Normal paragraph • A normal paragraph looks like this: <p> I'm using a style with an indent. </p> • I'm using a style with an indent. • A paragraph with the noindent looks like this: <p class="noindent"> I'm using a style without an indent. </p> • We using a style without an indent. • If you are going to only indent some paragraphs, but you probably won't indent most, you can just define a special paragraph called indent. p.indent { text-indent: 3em; } • If that's our only style, regular <p> </p> will have no indent, while <p class="indent"> </p> will have a 3em indentation.
  • 32. This h1 has an indent. • Imagine a selector .g, defined as { color: green; }. Every time you use class="g" in an element the text color would be shown in green. • ID selectors are used for special formatting of only a few elements. ID selectors use a # instead of a .. Imagine 3 paragraphs, we'll call them par1, par2, par3. We'll make one red, one orange, and one blue.
  • 33. This h1 has an indent con’t • We could use these styles: • p#par1 { color: red; } p#par2 { color: orange; } p#par3 { color: blue; } <p id="par1">I'm in red</p> <p id="par2">I'm in orange</p> <p id="par3">I'm in blue</p> • ID Selectors can also be element-less: • #par1 { color: red; } • ...would apply to all tags that specify id="par1".
  • 34. PSEUDO-ELEMENTS • There are two important pseudo-elements that are built into CSS capable web browsers. (There are also common pseudo-classes which you'll learn in the links chapter.) • These two elements are :first-letter and :first-line. Notice that pseudo-elements are defined with a : instead of a . or # (this is because they have special meanings to a web browser). • Here's a silly example for each: Imagine you want the first letter of each paragraph to be red, or the first-line of each paragraph to be green. • p:first-letter { color: red; } p:first-line { color: green; }
  • 35. CSS Background, Image and Color Styles • You are probably familiar with the <body> tag. A typical <body> tag looks something like this: • <body background="graphic.jpg" text="#FFFFFF" bgcolor="#000000"> • To convert that into CSS, it looks like this: • body { background-image: url(graphic.jpg); color: #FFFFFF; background-color: #000000; }
  • 36. Con’t • Big deal right? • But CSS adds some special features. One of the most important is thebackground-repeat property. • It has these values: repeat, repeat-x, repeat-y, or no-repeat. A regular web page has a default of background-repeat: repeat, which means the image is repeated both horizontally and vertically. With CSS, you can set the background to repeat horizontally (repeat-x), repeat vertically (repeat-y), or not repeat at all (no-repeat).
  • 37. Images con’t • We can edit the style mentioned above to have the body's background never repeat by adding background-repeat: no- repeat: • body { background-image: url(graphic.jpg); color: #FFFFFF; background-color: #000000; background-repeat: no-repeat; } • If you want to include the repeat in your standard background tag (for example, if are not using CSS for the rest of your page), you can add style="background-repeat: no-repeat;", so it looks like this: • <body background="graphic.jpg" text="#FFFFFF" bgcolor="#000000" style="background-repeat: no-repeat;">
  • 38. There are two more important background • properties: background-attachment andbackground-position. • background-attachment merely allows you to decide if you want the background to scroll or not. If you want it to scroll, use background-attachment: scroll. If you want it to not scroll, use background-attachment: fixed. • background-position allows you to position the background. It takes two values, the first is the the vertical position (in px [pixels], % [percent], or top, center, bottom) and the second value is the horizontal position (in px [pixels], % [percent], or left, center, right).
  • 39. Key features • If you want a background to be at the top right, use: background-position: top right. If you want it to be at the bottom center, use background- position: bottom center. This is typically most useful used with background-repeat: no repeat.
  • 40. Key Con’t • As you can see, the coding for the background can get pretty long. CSS lets you combine it all into a single property statement, known as background. It follows this format: • background: background-color || background-image || background-repeat || background-attachment || background- position • If you want a background color of white, a background image lightpattern.jpg, the background to never repeat, and never scroll, you could use: • body { background: #FFFFFF url(lightpattern.jpg) no-repeat fixed; }
  • 41. Key Con’t • Remember, you'll also need to set the text color, so add color: #000000 (if you want black text) • body { background: #FFFFFF url(lightpattern.jpg) no-repeat fixed; color: #000000; } • Notice that the browser is smart enough to realize that a value (in this case: background-position) is missing and it ignores that value. • Always set a text and bgcolor in <body> for full browser compatibility.
  • 42. Try a background with an element other than body. A good candidate is the p • la la la la • • <html> • <head> • <style type="text/css"> • <!-- • body { background: #EEEEEE url(/graphx/back.jpg) repeat-y scroll; } • --></style> • </head> • <body>la la la la • </body> • </html> • <html><head><style type="text/css"><!-- body { background: #FFFFFF url(/graphx/coddsite.gif) no-repeat fixed center left; }-- ></style></head><body></body></html>
  • 43. Typical Web Page (Browser) header footer mainmenu Container
  • 44. Typical Web Page (HTML) <div id=“container”> <div id=“header”>Insert Title</div> <div id=“main">content <div id=“menu”>content</div> </div> <div id=“footer”>content</div> </div> Typical HTML Web page is made up of containers (boxes) or DIVs. Each DIV is assigned an ID or a Class.
  • 45. Typical Web Page (CSS) #container {property: value;} #menu {property: value;} #main {property: value;} #footer {property: value;} The CSS file uses the same DIV/ID/Class names as the HTML and uses them to style the elements.
  • 46. IDs and Classes • IDs (#) are unique and can only be used once on the page • Classes (.) can be used as many times as needed HTML Code: <h1 id=“mainHeading”>Names</h1> <p class=“name”>Joe</p> CSS Code: #mainHeading {color: green} .name {color: red}
  • 47. CSS Box Properties • Background-color • Width • Padding • Margin • Border-width • Border-color • Border-style
  • 48. HTML CSS div id=“header” div id=“footer” div id=“content” #content { background-color: #ccc; margin-bottom: 10px; border: 1px dashed blue; color: #fff; width: auto; }
  • 49. The <div> tag • The <div> tag is nothing more than a container unit that encapsulates other page elements and divides the HTML document into sections. • Web developers use <div> elements to group together HTML elements and apply CSS styles to many elements at once. For instance, by wrapping a set of paragraph elements into a <div> element, the we can take advantage of CSS styles and apply a font to all paragraphs at once by applying a font style to the <div> tag instead of coding the same style for each paragraph element.
  • 50. Common CSS Layout Properties • Width • Height • Float • Clear • Border • Padding • Margin width height padding margin border
  • 51. Width & Height div id=“box” #box {width=“50px”} #box {width=“50em”} #box {width=“100%”} #box {width=“auto”} Width and height define the width and height of an element. #box {height=“auto”} *Width and height can be specified in pixels, ems, percentages or set to auto
  • 52. Float: (left, right) Float property makes elements float to the right or left of the screen, positioned where they are in the HTML. Floating allows word wrapping. div id=“box” Here is some text which wraps around the box floated to the left. #box {float:left; margin-right: 10px;}
  • 53. Clear: (left, right, both) #box3 { background-color: white; border: 1px solid #000; clear: both;} When elements are floated, they wrap around each other to form a “caravan.” The clear property detaches an element from the “caravan” and allows it to start on a new line. div id=“box1” div id=“box2” div id=“box3”
  • 54. Border (top, right, bottom, left) #box { border-color: red; border-style: dotted; border-width: 2px; div id=“box” #box { border: red dotted 1px; } #box { border-top: red dotted 1px; border-bottom: red dotted 1px; border-left: red dotted 1px; border-right: red dotted 1px; } You can define the entire border or only the top, bottom, left, or right. You can also define the border using one declaration. The code could be any of the following:
  • 55. Padding (top, right, bottom, left) Padding is the space between the text/content and the border. You can use padding for all around the element or specify each side of the rectangle separately. The code could be any of the following: padding: 10px; Padding: 10px 10px; padding: 10px 10px 10px 10px; padding-left: 10px; padding-right: 10px; padding-bottom: 10px; padding-top: 10px; div id=“box” padding
  • 56. Margin (top, right, bottom, left) Margin is the space outside the text/content and the border. You can use margin for all around the element or specify each side of the rectangle separately. The code could be any of the following: margin: 10px; or margin: 10px 10px; or margin: 10px 10px 10px 10px; or margin-left: 10px; margin-right: 10px; margin-bottom: 10px; margin-top: 10px; margin div id=“box”
  • 57. Text Properties .mainHeading { color: red; letter-spacing: 5px; text-transform: uppercase; word-spacing: 15px; text-align: left; font-family: Times; text-decoration: underline; font-size: 12px; font-style: italic; font-weight: bold; } M A I N H E A D I N G Gravida lacinia velit. Vivamus tortor enim, tincidunt at, pellentesque ut, iaculis eu, quam. To style the main heading in the paragraph above, we assigned a class the HTML tag. <h3 class=“mainHeading”>Main Heading</h3>
  • 58. CSS Colors • White • Black • Blue • Fuchsia • Gray • Green • Lime • Aqua • #ffffff • #fff • #cccf0f3 Standard Hexadecimal
  • 59. Styling Links a:link {color: red; text-decoration: none;border-bottom: 1px dashed red; background: white;} a:visited {color: yellow;} a:active {color: green;} a:hover {color: orange;} The links property defines how inactive, hovered, active, and visited link states appear to the user.
  • 60. Including Images Properties for working with images include: • Background-image • Background-repeat • Background-position • Background-attachment
  • 61. Layering Background colors and images are layered like sheets of paper one on top of the other. #bg {background:url(leaves.jpg) no-repeat top left} #main {background-color: red} #box {background-color: yellow} div id=“bg” div id=“main” div id=“box”
  • 62. Background-Image li { background-image:url(flower.jpg); padding-left: 10px; } Background images and colors are layered. If not transparent, the last one listed in the CSS file is visible. The background-image property sets an image in the background of an element.
  • 63. Background-Repeat li { background-image:url(flower.jpg); background-repeat:no-repeat; } Possible Values > The background-repeat property sets an image in the background of an element and tiles, or repeats, it. Tiling is the default. • repeat • repeat-x (horizontal) • repeat-y (vertical) • no-repeat
  • 64. Image Positioning The background-position property positions the image using either combined keywords (top, bottom, left, right, and center); length values; or percentage values. The background- attachment property fixes or scrolls an image in the browser window. Values include fixed and scroll. background-position: right top; /*can also use number values*/ background-attachment: fixed; /*can also use ‘scroll’*/ left top center top left bottom center bottom right bottom
  • 65. The Power of Cascade When multiple styles or style sheets are used, they start to cascade and sometimes compete with one another due to CSS’s inheritance feature. Any tag on the page could potentially be affected by any of the tags surrounded by it. So, which one wins? Nearest Ancestor Wins. 1. Inline style or directly applied style 2. The last style sheet declared in the <header> section
  • 66. Saving Time with Inheritance In a nutshell, inheritance (not the money you get from your grandma) is the process by which CSS properties applied to one tag are passed on to nested tags. For example, the paragraph tag will inherit the same styling as the body tag because <p> is always located inside <body>. <body style=“font-family: Arial”> <p>This text will be Arial as well</p> </body> So, instead of styling each paragraph separately, you can define the font color in the <body>, and everything inside will have that color.
  • 67. Resources • http://www.w3schools.com/css/css_reference.asp (list of all CSS properties) • http://www.w3schools.com/css/ • http://www.glish.com/css/ • http://www.html.net/tutorials/css/ • http://blog.html.it/layoutgala/ Great Book “CSS: The Missing Manual” - by David Sawyer McFarland
  • 68. Thank You I hope you enjoyed this presentation and learned some basic CSS. I hope this will help with creating beautiful and functional Web sites.

Notes de l'éditeur

  1. 1
  2. 2
  3. 4
  4. 5
  5. 8
  6. 9
  7. 10
  8. 11
  9. 16
  10. 17
  11. 18
  12. 19
  13. 20
  14. 21
  15. 22
  16. 43
  17. 44
  18. 45
  19. 46
  20. 47
  21. 48
  22. 50
  23. 51
  24. 52
  25. 53
  26. 54
  27. 55
  28. 56
  29. 57
  30. 58
  31. 59
  32. 60
  33. 61
  34. 62
  35. 63
  36. 64
  37. 65
  38. 66
  39. 67
  40. 68