Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer...

21
Introduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning www.NetComLearning.com © Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Transcript of Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer...

Page 1: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Introduction to

CSSMeganadha Reddy K.

Technical Trainer | NetCom Learning

www.NetComLearning.com

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 2: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Advantages of Style Sheets

• Saves time

• Easy to change

• Keep consistency

• Give you more control over layout

• Make it easy to create a common format for

all the Web pages

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 3: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Applying a single style sheet to

multiple documents

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 4: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Basic Structure of a Style

• Each definition contains:

• A property

• A colon

• A value

• A semicolon to separate two or more values

• Can include one or more values

• h1 {font-size:12pt; color:red}

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 5: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Style Precedence

1. External style sheet

2. Embedded styles

3. Inline styles

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 6: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Three Style Types

• Inline styles

• Add styles to each tag within the HTML file

• Use it when you need to format just a single section in a web

page

• Example

• <h1 style=“color:red; font-family: sans-sarif ”>IU</h1>

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 7: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Three Style Types

• Embedded or internal styles

• A style is applied to the entire HTML file

• Use it when you need to modify all instances of particular element (e.g., h1) in a web page

• Example

• <style>

• h1 {color:red; font-family:sans-serif}

• </style>

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 8: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Creating an Embedded Style

<head>

<title>Embedded Example</title>

<style> (default is “text/css”)

Style declarations

</style>

</head>

• A style declaration:

• Selector {attribute1:value1; attribute2:value2; …}

• Selector = an element in a document (e.g., a header or paragraph)

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 9: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

An Example of an embedded style

<head>

<title>Getting Started</title>

<style type=“text/css”>

h1 {font-family: sans-serif; color: orange}

</style>

</head>

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 10: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Three Style Types

• External style sheets

• An external style sheet is a text file containing the style

definition (declaration)

• Use it when you need to control the style for an entire web site

• Example

• h1, h2, h3, h4, h5, h6 {color:red; font-family:sans-serif}

• Save this in a new document using a .css extension

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 11: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Creating an External Style Sheet

• Open a new blank document in Notepad

• Type style declarations

• h1 {color:red; font-family:sans-serif;}

• Do not include <style> tags

• Save the document as filename.css

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 12: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Linking to Style Sheets 1

• Open an HTML file

• Between <head> and </head> add

• <link href=URL rel=“relation_type” type=“link_type”>

• URL is the file.css

• Relation_type=“stylesheet”

• Link_type=“text/css”

• Save this file and the .css file in the same web server directory

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 13: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

An example of an external style

sheet with an original html file

<head>

<title>Getting Started</title>

<link href=“scraps.css”

rel=“stylesheet”

type=“text/css” />

</head>

h1 {font-family: sans-serif;

color: orange}

b {color: blue}

html fileText file of css named scraps.css

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 14: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Style Sheet Strategies

• Wherever possible, place your styles in external style

sheets

• Take advantage of the power of CSS to have control

over an entire Web site

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 15: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Style Sheet Strategies

• At the top level of your web site: define a default

global.css style sheet

• Refine styles at sublevels with a section.css style sheet

• Try to avoid using styles in tags

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 16: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Attribute Selectors

• Create an attribute selector to

select an element based on the

element’s attributes.

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 17: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Using IDs and Classes

• Use an id to distinguish something, like a paragraph, from the others in a document.

• For example, to identify a paragraph as “head”, use the code:

<p id=“head”>… </p>

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 18: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Working With Ids

• To create an ID for a specific tag, use the property:

• <tag ID=id_name>

• To apply a style to a specific ID, use:

• #id_name {style attributes and values}

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 19: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Classes

• HTML and XHTML require each id be unique– therefore an id value can only be used once in a document.

• You can mark a group of elements with a common identifier using the class attribute.

<element class=“class”> … </element>

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 20: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Applying a style to a class

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Page 21: Cascading Style Sheets - Amazon Web ServicesIntroduction to CSS Meganadha Reddy K. Technical Trainer | NetCom Learning  © Meganadha Reddy K., 2015

Thank You!

Want to learn more about CSS, JavaScript, HTML and more?

Check out our Web Development Course Package

www.NetComLearning.com

[email protected]

1-888-563-8266