Some more CSS. CSS pseudo-classes Pseudo-classes let a stylesheet rule narrow its range Format of usage: selector:pseudo-class {property:value;} selector.class:pseudo-class.

Slides:



Advertisements
Similar presentations
CSS3 OVERVIEW Owen Williams Owen at dynabooks daht com.
Advertisements

LIS650 lecture 4 Thomas Krichel today Advice CSS Properties –Box properties-- List properties –Table properties-- Classification properties.
Copenhagen, 6 December 2004 Modern CSS Principles Miruna Bădescu Finsiel Romania.
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Ideas to Layout Beginning web layout using Cascading Style Sheets (CSS). Basic ideas, practices, tools and resources for designing a tableless web site.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
CSS Internet Engineering Spring 2014 Bahador Bakhshi CE & IT Department, Amirkabir University of Technology.
Cascading Style Sheets
Cascading Style Sheets
Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell.
NSWI142 – Web Applications Lecture 3 – CSS (Part 1) Martin Nečaský, Ph.D. Web Applications (NSWI142 ), Lecture 31.
Introduction to CSS.
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 level 3. History of CSS CSS level 1 – original CSS CSS level 2 CSS level 2 Revision 1 (CSS2.1) – up to CSS2.1 monolithic structure CSS level 3 – specification.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
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 )
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Neal Stublen Transforms  Defined by the transform property Translate Rotate Scale Skew  Apply to any element without affecting.
กระบวนวิชา 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.
ADVANCED CSS William Neely CEO, Piecewise.com. CSS FONTS AND TEXT CSS ‣ Line-height allows to indicate the amount of space between lines; allows for equal.
CSS Statements, media queries, selectors, cascading Web Applications Martin Nečaský Department of Software Engineering, Faculty of Mathematics and Physics,
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.
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.
Cascading style sheets CSS
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Style sheets can also affect the BODY. style4.css BODY {BACKGROUND-COLOR : white} H1 {COLOR : red; FONT-SIZE : 50; FONT-FAMILY : arial} H2 {COLOR : green}
Style sheets can also affect the body. style4.css body {background-color : white} h1 {color : red; font-size : 50; font-family : arial} h2 {color : green}
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
New Perspectives on XML, 2nd Edition Tutorial 5 1 TUTORIAL 5 WORKING WITH CASCADING STYLE SHEETS.
INTRODUCTION TO HTML5 CSS Styles. Understanding Style Sheets  HTML5 enables you to define many different types of content on a web page, including headings,
CSS Positioning Creating Special Effects with CSS CS202 Working with Cascading Style Sheets (Chapter 4) CS202 1.
1 Cascading Style Sheets (CSS) Part 2. 2 The Sources of Style Sheets.
Tutorial 8 Enhancing a Web Site with Advanced CSS
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
HTML, CSS, and XML Tutorial 8 Enhancing a Web Site with Advanced CSS.
Slide 1 CMPS 211 Internet Programming Spring 2008 Style Sheet Building Blocks Chapter 7 & 8 4/8/08.
Positioning and Printing Creating Special Effects with CSS.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
3.3. Managing the Graphical Interface by Using CSS. Managing the Graphical Interface by Using CSS.
The usable Media types are: all Suitable for all devices Braille Intended for Braille tactile feedback devices. embossed Intended for paged Braille printers.
The HTML5 logo was introduced by W3C in 2010
Working with Cascading Style Sheets
Creating Visual Effects
Cascading Style Sheets™ (CSS)
Chapter 5 Introduction to Cascading Style Sheets (CSS): Part 2
Tutorial 4 Topic: CSS 3.0 Li Xu
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Advanced CSS BIS1523 – Lecture 20.
Cascading Style Sheets
Creating Visual Effects and Animation
Web Systems & Technologies
Objectives Create a media query Work with the browser viewport
Cascading Style Sheets™ (CSS)
Tutorial 4 Creating Special Effects with CSS
Cascading Style Sheets
Web Programming and Design
Cascading Style Sheets™ (CSS)
Presentation transcript:

