To link to an external stylesheet, the link element is placed within the head of the html page:

Similar documents
CSS.

CSS: Cascading Style Sheets

2. Write style rules for how you d like certain elements to look.

Let s start with the document tree

CSS: The Basics CISC 282 September 20, 2014

Review Question 1. Which tag is used to create a link to another page? 1. <p> 2. <li> 3. <a> 4. <em>

The Benefits of CSS. Less work: Change look of the whole site with one edit

Appendix D CSS Properties and Values

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

Cascading Style Sheets Level 2

Reading 2.2 Cascading Style Sheets

Cascading Style Sheets (CSS)

ITNP43: HTML Lecture 4

Chapter 3 Style Sheets: CSS

CSS Cascading Style Sheets

Three Ways to Use CSS:

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

HTML/XML. HTML Continued Introduction to CSS

INTRODUCTION TO CSS. Topics MODULE 5

CSS. Lecture 16 COMPSCI 111/111G SS 2018

CSS 1: Introduction. Chapter 3

CSS Selectors. element selectors. .class selectors. #id selectors

CSS Lecture 16 COMPSCI 111/111G SS 2018

Introduction to WEB PROGRAMMING

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2)

Zen Garden. CSS Zen Garden

Web Information System Design No.4 Put Style to Web Documents. Tatsuya Hagino

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CSS: Cascading Style Sheets

BIM222 Internet Programming

Session 3.1 Objectives Review the history and concepts of CSS Explore inline styles, embedded styles, and external style sheets Understand style

CSC309 Programming on the Web week 3: css, rwd

Text and Layout. Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 11. This presentation 2004, MacAvon Media Productions

Welcome Please sit on alternating rows. powered by lucid & no.dots.nl/student

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

3.1 Introduction. 3.2 Levels of Style Sheets. - The CSS1 specification was developed in There are three levels of style sheets

- The CSS1 specification was developed in CSS2 was released in CSS2.1 reflects browser implementations

Web Development & Design Foundations with HTML5

CSS: formatting webpages

Web Development & Design Foundations with HTML5

Block & Inline Elements

CSS Cascading Style Sheets

Lab Introduction to Cascading Style Sheets

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

Styles, Style Sheets, the Box Model and Liquid Layout

Assignments (4) Assessment as per Schedule (2)

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

ADDING CSS TO YOUR HTML DOCUMENT. A FEW CSS VALUES (colour, size and the box model)

Tutorial 3: Working with Cascading Style Sheets

CSS3 Basics. From & CSS Visual Dictionary Learning Curve Books, LLC

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

Creating and Building Websites

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

Deccansoft Software Services

HTML and CSS COURSE SYLLABUS

Certified CSS Designer VS-1028

ACSC 231 Internet Technologies

APPLIED COMPUTING 1P01 Fluency with Technology

Media-Specific Styles

ICT IGCSE Practical Revision Presentation Web Authoring

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

Cascading Style Sheets

CSS

DAY 4. Coding External Style Sheets

The building block of a CSS stylesheet. A rule consists of a selector and a declaration block (one or more declarations).

Media Types & Media Features

Cascading Style Sheet. Styles as Tag Attributes. Syntax. <h1>: what font type/size is used? STYLE = SELECTOR {RULES} Attributes such as bgcolor

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

CSS is applied to an existing HTML web document--both working in tandem to display web pages.

IDM 221. Web Design I. IDM 221: Web Authoring I 1

INTRODUCTION TO HTML5! CSS Styles!

<style type="text/css"> <!-- body {font-family: Verdana, Arial, sans-serif} ***set font family for entire Web page***

Web Engineering CSS. By Assistant Prof Malik M Ali

HTML & CSS. SWE 432, Fall 2017 Design and Implementation of Software for the Web

CSS for Styling CS380

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Client-Side Web Technologies. CSS Part I

CSS. Text & Font Properties. Copyright DevelopIntelligence LLC

In the early days of the Web, designers just had the original 91 HTML tags to work with.

CSS THE M\SS1NG MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLr Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

Introduction to Cascading Style Sheet (CSS)

FrontPage 2000 Tutorial -- Advanced

Introduction to CSS. Fijihosting.com Introduction to CSS page 1. What are style sheets? Lovely! How do I use them?

**Method 3** By attaching a style sheet to your web page, and then placing all your styles in that new style sheet.

