Using the CSS. What is CSS? CSS is a language that’s used to define the formatting applied to a Website, including colors, background images, typefaces.

Slides:



Advertisements
Similar presentations
HIGH LEVEL OVERVIEW: CSS CSS SYNTAX CONSISTS OF A SET OF RULES THAT HAVE 3 PARTS: A SELECTOR, A PROPERTY, AND A VALUE. IT’S NOT NECESSARY TO REMEMBER THIS.
Advertisements

Intro To Cascading Style Sheets By Mario Yannakakis.
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Cascading Style Sheets
Cascading Style Sheets
Today CSS HTML A project.
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
CHAPTER 7 STYLING CONTENT WITH CASCADING STYLE SHEETS.
CSS CSS Precise Aesthetic Control. Cascading Style Sheets Though they can be put in HTML header, usually a separate page that the HTML links to Contains.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
“Cascading Style Sheets” for styling WWW information DSC340 Mike Pangburn.
CSS The Definitive Guide Chapter 2 & Review of some things in HTML5.
Lecture Cascading Style Sheets (CSS) Internal Style Sheets Classes.
SM5312 week 6: basic CSS syntax1 An Introduction to Cascading Style Sheets Basic CSS Syntax Nick Foxall.
4.01 Cascading Style Sheets
CM143 Week 4 Introducing CSS. Cascading Style Sheets A definition for the style in which an element of the webpage will be displayed Border width, colour,
W EB S ITE L ECTURE C ASCADING S TYLE S HEETS. Cascading Style Sheets (CSS) Introduction CSS Objectives – Provide more control over web site content presentation.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
 Missing (or duplicate) semicolons can make the browser completely ignore the style rule.  You may add extra spaces between the properties/values to.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
Cascading Style Sheets Dreamweaver. Styles Determine how the HTML code will display Determine how the HTML code will display Gives designers much more.
HTML - Quiz #2 Attendance CODE:
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
Cascading Style Sheets (CSS) 1.  What is CSS?  Why CSS?  How to write a CSS? 2.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
The Characteristics of CSS
CSS Cascading Style Sheets By Garrett Garman. CSS Why use Style Sheets? Separates Appearance and Structure Modularity Quick and Easy changes Flexibility.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
INTRODUCTION TO HTML5 CSS Styles. Understanding Style Sheets  HTML5 enables you to define many different types of content on a web page, including headings,
Chapter 6 Web Typography. 2 Principles of Web Design Chapter 5 Objectives Understand principles for type design on a Web site Use the element Understand.
IDs versus Classes Naming Your Tags for Maximum Functionality.
1 WDMD 170 – UW Stevens Point WDMD 170 Internet Languages eLesson: CSS Introduction to Style Sheets (NON-audio version) © Dr. David C. Gibbs
1 What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles are normally stored in Style Sheets  Styles.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 14, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
WRT235: Writing in Electronic Environments CSS Classes, IDs, divs.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Cascading Style Sheets Class 2, Lecture 2 Rachel A Ober
Essentials of HTML Class 4 Instructor: Jeanne Hart
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Cascading Style Sheets Dreamweaver. Styles Determine how the HTML code will display Determine how the HTML code will display Gives designers much more.
Neal Stublen Course Road Map  Create web page layouts using CSS  Manage CSS  Test website validity  Create navigation menus using.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Course created by Sarah Phillips BBCD Melbourne BAPDCOM Version 1 – April 2013.
CSS with XHTML Please use speaker notes for additional information!
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Introduction to CSS. Why CSS? CSS Provides Efficiency in Design and Updates CSS relatively easy to use Can give you more flexibility and control Faster.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
Cascading Style Sheets Primary readings Presentations Explain & review projects with class mates.
CSS FOUNDATIONS IN-DEPTH The nitty-gritty of css...
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
Chapter 4 Frames and Cascading Style Sheets. Frames Frames divide a browser window into two or more separate pieces or panes, with each pane containing.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Chapter 3 Designing Your Web Pages. Objectives What is CSS and Why it is needed How CSS looks and how to write it The different ways to add CSS code to.
4.01 Cascading Style Sheets
>> Introduction to CSS
Cascading Style Sheets
4.01 Cascading Style Sheets
Introduction to Styling
Presentation transcript:

Using the CSS

What is CSS? CSS is a language that’s used to define the formatting applied to a Website, including colors, background images, typefaces (fonts), margins, and indentation. Let’s look at a basic example to see how this is done. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " A Simple Page h1, h2 { font-family: sans-serif; color: #3366CC; } First Title … Second Title … Third Title …

Using CSS in HTML lnline Styles The simplest method of adding CSS styles to your web pages is to use inline styles. An inline style is applied via the style attribute, like this: Inline styles have two major disadvantages: 1)They can’t be reused. For example, if we wanted to apply the style above to another p element, we would have to type it out again in that element’s style attribute. 2)Additionally, inline styles are located alongside the page’s markup, making the code difficult to read and maintain. Amazingly few discotheques provide jukeboxes.

Using CSS in HTML Embedded Styles In this approach, you can declare any number of CSS styles by placing them between the opening and closing tags, as follows: While it’s nice and simple, the tag has one major disadvantage: if you want to use a particular set of styles throughout your site, you’ll have to repeat those style definitions within the style element at the top of every one of your site’s pages. CSS Styles here

