INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

Similar documents
What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

CSS how to display to solve a problem External Style Sheets CSS files

CSS CSS how to display to solve a problem External Style Sheets CSS files CSS Syntax

Assignments (4) Assessment as per Schedule (2)

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

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

CSS. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

HTML/XML. HTML Continued Introduction to CSS

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

BIM222 Internet Programming

Comp-206 : Introduction to Software Systems Lecture 23. Alexandre Denault Computer Science McGill University Fall 2006

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

Reading 2.2 Cascading Style Sheets

CREATING A WEBSITE USING CSS. Mrs. Procopio CTEC6 MYP1

Appendix D CSS Properties and Values

CSS: The Basics CISC 282 September 20, 2014

Chapter 4 CSS basics

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

COSC 2206 Internet Tools. CSS Cascading Style Sheets

CASCADING STYLE SHEET CSS

Three Ways to Use CSS:

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

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

Adding CSS to your HTML

With HTML you can create your own Web site. This tutorial teaches you everything about HTML.

Cascading Style Sheets. Overview and Basic use of CSS

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

Cascading style sheets, HTML, DOM and Javascript

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

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

LBS Polytechnic. Hey! Make With The Style Sheet Already, Bub!

CSC 443: Web Programming

CSE 154 LECTURE 3: MORE CSS

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

Introduction to Web Tech and Programming

CSS for Styling CS380

Web Development & Design Foundations with HTML5

CSS Cascading Style Sheets

Web Development & Design Foundations with HTML5

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

CSc 337 LECTURE 3: CSS

Introduction to Cascading Style Sheets

ACSC 231 Internet Technologies

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

CSS. Lecture 16 COMPSCI 111/111G SS 2018

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

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

Chapter 2 CSS for Style

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

QDITA ONLINE COURSE VISUAL EXPERIENCE FORMATION

CSS Lecture 16 COMPSCI 111/111G SS 2018

CSS.

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

CSS: Cascading Style Sheets

- HTML is primarily concerned with content, rather than style. - However, tags have presentation properties, for which browsers have default values

Introduction to Cascading Style Sheet (CSS)

Networks and Web for Health Informatics (HINF 6220) Tutorial 8 : CSS. 8 Oct 2015

CSS Tutorial Part 1: Introduction: A. Adding Style to a Web Page (3 options):

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

This tutorial will help both students as well as professionals who want to make their websites or personal blogs more attractive.

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

Tutorial 3: Working with Cascading Style Sheets

CSS: formatting webpages

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

Fundamentals of Web Programming a

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

CSS: Formatting Text. CSS for text processing: font-family. Robert A. Fulkerson

CHAPTER 4 CASCADING STYLE SHEETS BASICS KEY CONCEPTS

Overview. Part I: Portraying the Internet as a collection of online information systems HTML/XHTML & CSS

INTERNATIONAL UNIVERSITY OF JAPAN Public Management and Policy Analysis Program Graduate School of International Relations

Introducing Cascading Style Sheets. Cascading Style Sheet Basics Creating Styles Using Styles Manipulating Styles Text Formatting with CSS

Creating A Website - Part 1: Web Design principles, HTML & CSS. CSS Color Values. Hexadecimal Colors. RGB Color

1 of 7 11/12/2009 9:29 AM

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

Document Structure. Document Appearance. Interactivity

Using Dreamweaver. 6 Styles in Websites. 1. Linked or Imported Stylesheets. 2. Embedded Styles. 3. Inline Styles

Using Dreamweaver to Create Page Layouts

INTRODUCTION TO HTML5! CSS Styles!

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

Cascade Stylesheets (CSS)

Admin. Midterm 1 on. Oct. 13 th (2 weeks from today) Coursework:

Markup Language SGML: Standard Generalized Markup Language. HyperText Markup Language (HTML) extensible Markup Language (XML) TeX LaTeX

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

GIMP WEB 2.0 MENUS WEB 2.0 MENUS: HORIZONTAL NAVIGATION BAR CREATING AN HTML LIST

Basic CSS Lecture 17

ITNP43: HTML Lecture 4

Navigation. Websites need a formalized system of links to allow users to navigate the site

DAY 4. Coding External Style Sheets

Programmazione Web a.a. 2017/2018 HTML5

Intermediate Web Publishing: Working with Styles

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

