Cascading Style Sheets

Slides:



Advertisements
Similar presentations
HTML and CSS. HTML Hyper Text Markup Language Tells browser how to display text and images.
Advertisements

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.
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Web Engineering 1 Ishaq Khan Shinwari MCS City University Peshawar.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
Cascading Style Sheets
Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell.
Today CSS HTML A project.
Presenter: James Huang Date: Sept. 26,  Introduction  Basics  Lists  Links  Forms  CSS 2.
CSS. Intro to CSS Cascading Style Sheets – styles and enhances appearance of webpage.css extension.
CSS CSS stands for Cascading Style Sheets Styles define how to display HTML elements External Style Sheets can save a lot of work External Style Sheets.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
Introduction to CSS.
Very quick intro HTML and CSS. Sample html A Web Title.
Cascading Style Sheets (CSS): Pixel-Level Control with HTML Ease
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.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
End User Computing An Introduction to CSS Sujana Jyothi Research Lab1, Callan Building, Department of Computer Science
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
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.
Building a Website: Cascading Style Sheets (CSS) Fall 2013.
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.
CSS(Cascading Style Sheets )
1 Dreamweaver CS5 intermediate class by Cookie Setton Build a CSS website WITHOUT TABLES Just when you thought you were starting to understand HTML coding,
CSW131 Steven Battilana 1 CSW 131 – Chapter 5 (More) Advanced CSS Prepared by Prof. B. for use with Teach Yourself Visually Web Design by Ron Huddleston,
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Unit 20 - Client Side Customisation of Web Pages
Chapter 8 Creating Style Sheets.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
CSS Cascading Style Sheets Brief Introduction
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.
More CSS CS HTML id attribute 2 Coding Horror! Our mission is to combine programming and “human” factors with geekiness! output  A unique ID for.
4.01 Cascading Style Sheets
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.
Cascading style sheets (CSS)
Learning HTML. HTML Attributes HTML elements can have attributes Attributes provide additional information about an element Class – specifies a class.
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.
CSS. HTML: Looking Back HTML dictates order, structure, and function Does very little to specify layout or visual rendering.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Course created by Sarah Phillips BBCD Melbourne BAPDCOM Version 1 – April 2013.
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
WebD Introduction to CSS By Manik Rastogi.
CSS.
4.01 Cascading Style Sheets
( Cascading style sheet )
Creating Your Own Webpage
Madam Hazwani binti Rahmat
Cascading Style Sheets
Introduction to Web programming
Cascading Style Sheets (Layout)
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Introduction to Web programming
Web Programming– UFCFB Lecture 11
What are Cascading Stylesheets (CSS)?
Training & Development
Cascading Style Sheets
4.01 Cascading Style Sheets
Cascading Style Sheets III B. Com (Paper - VI) & III B
Web Programming and Design
Introduction to Cascading Style Sheets (CSS)
Cascading Style Sheets™ (CSS)
Presentation transcript:

Cascading Style Sheets CSS Cascading Style Sheets

HTML: Looking Back HTML dictates order, structure, and function Does very little to specify layout or visual rendering With HTML, we developed learned about elements in which we could place our content. We built the items, but we’ve said nothing of how they should be painted, decorated, or arranged. Or, for an analogy combo, you could say that we’ve developed a vocabulary--of nouns, verbs, and a couple adjectives, perhaps, but a vocabulary nonetheless! With enough time we could certainly string together these elements and make a paper--we learned how to make tables and, my gosh, we even learned how to place in some dazzling figures! Well, okay, that might pass the muster for grad students, but well, we’re MIT students, and it’s IAP--so let’s not just make papers, let’s be a little creative. Let’s write some poetry!

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

CSS Zen Garden Site using consistent HTML content Differing external CSS files create dramatically different layout Support for multiple browsers link: http://www.csszengarden.com hint: change the styles on the page

What is CSS? Style.css And so on…. 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…. Cascading Style Sheets: Pixel-Level Control with HTML Ease

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 Cascading Style Sheets: Pixel-Level Control with HTML Ease

HTML Without CSS “HTML without CSS is like a piece of candy without a pretty wrapper.” 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. Cascading Style Sheets: Pixel-Level Control with HTML Ease

HTML & CSS HTML and CSS work together to produce beautiful and functional Web sites HTML = structure CSS = style Cascading Style Sheets: Pixel-Level Control with HTML Ease

Typical Web Page (Browser) Container header menu main footer Cascading Style Sheets: Pixel-Level Control with HTML Ease

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> Cascading Style Sheets: Pixel-Level Control with HTML Ease

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;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

Selectors body { property: value; } h1 { property: value; } A selector, here in green, is often an element of HTML. body { property: value; } h1 { property: value; } em { property: value; } p { property: value; } Cascading Style Sheets: Pixel-Level Control with HTML Ease

