Cascading Style Sheets: Part 1

Slides:



Advertisements
Similar presentations
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
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.
Introduction to CSS.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
“Cascading Style Sheets” for styling WWW information DSC340 Mike Pangburn.
XP Introducing Cascading Style Sheets With Cascading Style Sheets (CSS), you can create one or more documents that control the appearance of some or all.
Introduction to Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 4.
4.01 Cascading Style Sheets
Using Cascading Style Sheets (CSS) Dept. of Computer Science and Computer Information CSCI N-100.
Review HTML  What is HTML?  HTML is a language for describing web pages.  HTML stands for Hyper Text Markup Language  HTML is not a programming language,
Cascading Style Sheets (CSS) 1.  What is CSS?  Why CSS?  How to write a CSS? 2.
Cascading Style Sheet (CSS)
Introduction To CSS.. HTML Review What is HTML used for? Give some examples of formatting tags in HTML? HTML is the most widely used language on the Web.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Essentials of HTML Class 4 Instructor: Jeanne Hart
INTRODUCTION TO CSS. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features of CSS Features of CSS  Creating Style Sheet Creating Style Sheet.
HTML GUIDE Press F5 and then Click on the links on the left to get to the section you want Section 1: Getting Started Section 2: Moving Banner Section.
Cascading Style Sheets Creating a Uniform Site. Style Sheets  Style sheets are used for conformity on a web page or web site.  Style sheets eliminate.
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.
XHTML Formatting font with a style declaration. Formatting Font HTML uses the font tag to change size and family of font But… the font tag is being deprecated.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
Introduction to CSS. What is CSS? CSS ("Cascading Style Sheets") determines how the elements in our XHTML documents are displayed and formatted. By using.
Cascading Style Sheets
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.
1 Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size, font color etc…
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.
Introduction To CSS. Lesson 1: History of CSS CSS was proposed in 1994 as a web styling language. To helps solve some of the problems HTML 4. There were.
Cascading Style Sheets Part 1 1 IT 130 – Internet and the Web.
Cascading Style Sheet.
CSS Nick Sims.
Internal Style Sheets External Style Sheets
Getting Started with CSS
HTML5 and CSS3 Illustrated Unit D: Formatting Text with CSS
4.01 Cascading Style Sheets
Web Development & Design Foundations with HTML5 8th Edition
Basics of Web Design Chapter 4 Cascading Style Sheets Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D.
>> Introduction to CSS
Cascading Style Sheets Part 1
Introduction to CSS.
Cascading Style Sheets
Madam Hazwani binti Rahmat
CX Introduction to Web Programming
Web Developer & Design Foundations with XHTML
Cascading Style Sheets contd: Embedded Styles
Cascading Style Sheets (CSS)
Intro to CSS CS 1150 Fall 2016.
Web Development & Design Foundations with HTML5
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Website Design 3
Introduction to CSS.
Intro to CSS CS 1150 Spring 2017.
Cascading Style Sheets
Introduction to Cascading Style Sheets (CSS)
Working with Cascading Style Sheets (CSS)
Working with Cascading Style Sheets (CSS)
What are Cascading Stylesheets (CSS)?
Some Stuff You Need to Know
Tutorial 3 Working with Cascading Style Sheets
Introduction to CSS.
CSS: Classes and Contextual Selectors
Made By : Lavish Chauhan & Abhay Verma
Basics of Web Design Chapter 4 Cascading Style Sheets Basics Key Concepts Copyright © 2016 Terry Ann Morris, Ed.D.
4.01 Cascading Style Sheets
CSS: Classes and Contextual Selectors
Modifying HTML attributes and CSS values
Cascading Style Sheets Part 1
Internal Style Sheets External Style Sheets
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

Cascading Style Sheets: Part 1

Learning Objectives After reading/watching/practicing this topic, you should be able to: Appreciate the motivation behind the development of CSS Appreciate the fact that HTML tags and attributes should never be used to change how something appears Name the three components that make up an inline CSS style Be able to create an inline style Be able to assign a color to a style using hexadecimal code