Comm 244 Week 3. Navigation. Navigation. Websites need a formalized system of links to allow users to navigate the site

8a. Cascading Style Sheet

COMP519 Web Programming Autumn Cascading Style Sheets

Web Site Design and Development Lecture 6

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

HTML TUTORIAL ONE. Understanding What XHTML is Not

How to create and edit a CSS rule

Transcription:

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS cristina gena dipartimento di informatica cgena@di.unito.it http://www.di.unito.it/~cgena/ materiale e info sul corso http://www.di.unito.it/~cgena/teaching.html Fonte delle slides http://www.w3schools.com/css/default.asp

WHAT IS CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files

STYLES SOLVED A BIG PROBLEM HTML was never intended to contain tags for formatting a document. HTML was intended to define the content of a document, like: <h1>this is a heading</h1> <p>this is a paragraph.</p> When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. To solve this problem, the World Wide Web Consortium (W3C) created CSS. In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file. All browsers support CSS today.

CSS SAVES A LOT OF WORK! CSS defines HOW HTML elements are to be displayed. Styles are normally saved in external.css files. External style sheets enable you to change the appearance and layout of all the pages in a Web site, just by editing one single file!

CSS SYNTAX A CSS rule set consists of a selector and a declaration block: The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons. Each declaration includes a property name and a value, separated by a colon.

CSS EXAMPLE A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly braces: p {color:red;text-align:center;} To make the CSS code more readable, you can put one declaration on each line, like this:

CSS COMMENTS Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment starts with /* and ends with */. Comments can also span multiple lines:

CSS SELECTORS CSS selectors allow you to select and manipulate HTML element(s). CSS selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more.

THE ELEMENT SELECTOR The element selector selects elements based on the element name. You can select all <p> elements on a page like this: (all <p> elements will be center-aligned, with a red text color)

THE ID SELECTOR The id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the id selector when you want to find a single, unique element. To find an element with a specific id, write a hash character, followed by the id of the element. The style rule below will be applied to the HTML element with id= para1" <p id= para1 >HELLO</p>

THE CLASS SELECTOR The class selector finds elements with the specific class. The class selector uses the HTML class attribute. To find elements with a specific class, write a period character, followed by the name of the class: In the example below, all HTML elements with class="center" will be center-aligned: <strong class= center >ciao</strong> You can also specify that only specific HTML elements should be affected by a class. In the example below, all p elements with class="center" will be center-aligned: <p class= center >ciao</p>

GROUPING SELECTORS In style sheets there are often elements with the same style: To minimize the code, you can group selectors. To group selectors, separate each selector with a comma. In the example below we have grouped the selectors from the code above:

THREE WAYS TO INSERT CSS There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style

EXTERNAL STYLE SHEET An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing just one file. Each page must include a link to the style sheet with the <link> tag. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> An external style sheet can be written in any text editor. The file should not contain any html tags. The style sheet file must be saved with a.css extension. An example of a style sheet file called "mystyle.css", is shown below: body { h1 { background-color: lightblue;} color: navy; margin-left: 20px;}

INTERNAL STYLE SHEET An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, inside the <style> tag, like this: <head> <style> body { } h1 { } background-color: linen; color: maroon; margin-left: 40px; </style> </head>

INLINE STYLES An inline style loses many of the advantages of a style sheet (by mixing content with presentation). Use this method sparingly! To use inline styles, add the style attribute to the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a h1 element: <h1 style="color:blue;margin-left:30px;">this is a heading.</h1>

MULTIPLE STYLES WILL CASCADE INTO ONE Styles can be specified: inside an HTML element inside the head section of an HTML page in an external CSS file Tip: Even multiple external style sheets can be referenced inside a single HTML document.

CASCADING ORDER What style will be used when there is more than one style specified for an HTML element? Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: 1. Browser default 2. External style sheet 3. Internal style sheet (in the head section) 4. Inline style (inside an HTML element) So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style defined inside the <head> tag, or in an external style sheet, or in a browser (a default value). Note: If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style sheet will override the internal style sheet!

CSS BACKGROUND CSS background properties are used to define the background effects of an element. CSS properties used for background effects: background-color background-image background-repeat background-attachment background-position