Some more CSS

CSS pseudo-classes

Pseudo-classes let a stylesheet rule narrow its range Format of usage: selector:pseudo-class {property:value;} selector.class:pseudo-class {property:value;} List of CSS pseudo-classes :link Example selector a:link Selects all unvisited links :visited Example selector a:visited Selects all visited links :active Example selector a:active Selects the active link :hover Example selector a:hover Selects links on mouse over :focus Example selector input:focus Selects the input element which has focus :first-letter Example selector p:first-letter Selects the first letter of every element :first-line Example selector p:first-line Selects the first line of every element :first-child Example selector p:first-child Selects every elements that is the first child of its parent :before Example selector p:before Insert content before every element :after Example selector p:after Insert content after every element :lang(language) Example selector p:lang(de) Selects every element with a lang attribute value starting with "de"

Pseudo-class examples The stylesheet below would display hotlinks which the user has already visited in red, unvisited in blue, and so on a:link {color:blue;} a:visited {color:red;} a:hover {color:purple;} a:active {color:pink;}

Pseudo-class examples (contd.) Effect of :active in the stylesheet below –if the user clicks and holds the mouse on the hotlink, its background turns green –if the user clicks and hold the mouse on the div, its background turns green Animation example a:active { background-color:green} div:active { background-color:yellow} This is a link Hello

Pseudo-class examples (contd.) The stylesheet below would display the first paragraph in white on a green background p:first-child { background-color:green;color:white; } This is a paragraph. This is another paragraph.

Pseudo-class examples (contd.) The stylesheet below would display the words "Some text in German" in green span:lang(de) {color: green; } Here is Some text in French, so it is. Here is Some text in German, so it is.

Pseudo-class examples (contd.) The stylesheet below would display the text "Read this: " on an orange background before each paragraph p:before { content : "Read this: "; background-color:orange } This is a paragraph. This is another paragraph.

CSS at-rules

CSS at-rules are so-called because an at-rule starts with character An at-rule does not specify a styling property Instead, an at-rule is an instruction to the CSS engine An at-rule can be used to –import one stylesheet into another –specify the character encoding of an external stylesheet –target style specifications at certain media –specify margins for paged media –specify custom fonts –declare an XML namespace, so that elements from different namespaces can have different style specifications –animate CSS properties

rule This was introduced in CSS1 It is used to import one stylesheet into another Basic { URI | string }; "local.css";

CSS names for media types CSS allows us to specify different styles for display on different media The following names can be used to specify different media all - all devices braille - braille tactile feedback devices embossed - paged braille printers handheld - handheld devices (typically small screen, limited bandwidth) print - paged material and for documents viewed on screen in print preview mode projection - presentations on projectors screen - colour computer screens speech - speech synthesizers tty - media using a fixed-pitch character grid (such as teletypes, terminals, or portable devices with limited display capabilities) tv - television-type devices (low resolution, colour, limited-scrollability screens, sound available)

CSS names for media groups On the previous slide, the explanation of the print media type referred to the concept of "paged" media CSS explanations often distinguish between media types on the basis of whether the media types are continuous or paged visual, audio, speech, or tactile. grid (character grid devices) or bitmap interactive (devices that allow user interaction) or static (those that do not)

rule rules can be targeted at specific media { URI | string } mediaType1, mediaType2,… ; url("/css/screen.css") screen, url("/css/mobile.css") handheld;