HTML code defines the organization of a document HTML was designed so that the tags indicate only the content and organization of a document (headings, lists, titles, etc.). HTML was never intended as a tool for formatting the content (e.g. bolding, italics, colors, etc.). This was fine when the HTML documents were mostly read by scientists doing research work. Nobody was thinking about web pages being used in the elaborate ways that we see today.

…but developers began to want more… As the web became more ubiquitous and went beyond the realm of scientific research, web page developers, especially those developing commercial websites, wanted to add more visual flair to their pages. For this reason, several new tags and attributes were introduced in subsequent versions HTML that allowed designers some control over the appearance of the content on the page. Even so, many designers were still unsatisfied with the options available to them. There were many reasons for this, including limitations on what could actually be done, as well as inconsistency in how HTML documents were being displayed among the many different web clients in use.

…and then it started getting out of hand… Developers soon started getting carried away though… They started inventing their own HTML formatting tags and attributes. Yet most of these tags had never been standardized by the W3C which meant that some browsers supported them, and others did not. In addition, because there was no uniformity, even when a tag was “popular” different browsers frequently displayed those tags differently. All of this went completely against the main objective of HTML which is that a web document should look the same on any browser, on any computer, running any operating system! At one point then, the W3C basically decided to start over. They decreed that HTML was no longer to be used for formatting. However, they did come up with a standardized—and quite powerful—way of formatting documents which they called Cascading Style Sheets (CSS).

Enter: Cascading Style Sheets (CSS) The W3 Consortium (www.w3c.org), the same organization that develops the standards for HTML and XHTML, introduced Cascading Style Sheets in the mid-1990s. CSS was intended as a way of formatting web pages. CSS was designed to augment – not replace — HTML by allowing web designers a powerful and consistent way of controlling the visual appearance of web pages.

Separating Content and Style The fundamental difference between CSS and HTML, is the distinction between the outline and content of a web page (achieved via HTML) and the formatting (e.g. appearance, positioning, etc.) of that content (achieved via CSS). As we learn about CSS you will see that it provides us with: Consistent design (e.g. changing a style definition in a single “style sheet” can change every single page on an entire website!) More flexibility Less work to maintain large websites – some very cool features possible here… Like HTML, style sheets are written in a language with its own rules and syntax.

An example of a CSS Style Here is a CSS style that changes the appearance of a particular h1 tag. In this example, we use CSS to instruct the browser to double the size of the h1 content, and to turn it green. We will explain this in detail in the upcoming slides. <h1 style="font-size:200%; color:green;">

Components of a CSS Style There are three parts to a CSS style: selector, property, and value. The selector is the HTML tag you are formatting (e.g. h1), The property is the attribute you want to change (e.g. font, color). Each property is set to a value. Every property and its value are separated by a colon ( : ). Recall that in HTML, we assign an attribute to its value by using the equals sign. However in CSS, we separate a property from its value by a colon. If you include multiple groups of property/value pairs, each group must be separated by semicolons ( ; ). I typically put a semicolon after every property/value pair – even if there is only one property-value pair being used.

An example of a CSS Style HTML attribute to create an "inline" CSS style “value” “value” <h1 style="font-size:200%; color:green;"> “selector” “property” “property” Note: The CSS style shown here is an example of an "inline" style. We will soon learn that there are two additional– and in fact preferable – ways of applying CSS styles called internal, and external styling.

Property / Value Pairs Comparison of how you assign an attribute/property with its value in HTML vs. CSS: HTML syntax: attribute="value" CSS syntax: property:value; We separate the property from its value by a colon We separate each property:value pair from the next property:value pair with a semicolon. Even if there is only one property:value pair, I usually place a semicolon after it anyways.

Another Example of an Inline Style This example applies several styles to a single h1 tag. <h1 style="font-family:Arial; font-style:italic; font-weight:bold; color:blue;"> Blah blah, de blah blah blah... </h1> Note how each property is separated from its value by a colon. Note how each property:value pair is separated from the next pair by a semicolon (including the last one).