CSS BACKGROUND Background Color The background-color property specifies the background color of an element. The background color of a page is defined in the body selector body { background-color: #b0c4de;} With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red" Look at CSS Color Values for a complete list of possible color values: http://www.w3schools.com/cssref/css_colors_legal.asp

BACKGROUND IMAGE The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this: body { background-image: url("paper.gif"); }

BACKGROUND IMAGE - REPEAT HORIZONTALLY OR VERTICALLY By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically, or they will look strange, like this: body { background-image: url("gradient_bg.png"); } If the image is repeated only horizontally (repeat-x), the background will look better: body { background-image: url("gradient_bg.png"); background-repeat: repeat-x; }

BACKGROUND IMAGE - SET POSITION AND NO-REPEAT Showing the image only once is specified by the background-repeat property: body { background-image: url("img_tree.png"); background-repeat: no-repeat;} In the example above, the background image is shown in the same place as the text. We want to change the position of the image, so that it does not disturb the text too much. The position of the image is specified by the background-position property: body { } background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top;

BACKGROUND - SHORTHAND PROPERTY As you can see from the examples above, there are many properties to consider when dealing with backgrounds. To shorten the code, it is also possible to specify all the properties in one single property. This is called a shorthand property. The shorthand property for background is simply "background": body { background: #ffffff url("img_tree.png") no-repeat right top;} When using the shorthand property the order of the property values is: background-color background-image background-repeat background-attachment background-position It does not matter if one of the property values is missing, as long as the ones that are present are in this order.

TEXT COLOR The color property is used to set the color of the text. With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red" The default color for a page is defined in the body selector body { color: blue;} h1 { color: #00ff00;} h2 { color: rgb(255,0,0);}

TEXT ALIGNMENT The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers). h1 { text-align: center;} p.date { text-align: right;} p.main { text-align: justify;}

TEXT DECORATION The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes: a { text-decoration: none;} It can also be used to decorate text: h1 { text-decoration: overline;} h2 { text-decoration: line-through;} h3 { text-decoration: underline;}

TEXT TRANSFORMATION The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word. p { text-transform: uppercase;} p { text-transform: lowercase;} p { text-transform: capitalize; }

TEXT INDENTATION The text-indent property is used to specify the indentation of the first line of a text. p { } text-indent: 50px;

CSS FONTS

FONT FAMILY The font family of a text is set with the font-family property. The font-family property should hold several font names as a "fallback" system. If the browser does not support the first font, it tries the next font. Start with the font you want, and end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available. Note: If the name of a font family is more than one word, it must be in quotation marks, like: "Times New Roman". More than one font family is specified in a comma-separated list: p { font-family: "Times New Roman", Times, serif; }

FONT STYLE The font-style property is mostly used to specify italic text. This property has three values: normal - The text is shown normally italic - The text is shown in italics oblique - The text is "leaning" (oblique is very similar to italic, but less supported) p.normal { font-style: normal;} p.italic { font-style: italic;} p.oblique { font-style: oblique;}

FONT SIZE The font-size property sets the size of the text. Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs. Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs. The font-size value can be an absolute, or relative size. Absolute size: Sets the text to a specified size Does not allow a user to change the text size in all browsers (bad for accessibility reasons) Absolute size is useful when the physical size of the output is known Relative size: Sets the size relative to surrounding elements Allows a user to change the text size in browsers Note: If you do not specify a font size, the default size for normal text, like paragraphs, is 16px (16px=1em).

FONT SIZE Set Font Size With Pixels Setting the text size with pixels gives you full control over the text size: h1 { font-size: 40px; } h2 { font-size: 30px; } p { font-size: 14px; }

FONT-SIZE Set Font Size With Em To allow users to resize the text (in the browser menu), many developers use em instead of pixels. The em size unit is recommended by the W3C. 1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px. The size can be calculated from pixels to em using this formula: pixels/16=em h1 { font-size: 2.5em; /* 40px/16=2.5em */} h2 { font-size: 1.875em; /* 30px/16=1.875em */} p { font-size: 0.875em; /* 14px/16=0.875em */ }

FONT SIZE Use a Combination of Percent and Em The solution that works in all browsers, is to set a default font-size in percent for the <body> element: body { font-size: 100%;} h1 { font-size: 2.5em;} h2 { font-size: 1.875em;} p { font-size: 0.875em;} Our code now works great! It shows the same text size in all browsers, and allows all browsers to zoom or resize the text!