Svetlin Nakov Telerik Corporation www.telerik.com.

Slides:



Advertisements
Similar presentations
LIS901N: Style sheet Thomas Krichel Style sheets Style sheets are the officially sanctioned way to add style to your document We will cover.
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. What is CSS? CSS stands for Cascading Style Sheets (the page—or sheet—helps you create a style that will cascade across all.
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
1 Cascading Style Sheets™ (CSS) Outline 5.1 Introduction 5.2 Inline Styles 5.3 Embedded Style Sheets 5.4 Conflicting Styles 5.5 Linking External Style.
CSS Digital Media: Communication and design 2007.
Today CSS HTML A project.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
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.
Cascading Style Sheets Basics. Why use Cascading Style Sheets? Allows you to set up a series of rules for all pages in a site. The series may be changed.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
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.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
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“ Example h1.
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 )
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Part 3 Introduction to CSS. CSS Text Text Styles h1 {color: green} // rgb(0,255,0), #00ff00 h2{letter-spacing: 0.5cm} // 2px h3 {text-align: right} //
กระบวนวิชา 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.
Measurement Many CSS properties (values within the declaration) require that you specify a unit of measurement, such as spacing between elements, border.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Chapter 8 Creating Style Sheets.
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.
Tutorial 5 Working with the Box Model. XP Objectives Understand the box model Create padding, margins, and borders Wrap text around an image Float a block-level.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
4.01 Cascading Style Sheets
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Cascading Style Sheets (CSS). CSS: A New Philosophy Separate content from presentation! Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Svetlin Nakov Telerik Corporation
 Cascading Style Sheets (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
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,
CSS Cascading Style Sheets *referenced from
WebD Introduction to CSS By Manik Rastogi.
CSS.
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets™ (CSS)
( Cascading style sheet )
Semester - Review.
CSS Layouts: Grouping Elements
Creating Your Own Webpage
Chapter 6 Cascading Style Sheets™ (CSS)
Using Cascading Style Sheets Module B: CSS Structure
CSS3 Cascading Style Sheet
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
The Internet 10/13/11 The Box Model
Second CSS Lecture Applications to XML
Cascading Style Sheets Color and Font Properties
Cascading Style Sheets™ (CSS)
More CSS 22-Feb-19.
CS3220 Web and Internet Programming CSS Basics
CS3220 Web and Internet Programming CSS Basics
Cascading Style sheet. What is CSS?  CSS stands for Cascading Style Sheets  Cascading: refers to the procedure that determines which style will apply.
Cascading Style Sheets
Introduction to Cascading Style Sheets (CSS)
Cascading Style Sheets™ (CSS)
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

Svetlin Nakov Telerik Corporation

 What is CSS?  Styling with Cascading Stylesheets (CSS)  Selectors and style definitions  Linking HTML and CSS  Fonts, Backgrounds, Borders  The Box Model in W3C and IE  Alignment, Z-Index, Margin, Padding  Positioning and Floating Elements  Visibility, Display, Overflow 2

 Separate content from presentation! 3 Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. Vestibulum et odio et ipsum Vestibulum et odio et ipsum accumsan accumsan. Morbi at accumsan accumsan. Morbi at arcu vel elit ultricies porta. Proin arcu vel elit ultricies porta. Proin tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. Bold Italics Indent Content (HTML document) Presentation (CSS Document)

4 Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. Vestibulum et odio et ipsum Vestibulum et odio et ipsum accumsan accumsan. Morbi at accumsan accumsan. Morbi at arcu vel elit ultricies porta. Proin arcu vel elit ultricies porta. Proin Tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus.

Styling with Cascading Stylesheets

 Cascading Style Sheets (CSS)  Markup language, used to describe the presentation of document  Defines sizes, fonts, colors, layout, etc.  Improves content accessibility  Improves flexibility  Designed to separate presentation from content  Because of CSS all HTML presentation tags are deprecated, e.g.,, etc. 6

 CSS can be applied to any XML document  Not just to HTML / XHTML  CSS can specify different styles for different rendering methods  On-screen  In print  Etc.  … even by voice or Braille-based reader 7

 Priority scheme determining which style rules apply to element  Cascade priorities or weights are calculated and assigned to the rules  Child elements in the HTML DOM tree inherit the styles from their parent  Can override them  Control via !important rule 8

9

 CSS has simple syntax, based on English words  Contains a set of cascading rules  Each rule consists of one or more selectors and declaration block  Declaration block consists of one or more semicolon-terminated declarations in curly braces  Declaration consists of property, a colon and value 10 h1,h2,h3,h4,h5,h6 { color: green }

 Selectors determine which element the rule applies to:  All elements of specific type  Those that mach specific attribute  Elements may be matched depending on how they are nested in the document (HTML)  Examples: 11 h1.title { color: green } #menu li { padding-top: 8px }

 Pseudo-classes define further behavior  Appended to a selector  :hover, :first-letter, :visited, :active, :before, :after  Not all browsers support them fully 12 a:link {text-decoration: none} a:visited {text-decoration: none} a:active {text-decoration: none} a:hover {text-decoration: underline; color: red}.title:before { content: "»" }.title:after { content: "«" }

 Three primary types of selectors:  By tag:  By element id:  By element class name (only for HTML):  Selectors can be combined with commas: This will match tags, elements with class link and element with id top-link 13 h1 {font-face: Verdana} #element_id {color:#FF0000}.class_name {border: 1px solid red} h1,.link, #top-link {font-weight: bold}

 Match relative to element placement: This will match all tags that are inside of This will match all tags that are inside of  * – universal selector: This will match all child nodes of tag  + selector – used to match “the following” tag: This will match all elements with class name link that appear immediately after tag 14 p a {text-decoration: underline} p * {color: black} img +.link {float:right}

 > selector – matches direct child nodes of element: This will match all elements with class error, direct children of tag  [ ] – match tag attributes by regular expression: This will match all tags with alt attribute containing the word logo  There are more rules to select attributes  Not well supported in all browsers 15 p >.error {font-size: 8px} img[alt~=logo] {border: none}

 Browsers have default CSS styles  Used when there is no CSS information or any other style information in the document  Silently inherited in all documents  Caution: default styles differ in browsers  E.g. Firefox default page background is white, while IE7 uses about 5% gray background 16

 HTML (content) and CSS (presentation) can be linked in three ways:  Inline: the CSS rules in the style attribute  No selectors are needed  Embedded: in the HTML in tag  External: CSS rules are in separate file  Usually a file with.css extension  Linked via tag directive in embedded CSS block 17

 Inline styles have highest priority  Then are the embedded styles  External styles are last  Using external files is highly recommended  Simplify the HTML document  Benefit from browser's cache  Inline styles are about to be deprecated by the W3C 18

 Inline CSS styles  Individual element’s style defined using style attribute  Contains only declaration, no selectors:  Override any other styles  Apply to all descendant elements  Used for styles that are not needed anywhere else in the Web site 19

20 <head> Inline Styles Inline Styles </head><body> Here is some text Here is some text Here is some Here is some more text more text <p style="font-size: 20pt;color: <p style="font-size: 20pt;color: #0000FF" >Even more text #0000FF" >Even more text </body></html> inline-styles.html

21 <head> Inline Styles Inline Styles </head><body> Here is some text Here is some text Here is some Here is some more text more text <p style="font-size: 20pt;color: <p style="font-size: 20pt;color: #0000FF" >Even more text #0000FF" >Even more text </body></html> inline-styles.html

 Inline CSS rules have precedence over the external CSS rules: 22 <head> CSS Rules Precedence - Example CSS Rules Precedence - Example span {color:red} span {color:red} </head><body> Some text Some text </body></html> precedence.html

 Inline CSS rules have precedence over the external CSS rules: 23 <head> CSS Rules Precedence - Example CSS Rules Precedence - Example span {color:red} span {color:red} </head><body> Some text Some text </body></html> precedence.html

 Embedded in the HTML in the tag:  The tag is placed in the section of the document  Styles apply to the whole document  type attribute specifies the MIME type  MIME is a describes the format of the content  Other MIME types include text/html, image/gif, text/javascript …  Used for document-specific styles 24

25 <head> Style Sheets Style Sheets em {background-color:#8000FF; color:white} em {background-color:#8000FF; color:white} h1 {font-family:Arial, sans-serif} h1 {font-family:Arial, sans-serif} p {font-size:18pt} p {font-size:18pt}.blue {color:blue}.blue {color:blue} <head> embedded-stylesheets.html

26 …<body> A Heading A Heading Here is some text. Here is some text. Here Here is some text. Here is some text. Here is some text. Here is some text. Here is some is some text. Here is some text. Here is some text. text. Another Heading Another Heading Here is some more text. Here is some more text. Here is some more Here is some more text. Here is some more text. text. Here is some more text. </body></html>

…<body> A Heading A Heading Here is some text. Here is some text. Here Here is some text. Here is some text. Here is some text. Here is some text. Here is some is some text. Here is some text. Here is some text. text. Another Heading Another Heading Here is some more text. Here is some more text. Here is some more Here is some more text. Here is some more text. text. Here is some more text. </body></html> 27

 External linking  Separate pages can all use shared style sheet  Only modify a single file to change the styles across your entire Web site  link tag (with rel attribute)  Specifies a relationship between current document and another document  link element can stay only in the HTML header 28 <link rel="stylesheet" type="text/css" href="styles.css"> href="styles.css">

@import  Another way to link external CSS files  Example:  Not all browsers recognize such rules  You can specify this way browser-specific styles (IE6 ignores ) url(styles.css);</style>

30 /* CSS Document */ a { text-decoration: none } a:hover { text-decoration: underline; color: red; color: red; background-color: #CCFFCC } background-color: #CCFFCC } li em { color: red; font-weight: bold } font-weight: bold } ul { margin-left: 2cm } ul ul { text-decoration: underline; margin-left:.5cm } margin-left:.5cm } styles.css

31 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Transitional//EN" " transitional.dtd"> " transitional.dtd"> <head> Importing style sheets Importing style sheets <link type="text/css" rel="stylesheet" <link type="text/css" rel="stylesheet" href="styles.css" /> href="styles.css" /></head><body> Shopping list for Monday : Shopping list for Monday : Milk Milk … external-styles.html

32 … Bread Bread White bread White bread Rye bread Rye bread Whole wheat bread Whole wheat bread Rice Rice Potatoes Potatoes Pizza with mushrooms Pizza with mushrooms </ul> <a href=" title="grocery store">Go to the Grocery store store">Go to the Grocery store </body></html>

… Bread Bread White bread White bread Rye bread Rye bread Whole wheat bread Whole wheat bread Rice Rice Potatoes Potatoes Pizza with mushrooms Pizza with mushrooms </ul> <a href=" title="grocery store">Go to the Grocery store store">Go to the Grocery store </body></html> 33

 Colors are specified in RGB format, in hex form:  Example: #A0A6AA  Predefined color aliases exist: black, blue, etc.  Numeric values are specified in:  Pixels, e.g. 12px  Points, e.g. 10pt  Inches, centimeters, millimeters  E.g. 1in, 1cm, 1mm  Percentages, e.g. 50%  Percentage is relative to the parent element 34

 color – specifies the color of the text  font-size – size of font: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger or numeric value  font-family – comma separated font names  Example: Verdana, Sans-Serif, etc.  The browser loads the first one that is available  There should always be at least one serif font  font-weight – normal, bold, bolder, lighter or number in range [ 100 … 900 ] 35

 font-style – styles the font  Values: normal, italic, oblique  text-decoration – decorates the text  Values: none, underline, line-trough, overline, blink  text-align – defines the alignment of text or other content  Values: left, right, center, justify 36

 font  Shorthand rule for setting multiple font properties at the same time is equal to writing this: 37 font: italic normal bold 12px Verdana; font-style: italic; font-variant: normal; font-weight: bold; font-size:12px; font-family: Verdana;

Live Demo font-rules.html

 background-color  Solid color background  background-image  URL of image to be used as background, e.g.:  background-repeat  repeat-x, repeat-y, repeat, no-repeat  background-attachment  fixed / scroll 39 background-image:url("back.gif");

 background-position : specifies vertical and horizontal position of the background image  Vertical position: top, center, bottom  Horizontal position: left, center, right  Both can be specified in percentage or other numerical values  Examples: 40 background-position: top left; background-position: -5px 50%;

 background : shorthand rule for setting background properties at the same time: is equal to writing:  Some browsers will not apply BOTH color and image for background if using shorthand rule 41 background: #FFF0C0 url("back.gif") no-repeat fixed top; background-color: #FFF0C0; background-image: url("back.gif"); background-repeat: no-repeat; background-attachment: fixed; background-position: top;

 Background images allow you to save many image tags from the HTML  Leads to less code  More content-oriented approach  All images that are not part of the page content should be moved to the CSS 42

Live Demo background-rules.html

 border-width : thin, medium, thick or numerical value (e.g. 10px )  border-color : color alias or RGB value  border-style : none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset  Each property can be defined separately for left, top, bottom and right  border-top-style, border-left-color, … 44

 border : shorthand rule for setting border properties at once: is equal to writing:  Specify different borders for the sides via shorthand rules: border-top, border-left, border-right, border-bottom 45 border: 1px solid red; border-width:1px;border-color:red;border-style:solid;

Live Demo border-rules.html

 width – defines numerical value for the width of element, e.g. 200px  height – defines numerical value for the height of element, e.g. 100px  Important: not all elements and browsers follow this value!  Usually the height of an element is defined by its content  Common mistake is to apply height to tables or table cells 47

Live Demo size-rules.html

 margin and padding define the spacing around the element  Numerical value, e.g. 10px or -5px  Can be defined for each of the four sides separately  margin-top, padding-left, …  margin is the spacing outside of the border  padding is the spacing between the border and the content 49

 margin: 5px ;  Sets all four sides to have margin of 5 px;  margin: 10px 20px ;  Sets margins: top and bottom to 10px, left and right to 20px ;  margin: 1px 3px 5px 7px ;  Sets top, right, bottom, left margins to 1px, 3px, 5px and 7px respectively  Same shorthand rules apply for padding 50

51

 Major difference between browsers when applying border, padding and width/height  To avoid you need either “CSS hacks” or just don’t specify for the same element width/height and padding or border, different than 0 52

Live Demo margins-paddings-rules.html

 position : defines the positioning of the element, depending on the parent elements  The value is one of:  static (default)  relative – relative position according to where the element would appear with static position  absolute – position according the parent element  fixed – fix element on screen, ignore page scrolling 54

 Fixed and absolute positioned elements “float” over the rest of elements  Moved to separate document layer  Their position and size is ignored when calculating the size of parent element or position of surrounding elements  Ordered by their z-index 55

Live Demo positioning-rules.html

 top, left, bottom, right : specifies offset of absolute/fixed/relative positioned element as numerical values  vertical-align : sets the vertical-alignment of an element  Usually used for table cells  Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom or numeric  z-index : specifies the depth-order of element 57

Live Demo alignments-and-z-index-rules.html

 float : the element “floats” above the elements  similar to position: absolute and the align HTML property of tag  element is taken into account when rendering the surrounding text and elements  left : places the element on the left  right : places the element on the right 59

 clear  Sets the sides of the element where other floating elements are NOT allowed  Possible values: left, right, both  This rule can be applied only to “floating” elements 60

Live Demo float-rules.html

 opacity : specifies the opacity of the element  Floating point number from 0 to 1  Supported only by Safari browser  For Mozilla use –moz-opacity CSS rule  For IE use filter:alpha(opacity=value) where value is from 0 to 100  Need to apply all three rules 62

Live Demo opacity-rule.html

 visibility  Determines whether the element is visible  hidden : element is not rendered, but still takes place in the rendering (acts like opacity:0 )  visible : element is rendered normally 64

Live Demo visibility-rule.html

 display : controls the display of the element and the way it is rendered and if breaks should be placed before and after the element  inline : no breaks are placed before and after ( is inline element)  block : breaks are placed before AND after the element ( is block element) 66

 none : element is hidden and its dimensions are not used to calculate the surrounding elements rendering (differs from visibility: hidden !)  There are some more possible values, but not all browsers support them  Specific displays like table-cell and table- row 67

Live Demo display-rule.html

 overflow : defines the behavior of element when content needs more space than you have specified by the size properties or for other reasons. Values:  visible (default) – element size is increased to make space for content or the content “overflows” out of the element  scroll – show horizontal/vertical scroll bar in the element  hidden – any content in the element that cannot be placed inside is hidden 69

Live Demo overflow-rule.html

 cursor : specifies the look of the mouse cursor when placed over the element  Values: crosshair, help, pointer, progress, move, hair, col-resize, row- resize, text, wait, copy, drop, and others  white-space – controls the line breaking of text. Value is one of:  nowrap – keeps the text on one line  normal (default) – browser decides whether to brake the lines if needed 71

 More powerful formatting than using presentation tags  Your pages load faster, because browsers cache the.css files  Increased accessibility, because rules can be defined according given media  Pages are easier to maintain and update 72

73 Title Some random text here. You can’t read it anyway! Har har har! Use Css. Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title one CSS file

 Don’t use or other presentation tags to change the look of your text    text that is bold  this text is centered  Do not use complex CSS rules-sets because may slow down page rendering  Move as much as possible to external files  Avoid inline CSS 74

 Visual Studio – CSS Editor 75

 Firebug – add-on to Firefox used to examine and adjust CSS and HTML 76

 IE Developer Toolbar – add-on to IE used to examine CSS and HTML (press [F12]) 77

Questions?