Using CSS in HTML External Style Sheets An external style sheet is a file (usually given a.css filename) that contains a web site’s CSS styles, keeping them separate from any one web page. Multiple pages can link to the same.css file, and any changes you make to the style definitions in that file will affect all the pages that link to it. To link a document to an external style sheet (say, styles.css), we simply place a link element in the document’s header:

CSS Selectors Every CSS style definition has two components:  A list of one or more selectors, separated by commas, define the element or elements to which the style will be applied.  The declaration block specifies what the style actually does.

CSS Selectors Type Selectors By naming a particular HTML element, you can apply a style rule to every occurrence of that element in the document. For example, the following style rule might be used to set the default font for a web site: p, td, th, div, dl, ul, ol { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 1em; color: #000000; }

CSS Selectors Class Selectors CSS classes comes in when you want to assign different styles to identical elements that occur in different places within your document. Consider the following style, which turns all the paragraph text on a page blue: Great! But what would happen if you had a sidebar on your page with a blue background? You wouldn’t want the text in the sidebar to display in blue as well—then it would be invisible. What you need to do is define a class for your sidebar text, then assign a CSS style to that class. To create a paragraph of the sidebarclass, first add a classattribute to the opening tag: p { color: #0000FF; } This text will be white, as specified by the CSS style definition below.

CSS Selectors Class Selectors Now we can write the style for this class: This second rule uses a class selector to indicate that the style should be applied to any element of the sidebar class. The period indicates that we’re naming a class—not an HTML element. p { color: #0000FF; }.sidebar { color: #FFFFFF; }

CSS Selectors ID Selectors In contrast with class selectors, ID selectors are used to select one particular element, rather than a group of elements. To use an ID selector, first add an id attribute to the element you wish to style. It’s important that the ID is unique within the document: To reference this element by its ID selector, we precede the id with a hash (#). For example, the following rule will make the above paragraph white: ID selectors can be used in combination with the other selector types. This paragraph is uniquely identified by the ID "tagline". #tagline { color: #FFFFFF; } #tagline.new { font-weight: bold; color: #FFFFFF; }

CSS Selectors Descendant Selectors A descendant selector will select all the descendants of an element. In this case, because our page contains a div element that has a class of sidebar, the descendant selector.sidebar p refers to all p elements inside that div. p { color: #0000FF; }.sidebar p { color: #FFFFFF; } This paragraph will be displayed in white. So will this one.

CSS Selectors Child Selectors A descendant selector will select all the descendants of an element, a child selector only targets the element’s immediate descendants, or “children.” Consider the following markup: This paragraph will be displayed in white. So will this one. If we use a descendant selector, this will be white too. But if we use a child selector, it will be blue.

CSS Selectors Child Selectors In this example, the descendant selector we saw in the previous section would match the paragraphs that are nested directly within div.sidebar as well as those inside div.tagline. If you didn’t want this behavior, and you only wanted to style those paragraphs that were direct descendants of div.sidebar, you’d use a child selector. A child selector uses the > character to specify a direct descendant. Here’s the new CSS, which turns only those paragraphs directly inside.sidebar (but not those within.tagline) white: Note: Unfortunately, Internet Explorer 6 doesn’t support the child selector. p { color: #0000FF; }.sidebar>p { color: #FFFFFF; }

Most Common CSS Mistakes

ID vs. Class What An ID refers to a unique instance in a document, or something that will only appear once on a page. For example, common uses of IDs are containing elements such as page wrappers, headers, and footers. On the other hand, a CLASS may be used multiple times within a document, on multiple elements. A good use of classes would be the style definitions for links, or other types of text that might be repeated in different areas on a page. In a style sheet, an ID is preceded by a hash mark (#), and might look like the following: #header { height:50px; } #footer { height:50px; } #sidebar { width:200px; float:left; } #contents { width:600px; }

ID vs. Class What Classes are preceded by a dot (.). An example is given below..error { font-weight:bold; color:#C00; }.btn{ background:#98A520; font-weight:bold; font-size:90%; height:24px; color:#fff; }

Redundant Units for Zero Values The following code doesn't need the unit specified if the value is zero. It can be written instead like this: Don't waste bytes by adding units such as px, pt, em, etc, when the value is zero. The only reason to do so is when you want to change the value quickly later on. Otherwise declaring the unit is meaningless. Zero pixels is the same as zero points. padding:0px 0px 5px 0px; padding:0 0 5px 0;

Avoid Repetition We should avoid using several lines when just one line will do. For example, when setting borders, some people set each side separately: But why? When each border is the same! Instead it can be like: border-top:1px solid #00f; border-right:1px solid #00f; border-bottom:1px solid #00f; border-left:1px solid #00f; border:1px solid #00f;

Excess Whitespace Usually we have tendency to include whitespace in the code to make it readable. It'll only make the stylesheet bigger, meaning the bandwidth usage will be higher. Of course it's wise to leave some space in to keep it readable.

Grouping Identical Styles together So when we want a same style to a couple of elements. It is good to group them together and define the style instead of defining the style for each element separately. It will also make updating the style much easier. h1, p, #footer,.intro { font-family:Arial,Helvetica,sans-serif; }

Margin vs. Padding As margins and paddings are generally be used interchangeably, it is important to know the difference. It will give you greater control over your layouts. Margin refers to the space around the element, outside of the border. Padding refers to the space inside of the element, within the border. Example: No Padding, 10px Margin Result: p { border: 1px solid #0066cc; margin:10px; padding:0; }

Margin vs. Padding Example: No Margin, 10px Padding Result: p { border: 1px solid #0066cc; padding:10px; margin:0; }