Lab 4 CSS CISC1600, Spring 2012

CSS مفاهیم ساختار و اصول استفاده و به کارگیری

Cascading Style Sheets. Overview and Basic use of CSS

EECS1012. Net-centric Introduction to Computing. Lecture 3: CSS for Styling

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

CSCB20 Week 7. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSE 154 LECTURE 3: MORE CSS

CSS exercise - Part 1

Chapter 7 Typography, Style Sheets, and Color. Mrs. Johnson

Introduction to Web Tech and Programming

CS 350 Internet Applications I Name: Exam II (CSS) October 29, 2013

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

Transcription:

CSS Basics An external style sheet is simply a text file (use BBEdit or Textwrangler) containing style rules, saved with the.css extension. It s best practice to keep style sheets for a site grouped within a single folder, often named css or styles. To link to an external stylesheet, the link element is placed within the head of the html page: <head> <meta charset="utf- 8" /> <title>el Palau de la Música</title> <link rel="stylesheet" href="css/my- style.css" /> </head> Less preferred is to embed the stylesheet directly into the head of the html page: <head> <meta charset="utf- 8" /> <title>el Palau de la Música</title> <style> img { border: 4px solid red; </style> </head> Least preferred is to put style rules inline with the html elements: <img src="palau.jpg" width="250" height="163" style="border: 4px solid red" /> As an option, you can create different style sheets for different output, the two most common being for print and screen: <link rel="stylesheet" href="style.css" media="screen" /> <link rel="stylesheet" href="print.css" media="print" /> Alternatively, you can do the same within a single style sheet, using the @media rule: @media print { body { font- size: 25pt;

A style rule is constructed generically like: selector { property: value; property: value; The property: value pair or pairs within the curly brackets are called declarations. All punctuation is required, though spacing and line breaks can vary. The selector identifies the part of the page to be styled, and can be an element type, a class or an id. The property identifies which CSS property will be changed, and the value specifies the chosen option for that property. An example of a basic style rule might be: h1 { background- color: yellow; color: red; You can place comments in CSS wherever necessary, using the /* and */ tags. Commenting is critical in helping other users (or yourself at a later date) understand the purpose of your coding. /* Comments can be placed between or within style rules */ Style rules may be written in several places: in external stylesheets linked to the html page (strongly recommended), embedded at the top of the html page, or applied directly to individual elements (called inline and advised against in most cases.)

CSS Inheritance By default, many CSS properties are inherited from parent html elements to child html elements. Child elements are those elements that are contained within larger elements. In the example, em is a child of p, and h1 and p are children of article, and they all are children of body. The indenting of this example, while entirely optional in html coding, does help make the hierarchical nature of the element relationships a bit clearer: <body> <article> <h1>headline</h1> <p>this is a <em>paragraph</em> of text.</p> </article> </body> So the following style rule would change the font of all of those elements to Helvetica body { font- family: Helvetica, sans- serif; while the following would change only the p and em elements, leaving the h1 in the default browser font p { font- family: Helvetica, sans- serif; You can always override the inheritance of children from their parents. Simply give those elements their own style rule. The following would ensure that all text within body and its children was blue, with the exception of the h1 elements. body { color: blue; h1 { color: black;

The following CSS properties are inheritable by default: Text color (except by the a element) direction font font-family font-size font-style font-variant font-weight letter-spacing line-height text-align text-indent text-transform visibility white-space word-spacing Lists list-style list-style-image list-style-position list-style-type Tables border-collapse border-spacing caption-side

empty-cells Properties not on this list can be forced to inherit the values of the parent elements by using inherit as the value. p { border: inherit;

The C in CSS: Cascading styles Html elements may be targeted by CSS in a number of ways, by element type (e.g. p, article, ol, h1, etc.), by class, by id, and through inheritance of parent properties. Additionally, a single element may be targeted from multiple style rules. Cascading determines the priority of style rules. Basically, the more specific selector overrides the more general, and the sequence, from general to specific, is: Default browser styles - > element - > class - > id When the selectors are equal, such as when an element has two classes, and the same property is targeted by both, then the order of the style rules establishes precedence, with the later rule overriding the earlier (inline styles are considered to appear after, and thus have precedence over, all other rules.) So the following example p { color: red;.example { color: blue;.example.example- 2 { color: magenta; /* negated by next rule */.example.example- 2 { color: green; will change the color property of all targeted paragraphs (p) to red, except for those paragraphs with the example class. example class paragraphs will be blue, except for those that also have the example- 2 class, which will be green. Because of the priority given to order (latest overrides earlier), the first example.example- 2 style rule, with the magenta value for color, is immediately overridden by the one below it (and in fact there would likely be no reason to have both of these in the same style sheet.)

CSS Property values Values vary depending on the property. Many properties only take one of a few specified values (such as float: left) or may take a specified value in addition to a numeric or other value (such as border: none or font- family: sans- serif). Type these specified values exactly, and do not enclose them in quotation marks. Many CSS properties determine the size of the targeted element, and those sizes may be either absolute, set in pixels (px) or, rarely, in points (pts); or relative, set in ems (em) or in percentages (%). Values that determine size must always state the unit, such as margin- left: 2em or font- size: 16px. An exception is when the value is 0, where no unit is required. With the prevalence of drastically different screen sizes on phones, tablets and computers, along with the varying resolution introduced by technologies like Retina displays, specifying sizes in pixels has become less common than using ems. This is a key part of responsive design (designing content that looks good and works well across a variety of platforms.) An em is equal to the font size of the element, which is generally inherited from a parent. Thus, if the font- size of the body element has been specified as 16px (which is the html default) a value of 1.5em will generate a size of 24 pixels in a child element (recall that the h1 element, like almost all of the other content of the html page, will be contained within the <body> tags, and so inherits properties assigned to body): body { font- family: Geneva, Tahoma, Verdana, sans- serif; font- size: 100%; /* this establishes the default size of 16px */ h1 { font- size: 1.5em; /* 1.5 times the parent size of 16px = 24px */

CSS Selectors Simple type selector. All article elements will be styled: article { color: red; Class selector. All elements with the class = artist attribute will be styled:.artist { font- style: bold; ID selector. The single element with the id = degas attribute will be styled: #degas { color: green; All things being equal, it is better to style by class than by ID, as a single style rule with a class selector can style multiple elements on the html page (any of that class.) A rule with an ID selector can only style the single element with that id, and so is capable of doing less work. Attribute selector. All elements of this type with this attribute, regardless of their value, are styled: a[title] { color: red; Value selector. All elements of this type with this attribute with this exact value, are styled: h1[title= chapter- heads ] { font- family: Palatino, serif;

There are more specific value selectors, which allow you to select values that contain part of a word, that start with a word, or end with a word, etc. These are a bit fussy, but may be useful at times. They are written: [attribute~= value ] value is word in a space delimited list of words [attribute = value ] is exact value as complete word or begins with value immediately followed by a hyphen (- ) [attribute^= value ] begins with value as full word or as part of a longer word [attribute$= value ] ends with value as full word or as part of a longer word [attribute*= value ] contains value as full word or as part of a longer word Descendent combinator. Only small elements that are descendents of h1 elements will be styled: h1 small { /* The space between the two elements is required */ font- style: italic; Descendent combinators can also use classes (or IDs, more rarely):.callout p { font- style: italic; Child combinator. This kind of selector restricts the specified style to only immediate children of the parent: aside > h1 { color: blue; Thus if the html code looked like this <aside> <h1>a Sad Story</h1> <p>blah, blah, blah.</p> <section> <h1>a Quick Tip</h1> </section> </aside>

only A Sad Story would be styled blue, as A Quick Tip is a child of section, and only a grandchild of aside.

Adjacent sibling combinator. Siblings are elements that are equal children of the same parent. Adjacent siblings (of the type following the plus sign) immediately follow the specified sibling (of the type preceding the plus sign):.artist h1+h1{ /* the element types of the siblings do not have to be the same */ color: blue; Thus if the html code looked like this <article class= artist > <h1>a Sad Story</h1> <h1>a Quick Tip</h1> <h1>more Quick Tips</h1> <p>blah, blah, blah</p> <h1>summing Up</h1> </article> A Quick Tip and More Quick Tips would be styled blue, as each follows an h1 element. Summing Up would not be styled blue, as it does not immediately follow an h1. General sibling combinator. Like the adjacent sibling combinator, but here the siblings do not have to immediately follow, so long as they are preceded somewhere in the parent by an h1:.artist h1~h1{ /* the element types of the siblings do not have to be the same */ color: blue;