Whitespace redux As discussed earlier, note how we spread the code over more than one line to make it a little easier to read. It is not always necessary to do this. It all comes down to preference. However, you should always do your best to ensure that your code is relatively easy to follow. For example, compare our code: <h1 style="font-family:Arial; font-style:italic; font-weight:bold; color:blue;"> It Takes Practice... </h1> With this: <h1 style="font-family:Arial;font-style:italic;font-weight:bold; color:blue;">It Takes Practice... </h1> Both will work just fine. However, the second version strikes me as a bit dense. At the very least, I'd probably do something like this: <h1 style="font-family:Arial;font-style:italic;font-weight:bold; color:blue;"> Again, it must be emphasized that use of whitespace is not set in stone. However, you should always make some effort to ensure that your code is easy to read.

Three ways of creating a style There are 3 different ways that you can apply a CSS style. Inline style Internal style (a.k.a. "Embedded style") External style Each has various advantages and disadvantages.

Three ways of creating a style: Inline, Internal, External Inline style An inline style is applied to a single tag inside an HTML document. Inline style declarations are placed inside the tag. The HTML attribute "style" is used to notify the browser that we are about to apply a CSS style. <h1 style="font-size: 200%; font-style: italic"> Internal style sheet (also called embedded style sheet)  discussed later An internal style is applied to the entire current HTML file but is not applied to other files on the website. Internal style declarations are frequently placed in the <head> section of the HTML document. External style sheet (also called linked style sheet)  discussed later An external style is applied to the entire HTML file and may be applied to any or all pages on the website. External style declarations are written in a separate text file which is then linked to the HTML file. External style sheets make it easy to give a consistent look to any number of web pages.

Inline Style Again: To create an inline style, the style is declared inside the tag: <h1 style="font-size:200%; font-style:italic;">

Inline Style Examples Identify the selector, property, and value <body style="color:blue;"> body is the selector, color is the property, and blue is the value. This style would set the text of the entire <body> section to blue. <body style="background-color:silver;"> body is the selector, background-color is the property, and silver is the value. This style would set the background color of the entire document to silver.

Inline Style Examples In the style <p style="font-family:Arial; font-weight:bold"> p is the selector, font-family and font-weight are the properties, and Arial and bold are the values. <p style="font-size:300%; color:red"> p is the selector, font-size and color are the properties, and 300% and red are the values.

Example <body> <h3>This is plain h3</h3> <h3 style="font-family:Arial;font-style:italic; color:green"> This is an example of h3 in Arial, italic, green. </h3> </body> This is plain h3 This is h3 in Arial, italic, and green

Aside: How to specify colors There are a few different ways to specify a color. However, there is one in particular that is preferred. All of the examples below specify the color ‘teal’ but in different ways: Name code: body { style= " color: teal " } RGB color values: body {style= " color: rgb(0,128,128) "} RGB color percentages: body {style= " color: rgb(0%,50%,50%) "} Hexadecimal form: body {style= " color: #008080 "} We will use this form throughout our course Note the pound sign (#) – this HAS to be there. Most people use hexadecimal, and that is what we will use in this course. Sometimes during testing, I will use the ‘name code’, (e.g. ‘blue’) since it's quick and easy – great when just experimenting and "playing around". However, when making a “professional” page, I use hex codes. You should use hex for your assignments.

Colors: Names, RGB, and Hex values One example: http://websitetips.com/colorcharts/visibone/hex/ This is only a very small sampling of the colors available to you. Google “html color swatch” and you’ll see a vast number of pages with similar tables/swatches.

Use Hex codes for your colors When playing around on your own during testing, experimenting and so on, feel free to use "name form" (i.e. specifying the color by its name). e.g. <h1 style="color:red;"> However, when doing “official” work (e.g. homework assignments, quizzes, etc.) you should always use "hex form". e.g. <h1 style="color:#ff0000;"> Happy Grader: <h1 style="color:#ff0000;">… Critical Grader: <h1 style="color:red; ">… Why? When learning to program in any language, it is very important to try and adhere to various "programming conventions" recommended by the standards organizations and/or the community at large. For reasons we won't go into here, using hex form to identify colors is a widely used convention among professional web designers.