Properties and Values Properties and values tell an HTML element how to display. body {background: purple;} h1 {color: green; } h2 {font-size: large;} p {color: #ff0000;} /*hexadecimal for red*/ *CSS code can be written in a linear format (above) or in a block format (below). body { background: purple; color: green; } Cascading Style Sheets: Pixel-Level Control with HTML Ease

Grouping Selectors Group the same selector with different declarations together on one line. h1 {color: black;} h1 {font-weight: bold;} h1 {background: white;} Example of grouping selectors (both are correct): h1 { color: black; font-weight: bold; background: white; } Cascading Style Sheets: Pixel-Level Control with HTML Ease

Grouping Selectors Group different selectors with the same declaration on one line. h1 {color: yellow;} h2 {color: yellow;} h3 {color: yellow;} Example of grouping selectors (both are correct): h1, h2, h3 {color: yellow;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

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*/ Cascading Style Sheets: Pixel-Level Control with HTML Ease

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.

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). Suppose 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 <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; }

Typical Web Page (Browser) Container header menu main footer Cascading Style Sheets: Pixel-Level Control with HTML Ease

Typical Web Page (HTML) Typical HTML Web page is made up of containers (boxes) or DIVs. Each DIV is assigned an ID or a Class. <div id=“container”> <div id=“header”>Insert Title</div> <div id=“main">content <div id=“menu”>content</div> </div> <div id=“footer”>content</div> Cascading Style Sheets: Pixel-Level Control with HTML Ease

Typical Web Page (CSS) The CSS file uses the same DIV/ID/Class names as the HTML and uses them to style the elements. #container {property: value;} #menu {property: value;} #main {property: value;} #footer {property: value;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

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} Cascading Style Sheets: Pixel-Level Control with HTML Ease

CSS Box Properties Background-color Width Padding Margin Border-width Border-color Border-style Cascading Style Sheets: Pixel-Level Control with HTML Ease

HTML CSS #content { background-color: #ccc; margin-bottom: 10px; div id=“header” #content { background-color: #ccc; margin-bottom: 10px; border: 1px dashed blue; color: #fff; width: auto; } div id=“content” div id=“footer” Cascading Style Sheets: Pixel-Level Control with HTML Ease

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.

The <span> tag The <span> tag is similar but is a default inline element where-as the div is a default block element. Default display can be changed via style rules /* change the default display for div with class inline */ div.inline { display:inline; } /* change the default display for spans with class block */ span.block { display:block; }

Common CSS Layout Properties Width Height Float Clear Border Padding Margin margin padding width height border Cascading Style Sheets: Pixel-Level Control with HTML Ease

Width & Height div id=“box” Width and height define the width and height of an element. Width and height can be specified in pixels, ems, percentages or set to auto #box {width=“50px”} #box {width=“50em”} #box {width=“100%”} #box {width=“auto”} #box {height=“auto”} div id=“box” Cascading Style Sheets: Pixel-Level Control with HTML Ease

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. Here is some text which wraps around the box floated to the left. div id=“box” #box {float:left; margin-right: 10px;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

Clear: (left, right, 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” #box3 { background-color: white; border: 1px solid #000; clear: both;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

Border (top, right, bottom, left) 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: #box { border-color: red; border-style: dotted; border-width: 2px; } border: red dotted 2px; border-top: red dotted 2px; border-bottom: red dotted 2px; border-left: red dotted 2px; border-right: red dotted 2px; div id=“box” Cascading Style Sheets: Pixel-Level Control with HTML Ease

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 Cascading Style Sheets: Pixel-Level Control with HTML Ease

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; margin: 10px 10px 10px 10px; margin-left: 10px; margin-right: 10px; margin-bottom: 10px; margin-top: 10px; margin div id=“box” Cascading Style Sheets: Pixel-Level Control with HTML Ease

Text Properties To style the main heading in the example, we assign a class the HTML tag. <h3 class=“mainHeading”>Main Heading</h3> 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; } MAIN HEADING Gravida lacinia velit. Vivamus tortor enim, tincidunt at, pellentesque ut, iaculis eu, quam. Cascading Style Sheets: Pixel-Level Control with HTML Ease

Standard Hexadecimal CSS Colors White Black Blue Fuchsia Gray Green #ffffff Black #fff Blue #cccf0f3 Fuchsia Gray Green Lime Aqua Cascading Style Sheets: Pixel-Level Control with HTML Ease

Styling Links The links property defines how inactive, hovered, active, and visited link states appear to the user. 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;} Cascading Style Sheets: Pixel-Level Control with HTML Ease

Including Images Properties for working with images include: Background-image Background-repeat Background-position Background-attachment Cascading Style Sheets: Pixel-Level Control with HTML Ease

Layering div id=“bg” 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=“main” div id=“box” Cascading Style Sheets: Pixel-Level Control with HTML Ease

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. Inline style or directly applied style The last style sheet declared in the <header> section Cascading Style Sheets: Pixel-Level Control with HTML Ease

Saving Time with Inheritance In a nutshell, inheritance 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. Cascading Style Sheets: Pixel-Level Control with HTML Ease