56
Web Design with Cascading Style Sheet Lan Vu

Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Embed Size (px)

Citation preview

Page 1: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Web Design with Cascading Style Sheet

Lan Vu

Page 2: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Overview•Introduction to CSS•Designing CSS•Using Visual Studio to create CSS•Using template for web design

Page 3: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Introduction to CSS

Page 4: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•Our designing purpose:▫Create a theme for website▫To have a indentify look throughout our

website

Page 5: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design
Page 6: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•How to do that ?▫Use a common layout for all pages▫Use color of texts, links, buttons and

graphics… reflecting that color theme for all page▫Use same font set for all page

Page 7: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design
Page 8: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•What have we done until now? ▫Create a sample page with expected

format, layout.▫Create specific pages as a copy of this

sample page▫Modify design on each specific page.

Page 9: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•What if we want ?

•Do the whole design process again with new theme•Or modify each existing pages to new design

Page 10: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•If your website has 2-3 pages ▫No problem, I will re-design them.

•But if your website has 10, 20 … 100 pages▫Oh NO! I don’t have time to re-design all

pages

Page 11: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Why do we need CSS?•Using CSS helps you to save much time

on change format, style and theme of your website.•CSS even bring you more benefit in design.

Page 12: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

What CSS is?

CSS = Cascading Style Sheets

Page 13: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

What CSS is?•A style sheet is a set of rules to tell a

web browser how to present the web page content▫i.e. how to display HTML elements

Page 14: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS Benefits•Separate structure from appearance▫HTML establishes structure and content of a web page▫CSS controls appearance of the page

•Create consistent look-and-feel across multiple pages

•Ease of maintenance

•Reduce HTML file size

Page 15: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS structure•CSS is a set of rules•Sample of style sheet

body { font-family: Tahoma, Arial, sans-serif; font-size: 13px; color: black;}