rule This was introduced in CSS2 It is used to target style specifications at certain media mediaType1,mediaType2, … {styleSpecifications} screen { body {width: 1200;} handheld { body {width: 400;} }

rule You should rarely, if ever, need to use this rule, which was introduced in CSS2 It is used in external stylesheets to declare the character encoding of the file –For this reason, it must be the very first thing in the file "encoding"; "ISO ";

rule Used to specify margin widths for the page box in stylesheets for paged media such as the print media type Introduced in CSS2 [ { :left | :right | :first } ] { marginSpecifications } { margin: 2.5cm; :left { margin-left: 5cm; :right { margin-right: 5cm; :first { margin-top: 8cm; }

rule Used to define custom fonts Introduced in CSS2 { fontDescriptors } Reference:

rule Used to declares an XML namespace and, optionally, a prefix, so that tag names in different namespaces can have different style specifications Introduced in CSS3 [ prefix ] URI; shop " shop|item { color:red } The stylesheet above would cause the item element below to appear in red because the namespaces match … Note use of the pipe symbol above - the colon character was already used in stylesheets, for pseudo-classes

rule rules must –follow rules, and –precede all other at-rules and style specifications in a stylesheet The scope of rule is the stylesheet in which it appears –the scope does not include imported style sheets If rule does not include a prefix, the rule defines the default namespace

rule rule is used to animate CSS properties We will examine it later

Browser rendering engines and their vendor-specific prefixes

Browser rendering engines WebKit is an open-source layout engine which is used in Google Chrome and Apple Safari Gecko is an open-source layout engine which is used in Firefox Presto is a proprietary layout engine which is used in Opera Trident (also known as MSHTML) is a proprietary layout engine which is used in Opera

Vendor-specific CSS property prefixes When layout engines develop their own implementation of almost- standardized CSS property specifications, they often prefix the property name with an identifying label WebKit uses the -webkit- prefix Gecko uses the -moz- prefix Presto uses the -o- prefix Trident (MSHTML) uses the -ms- prefix Thus, for example, at the moment, the safest way to use a new property called transform is as shown in the following example: div { transform: translate(50px,100px); -ms-transform: translate(50px,100px); /* IE 9 */ -webkit-transform: translate(50px,100px); /* Safari and Chrome */ -o-transform: translate(50px,100px); /* Opera */ -moz-transform: translate(50px,100px); /* Firefox */ } A list of prefixed properties:

CSS transforms

CSS 2D transforms 2D transformations in CSS rely on two new properties: transform transform-origin Example use of the transform property - rotation div { width:200px; height:100px; background-color:red; transform:rotate(-15deg); -moz-transform:rotate(-15deg); /* Firefox */ -webkit-transform:rotate(-15deg); /* Chrome, Safari */ -ms-transform:rotate(-15deg); /* IE9 */ -o-transform:rotate(-15deg); /* Opera */ } Hello

CSS 2D transformation functions rotate( ) - spec ifies rotation by the angle given translateX( ) –specifies a translation by the given amount in the X direction translateY( ) –specifies a translation by the given amount in the Y direction translate( [, ]) - specifies translation by the vector [trX,trY]; if tY is not given, zero is used scale( [, ]) - specifies scaling by the [sx,sy] scaling vector; if second parameter not given, a value equal to the first is used scaleX( ) - specifies by the [sx,1] scaling vector scaleY( ) - specifies by the [1,sY] scaling vector skewX( ) - specifies skewing along X axis by given angle skewY( ) - specifies skewing along Y axis by given angle matrix(,,,,, ) - specifies application of the transformation matrix [n1,n2,n3,n4,n5,n6] Reference:

Using a list of CSS 2D transformations A list of transformation can be specified, for example div {width:200px; height:100px; background-color:red; transform:rotate(-15deg) translateX(300px); -moz-transform:rotate(-15deg) translateX(300px); -webkit-transform:rotate(-15deg) translateX(300px); -ms-transform:rotate(-15deg) translateX(300px); -o-transform:rotate(-15deg) translateX(300px); } Hello

The transform-origin property - example usage div { width:200px; height:100px; background-color:red; transform:rotate(-15deg); -moz-transform:rotate(-15deg);-webkit-transform:rotate(-15deg); -ms-transform:rotate(-15deg);-o-transform:rotate(-15deg); } This is a paragraph Hello div { width:200px; height:100px; background-color:red; transform-origin:top left; -moz-transform-origin:top left;-webkit-transform-origin:top left; -ms-transform-origin:top left; -o-transform-origin:top left; transform:rotate(-15deg); -moz-transform:rotate(-15deg);-webkit-transform:rotate(-15deg); -ms-transform:rotate(-15deg);-o-transform:rotate(-15deg); } This is a paragraph Hello

The transform-origin property The initial transform-origin for an element is at its centre We can change this by specifying the following values for the CSS property: [ top | bottom ] | [ | | left | center | right ] [ | | top | center | bottom ]? | [ center | [ left | right ] [ | ]? ] && [ center | [ top | bottom ] [ | ]? ] If only one value is specified, second is assumed to be ‘center’ If two values are given and at least one is not a keyword, then first value represents horizontal position (or offset) and second represents vertical position (or offset) a or value represents an offset of the transform origin from the top left corner of the element's border box. If three or four values are given, then each or represents an offset and must be preceded by a keyword, which specifies from which edge the offset is given. Example: transform-origin: bottom 10px right 20px represents a 10px vertical offset up from the bottom edge and a ‘20px’ horizontal offset leftward from the right edge If three values are given, the missing offset is assumed to be zero. Positive values represent an offset inward from the edge of the border box. Negative values represent an offset outward from the edge of the border box.

CSS Transitions

CSS transitions CSS transitions provide a way to achieve simple animations of CSS properties Reference: We will consider CSS transitions now Later, we will consider more sophisticated CSS animations using rule

CSS response to user actions The stylesheet below will cause a sharp change of style for the div element when the user holds his mouse over it div { width:200px; background-color:pink; font-size:10 } div:hover { width:400px; background-color:yellow; font-size:100 } This is a paragraph. Hello

Gradual change in response to user actions These two CSS properties allow use to specify gradual responses to user actions: transition-property transition-duration However, since the browser implementations still appear to be experimental/tentative, we must use vendor- specific prefixes

Gradual change in response to user actions (contd.) The stylesheet below will cause a gradual transition in style for the div element when the user holds his mouse over it div { width:200px; height:180px; background-color:pink; font-size:10; transition-property: width, background-color, font-size; transition-duration: 15s, 15s, 15s; -moz-transition-property: width, font-size;-moz-transition-duration: 15s, 15s, 15s; -ms-transition-property: width, font-size;-ms-transition-duration: 15s, 15s, 15s; -webkit-transition-property: width, font-size;-webkit-transition-duration: 15s, 15s, 15s; -o-transition-property: width, font-size;-o-transition-duration: 15s, 15s, 15s; } div:hover { width:400px; background-color:yellow; font-size:100 } This is a paragraph. Hello

Varying transition speed Normally, the speed of a transition is uniform between the start and finish of the transition Using the transition-timing-function property, we can vary the speed Browser implementations of this property still have vendor-specific prefixes transition-timing-function: …; -moz-transition-timing-function: …; /* Firefox 4 */ -webkit-transition-timing-function: …; /* Safari and Chrome */ -o-transition-timing-function: …; /* Opera */ -ms-transition-timing-function: …; /* 9 */

Values of the transition-timing-function property linear – specifies that a transition has the same speed from start to end, ease – specifies that a transition starts slowly, then speeds up but finishes slowly ease-in – specifies that a transition starts slowly ease-out – specifies that a transition ends slowly ease-in-out – specifies that a transition starts and ends slowly cubic-bezier(x1,y1,x2,y2) - see next slide

Values of transition-timing-function property (contd.) cubic-bezier(x1,y1,x2,y2) specifies that the speed of a transition varies along a cubic bezier curve, where the x axis is time and the y axis is the delta in the property being changed the start and end points of the bezier curve are fixed (0,0), start, change = 0 (1,1) - end, change = 100% of delta the four arguments are the x and y coordinates of the two control points for the cubic bezier curve linear is equivalent to cubic-bezier(0,0,1,1) ease is equivalent to cubic-bezier(0.25,0.1,0.25,1) ease-in is equivalent to cubic-bezier(0.42,0,1,1) ease-out – is equivalent to cubic-bezier(0,0,0.58,1) ease-out –is equivalent to cubic-bezier(0.42,0,0.58,1) An interactive utility for checking bezier values: (needs a modern browser)

transition-timing-function - example The transition in the stylesheet below will start very slowly and then accelerate towards the end See it in action at div { height: 180px; width:200px; background-color:pink; font-size:10; transition-property: width, background-color, font-size; transition-duration: 15s, 15s; transition-timing-function: cubic-bezier(.97,.01,.98,.05); -moz-transition-property: width, background-color, font-size;-moz-transition-duration: 15s, 15s; -moz-transition-timing-function: cubic-bezier(.97,.01,.98,.05); -o-transition-property: width, background-color, font-size;-o-transition-duration: 15s, 15s; -o-transition-timing-function: cubic-bezier(.97,.01,.98,.05); -ms-transition-property: width, background-color, font-size;-ms-transition-duration: 15s, 15s; -ms-transition-timing-function: cubic-bezier(.97,.01,.98,.05); -webkit-transition-property: width, background-color, font-size;-webkit-transition-duration: 15s, 15s; -webkit-transition-timing-function: cubic-bezier(.97,.01,.98,.05); } div:hover { width:400px; background-color:yellow; font-size:100;} This is a paragraph. Hello

Transitions can control transforms as well as styles This example is at The transform and three style properties transition gradually, over 15 secs, when the mouse is held over the initial position of the div element div { height: 180px; width:200px; background-color:pink; font-size:10; transition-property: transform, font-size, background-color, width; transition-duration: 15s, 15s, 15s,15s; -moz-transition-property: -moz-transform, font-size; background-color, width;-moz-transition-duration: 15s, 15s, 15s, 15s;-o-transition-property: -o-transform, font-size; background-color, width;-o-transition-duration: 15s, 15s, 15s, 15s;-ms-transition-property: -ms-transform, font-size; background-color, width;-ms-transition-duration: 15s, 15s, 15s, 15s;-webkit-transition- property: -webkit-transform, font-size; background-color, width; -webkit-transition-duration: 15s, 15s, 15s, 15s; } div:hover { width:400px; background-color:yellow; font-size:100 ; transform-origin:top left ; transform:rotate(-15deg ); -moz-transform-origin:top left;-webkit-transform-origin:top left;-ms-transform-origin:top left;-o-transform-origin:top left;-moz-transform:rotate(-15deg);-webkit-transform:rotate(-15deg);-ms- transform:rotate(-15deg); -o-transform:rotate(-15deg);} This is a paragraph. Hello

The transition-delay property The stylesheet below will cause a delayed style transition for the div element when the user holds his mouse over it Check it out at p {width:200px;color:red} div { height: 180px; width:200px; background-color:pink; font-size:40; transition-property: width; transition-duration: 15s; transition-delay: 10s; -moz-transition-property: width;-moz-transition-duration: 15s;-moz-transition-delay: 10s;-ms-transition-property: width;-ms-transition-duration: 15s;-ms-transition-delay: 10s;-o-transition-property: width;-o-transition-duration: 15s;-o-transition-delay: 10s;-webkit-transition-property: width;-webkit-transition-duration: 15s;-webkit-transition- delay: 10s; } div:hover { width:400px;} Transition delay Note that, if you hover your mouse over the pink box below, the transition will not start for 10 seconds and will then last for 15 seconds Hello A transition-delay can have a negative value Example: if the delay above were -10s, the transition would start immediately, the box having a width as if the transition has started 10s before, and would then spend 5s more to finish the width change