h1 { font-size: 19px; border-bottom: 1px solid black}.shaded { background: #d0d0ff;}

Rules

Page 16: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Rule Structure•Have two parts▫Selector: tells a browser which HTML elements in a

page will be affected by the rule.▫Declaration: tells the browser which set of

properties to apply.•Sample Style sheet

Page 17: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Slide 17

body { font-family: Tahoma, Arial, sans-serif; color: black; background: white; margin: 8px;}

Selector Declaration

Property

Value

Rule Structure

Page 18: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Slide 18

body { font-family: Tahoma, Arial, sans-serif; font-size: 13px; color: black; background: white; margin: 8px;}h1 { font-size: 19px; margin-top: 15px; margin-bottom: 5px; border-bottom: 1px solid black}.shaded { background: #d0d0ff;}

<body><h1>First Section Heading</h1><p>

Here is the first paragraph, containingtext that really doesn't have any useor meaning; it just prattles on and on,with no end whatsoever, no point tomake, really no purpose for existenceat all.

</p><div class="shaded">

<h1>Another Section Heading</h1><p>

Another paragraph.</p>

</div></body>

CSS: HTML:Applying CSS to HTML

Page 19: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Slide 19

<body><h1>First Section Heading</h1><p>

Here is the first paragraph, containingtext that really doesn't have any useor meaning; it just prattles on and on,with no end whatsoever, no point tomake, really no purpose for existenceat all.

</p><div class="shaded">

<h1>Another Section Heading</h1><p>

Another paragraph.</p>

</div></body>

HTML:

body { font-family: Tahoma, Arial, sans-serif; font-size: 13px; color: black; background: white; margin: 8px;}h1 { font-size: 19px; margin-top: 15px; margin-bottom: 5px; border-bottom: 1px solid black}.shaded { background: #d0d0ff;}

CSS:

Applying CSS to HTML

Page 20: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Applying CSS to HTML•Internal Style Sheets▫Inline Styles▫Embedded style sheets

•External style sheets

Page 21: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Slide 21

Adding Styles to HTML<head> ... <link rel="stylesheet" type="text/css" href="myStyles.css" /> <style type="text/css"> body { font-family: Tahoma, Arial, sans-serif; ... } </style></head><body> ... <div style=“padding:2px; ... "> ...</body>

External style sheets

Embedded style sheets

Inline Styles

Page 22: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Inline StyleAffects individual HTML tag

<html>...

<body>...<p style=“font-family: Arial, sans-

serif; ”>some text</p></body>

</html>

Page 23: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Embedded style sheets

Affects individual HTML document

<html><head>

... <style type=“text/css”>

p {font-family: Arial, sans-serif;} </style></head>

<body>...

<p>some text</p> </body></html>

Page 24: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

External Style Sheets• Styles are defined in separate text file (.css)▫ styles.css, style1.css, style2.css

•HTML files (.html) have links to style sheet files (.css)▫Affect all HTML files that are linked to the style sheet

Page 25: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

External Style Sheets•styles.css file

p {font-family: Arial, Sans-serif;}

•sample.html file<html>

<head>

...

<link href=“styles.css” rel=“stylesheet” type=“text/css” />

</head>

<body>

...

<p>some text</p>

</body>

</html>

Page 26: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Cascading Order• CSS uses an order of precedence to

determine which styles to apply when a selector is formatted in different sources

• The least important style formatting is the browser’s default style settings

Page 27: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

• The cascading order of precedence for styles, starting with the least important to the most important, is as follows:1. Browser default2. External style sheets3. Internal style sheets4. Inline styles

Cascading Order

Page 28: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Designing CSS

Page 29: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Selector TypeElement Selectors

H1 {color: purple;}

H1, H2, P {color: purple;}

body { font-family: Tahoma, Arial, sans-serif;

color: black;background: white;margin: 8px;

}

Page 30: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Selector TypeContextual Selector:

Used when an HTML element can display more than one behaviour (e.g. hyperlinks)

• CSS:

a:link {color: #000}a:visited {color: #000}a:hover {color: #69f}a:active {color: #000}

• HTML

<a href=“nextpage.html”>Next page</a>

Page 31: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Selector TypeID Selector▫CSS…#red_heading {color: red}#summary {color: red}p#conclusion {color: blue}

▫HTML…<h1 id=“red_heading”>Headline</h1><p id=“summary”>Summary</p><p id=“conclusion”>Conclusion</p>…

Page 32: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Selector TypeClass Selectors▫ CSS:….blue {color: #082984}.red {color: #de2131}

▫ HTML…<h1 class=“red”>Headline</h1><p class=“red”>a summary</p><p class=“blue”>some text</p>…

Page 33: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

The most frequently used HTML elements

Page 34: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS Properties•Font▫Font styles: font family▫Type: size, weight, or variant

•Text▫Define the layout of blocks of text▫Words and characters▫Spacing▫Alignment▫Transformation (forced uppercase or lowercase)▫Decoration (underline, overline, and blinking)

Page 35: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS Properties•Color and image▫Color and background formatting of text and images▫Define position of background image

•Border▫Define the style of borders for elements like tables,

images, documents▫Border properties include width, height, style, color,

margins, and padding.•Display▫Define styles for the structure of the doc.▫Placement of elements (block or inline)

Page 36: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS1 Text Properties

Page 37: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Setting Font Properties

Page 38: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Boxes Properties

Page 39: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

CSS Properties•Visit here for full list of properties• http://msdn.microsoft.com/en-us/library/ms531205(VS.85).aspx

Page 40: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Create External Cascading Style Sheets with Visual Studio

Page 41: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Create CSS file1. Run VS : All program Visual Studio 2005 Visual

Studio 2005

2. Creating CSS file in VS: Choose menu File New File

Page 42: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Create CSS file3. In the New File box, choose General in Categories

and then choose Style Sheet in the right list . Finally, click Open button

Page 43: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Create CSS file4. After a new CSS file is created, you can start to add

rules to CSS file by typing CSS code in the editor or using design tools of Visual Studio.

Page 44: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Create CSS file5. Save your CSS file when you’ve done by selecting

File Save or Save As enter Filename in the Save box. And now, you have had an CSS to be used in all page of your website.

Page 45: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Add CSS rulesThere are two ways• Typing CSS code in the editor• Using design tools of Visual Studio.

Page 46: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Add CSS rules Using design tools for designing1. On the Styles menu, click Add Style Rule.

The Add Style Rule dialog box appears

Page 47: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Add CSS rules2. In the Add Style Rule dialog box, select one of the following

CSS selectors▫Element Defines a rule for an element by tag name. ▫Class name Defines a rule for a CSS class. ▫Element ID Defines a rule for an element with a specific ID.

Enter the element name/Class name/ Element ID and then click OK:

Page 48: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Add CSS rules3. Find the new style selector and then place the cursor between the braces ( { } ).4. On the Styles menu, click Build Style.5. In the Style Builder dialog box, define the style attributes that you want the

element to have, and then click OK.The Style Builder dialog box inserts CSS style attributes within the braces ( { } ) of the style selector.

Page 49: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Link Cascading Style Sheets to HTML page

After you have defined an external cascading style sheet (CSS) you can link the style sheet to individual HTML Web pages to apply the styles to the elements on the page. 1. Open the HTML page in Visual Studio2. Select Source view windows3. Add a link element inside the <head></head> tags on the

Web page.Example: <link href="MyStyles.css" rel="stylesheet" type="text/css" />MyStyles.css is the filename of CSS file you’ve created

NOTE: Remember to upload all CSS files that you linked to your web pages

Page 50: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Using template for web design

Page 51: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Web template

•Templates are sample web pages that are designed in a specific theme

▫ Just need to add content to template page▫ No design effort require

•Use available template for time saving in web design

Page 52: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Web template

•A template often include: One or few sample web pages (HTML, PHP, ASP…)

Cascading Style Sheets Files

Images used in template

•There are a lot templates available in Internet for free download or charged download

•A download template need to be customized for best fit your design requirement knowledge in HTML, CSS is useful.

Page 53: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Free Web templates

•http://www.freewebtemplates.com/templates/html

•http://www.freewebsitetemplates.com/

Page 54: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Practicing

Page 55: Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design

Creating a template for your website

The template include▫A sample HTML file with specific layout for your website▫A CSS file with rules for design of sample file▫Images ( if needed )

Using this template to re-design your existing website