04 – CSS Informatics Department Parahyangan Catholic University.

Slides:



Advertisements
Similar presentations
Cascading Style Sheets (CSS). Cascading Style Sheets With the explosive growth of the World Wide Web, designers and programmers quickly explored and reached.
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
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.
Cascading Style Sheets
Cascading Style Sheets
Today CSS HTML A project.
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
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.
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. 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.
Lecture Cascading Style Sheets (CSS) Internal Style Sheets Classes.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
4.01 Cascading Style Sheets
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
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.
TUTORIAL 8: Enhancing a Web Site with Advanced CSS
 Missing (or duplicate) semicolons can make the browser completely ignore the style rule.  You may add extra spaces between the properties/values to.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Cascading Style Sheets (CSS) Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
CSS Style Rules Guang Tong, Zhan L;lo’p[ Css Style Rule Guang Tong Zhan Three ways to insert CSS 1 External style sheet 2 Internal style sheet 3 Inline.
Cascading style sheets (CSS)
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External 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,
1 Cascading Style Sheets (CSS) Part 2. 2 The Sources of Style Sheets.
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.
CSS Netcentric. What is CSS O CSS stands for Cascading Style Sheets O Styles define how to display HTML elements O Styles were added to HTML 4.0 to solve.
ITCS373: Internet Technology Week 3: Introduction to CSS Dr. Faisal Al-Qaed.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CSS Basic (cascading style sheets)
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 7.
 Remember that HTML is just text  Need to point to pictures  Use the img tag  alt: › screen reader › REQUIRED for this class and to validate.
Cascade Style Sheet Introduction. What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles were added.
Tutorial #6 – Creating Fixed Width Layouts. Tutorial #5 Review – Box Model Every html element is surround by a box Content, Padding, Border, Margin Can.
Web Design and Development for Business Lecture 4 Cascading Style Sheet (CSS)
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
DIV, Span, CSS.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
How to… Cascading Style Sheets. How to Insert a Style Sheet When a browser reads a style sheet, it will format the document according to it. There are.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
Chapter 4 Frames and Cascading Style Sheets. Frames Frames divide a browser window into two or more separate pieces or panes, with each pane containing.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
CASCADING STYLE SHEET 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.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
CSS (Cascading Style Sheets). CSS CSS – Cascading Style Sheets – Cascade because of the way CSS rules can stack on top of each other. Allows you to add.
CSS.
Cascading Style Sheets (CSS) Internal Style Sheets Classes
4.01 Cascading Style Sheets
Cascading Style Sheets
Intro to CSS CS 1150 Fall 2016.
CASCADING STYLE SHEET CSS.
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Intro to CSS CS 1150 Spring 2017.
Styles and the Box Model
What are Cascading Stylesheets (CSS)?
4.01 Cascading Style Sheets
Presentation transcript:

04 – CSS Informatics Department Parahyangan Catholic University

 CSS allows us to create rules that specify how the content of an element should appear.  For example, we can specify that:  The background of the page is cream  All paragraphs should appear in gray using the Arial typeface  All level one headings should be in a blue, italic, Times typeface  Etc.

 The key to understanding how CSS works is to imagine that there is an invisible box around every HTML element.  CSS allows you to create rules that control the way that each individual box (and the contents of that box) is presented.

 CSS works by associating rules with HTML elements.  These rules govern how the content of specified elements should be displayed.  A CSS rule contains two parts: a selector and a declaration.

 Selectors indicate which element the rule applies to. To apply the same rule to more than one element, separate the element names with commas.  Declarations indicate how the elements referred to in the selector should be styled. Declarations are split into two parts (a property and a value),and are separated by a colon.

 Example:  This rule indicates that all elements should be shown in the Arial typeface.

 Example:  This rule indicates that all, and elements should be shown in the Arial typeface, in a yellow color.

 There are some ways to use CSS to your web page:  External CSS  Internal CSS  Inline CSS

 When building a site with more than one page, you should use an external CSS file.  This:  Allows all pages to use the same style rules (rather than repeating them in each page).  Keeps the content separate from how the page looks.  Means you can change the styles used across all pages by altering just one file (rather than each individual page).

 The element can be used in an HTML document to tell the browser where to find the CSS file used to style the page.  It is an empty element.  It lives inside the element.

 It should use three attributes:  href This specifies the path to the CSS file (which is often placed in a folder called css or styles).  type This attribute specifies the type of document being linked to. The value should be text/css.  rel This specifies the relationship between the HTML page and the file it is linked to. The value should be stylesheet when linking to a CSS file.

 An HTML page can use more than one CSS file  To do this it could have a element for every CSS file it uses.  For example, some authors use one CSS file to control the presentation (such as fonts and colors) and a second to control the layout. Using External CSS

 You can also include CSS rules within an HTML page by placing them inside a element (which usually sits inside the element of the page). body { background-color: linen; } h1 { color: maroon; margin-left: 40px; } Example:

 An inline style may be used to apply a unique style for a single element.  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.  Example: This is a heading.

 When there is more than one style specified for an HTML, we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules (where number three has the highest priority): 1. Browser default 2. External and internal style sheets (in the head section) 3. Inline style (inside an HTML element)  If the link to the external style sheet is placed below the internal style sheet in HTML, the external style sheet will override the internal style sheet!

 LAST RULE If the two selectors are identical, the latter of the two will take precedence.  SPECIFICITY If one selector is more specific than the others, the more specific rule will take precedence over more general ones. Example:  h1 is more specific than *  p b is more specific than p  p#intro is more specific than p

 IMPORTANT You can add !important after any property value to indicate that it should be considered more important than other rules that apply to the same element.  Understanding how CSS rules cascade means you can write simpler style sheets because you can create generic rules that apply to most elements and then override the properties on individual elements that need to appear differently.

 There are many different types of CSS selector that allow you to target rules to specific elements in an HTML document.  CSS selectors are case sensitive, so they must match element names and attribute values exactly.

SelectorsMeaningExample Universal Selector Applies to all elements in the document * {} Targets all elements on the page. Type SelectorMatches element names h1, h2, h3 {} Targets the, and elements Class SelectorMatches an element whose class attribute has a value that matches the one specified after the period (or full stop) symbol..note {} Targets any element whose class attribute has a value of note p.note {} Targets only elements whose class attribute has a value of note.

SelectorsMeaningExample ID SelectorMatches an element whose id attribute has a value that matches the one specified after the pound or hash symbol. #introduction {} Targets the element whose id attribute has a value of introduction. Child Selector Matches an element that is a direct child of another. li>a {} Targets any elements that are children of an element (but not other elements in the page) Descendant Selector Matches an element that is a descendent of another specified element (not just a direct child of that element) p a {} Targets any elements that sit inside a element, even if there are other elements nested between them.

SelectorsMeaningExample Adjacent Sibling Selector Matches an element that is the next sibling of another. h1+p {} Targets the first element after any element (but not other elements) General Sibli ng Selector Matches an element that is a sibling of another, although it does not have to be the directly preceding element. h1~p {} If you had two elements that are siblings of an element, this rule would apply to both

 Every HTML element can carry the id attribute.  It is used to uniquely identify that element from other elements on the page.  Its value should start with a letter or an underscore (not a number or any other character).

 Giving an element a unique identity allows us to style it differently than any other instance of the same element on the page.  For example:  we want to assign one paragraph within the page (perhaps a paragraph containing a pull quote) a different style than all of the other paragraphs.

 Every HTML element can also carry a class attribute.  Sometimes, rather than uniquely identifying one element within a document, we want a way to identify several elements as being different from the other elements on the page.

 For example:  we have some paragraphs of text that contain information that is more important than others and want to distinguish these elements  we want to differentiate between links that point to other pages on our own site and links that point to external sites.

 The element is a block-level element that is often used as a container for other HTML elements.  The element has no required attributes, but style and class are common.  When used together with CSS, the element can be used to style blocks of content: London London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

 The element is an inline element that is often used as a container for some text.  The element has no required attributes, but style and class are common.  When used together with CSS, the element can be used to style parts of the text: My Important Heading

 The element is often used as a layout tool, because it can easily be positioned with CSS.

 Example: The CSS ? See

 HTML5 offers new semantic elements that define different parts of a web page:  header: Defines a header for a document or a section  nav: Defines a container for navigation links  section: Defines a section in a document  article: Defines an independent self-contained article  aside: Defines content aside from the content (like a sidebar)  footer: Defines a footer for a document or a section  details: Defines additional details  summary: Defines a heading for the details element

City Gallery #header { background-color:black; color:white; text-align:center; padding:5px; } HTML CSS City Gallery header { background-color:black; color:white; text-align:center; padding:5px; } HTML CSS BEFORE HTML 5AFTER HTML 5

 All HTML elements can be considered as boxes.  The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content.  Content - The content of the box, where text and images appear  Padding - Clears an area around the content. The padding is transparent  Border - A border that goes around the padding and content  Margin - Clears an area outside the border. The margin is transparent

 Important: The width and height properties set through CSS is for the content area. To calculate the full size of an element, we must also add padding, borders and margins. div { width: 320px; padding: 10px; border: 5px solid gray; margin: 0; }320px 340px 350px 350px Internet Explorer 8 and earlier versions, include padding and border in the width property. To fix this problem, add a to the HTML page.

 The CSS3 box-sizing property allows us to include the padding and border in an element's total width and height..div1 { width: 300px; height: 100px; border: 1px solid blue; }.div2 { width: 300px; height: 100px; padding: 50px; border: 1px solid red; }

 The CSS3 box-sizing property allows us to include the padding and border in an element's total width and height..div1 { width: 300px; height: 100px; border: 1px solid blue; box-sizing: border-box; }.div2 { width: 300px; height: 100px; padding: 50px; border: 1px solid red; box-sizing: border-box; }

 RWD can deliver web pages in variable sizes Example see:

Example:.city { float: left; margin: 5px; padding: 15px; width: 300px; height: 300px; border: 1px solid black; }

 The viewport is the user's visible area of a web page.  When browsing on a mobile device, fixed sized web page might be too large to fit the viewport. To fix this, the browser on that devices scale down the entire web page to fit the screen.

 HTML5 introduced a method to let web designers take control over the viewport, through the tag. The width=device-width part sets the width of the page to follow the screen- width of the device (which will vary depending on the device). The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.

BeforeAfter

 If the width property is set to 100%, the image will be responsive and scale up and down:  If the max-width property is set to 100%, the image will scale down if it has to, but never scale up to be larger than its original size: img { width: 100%; height: auto; } img { max-width: 100%; height: auto; }

 If the background-size property is set to "contain", the background image will scale, and try to fit the content area. However, the image will keep its aspect ratio div { width: 100%; height: 400px; background-image: url('img_flowers.jpg'); background-repeat: no-repeat; background-size: contain; border: 1px solid red; }

 If the background-size property is set to "100% 100%", the background image will stretch to cover the entire content area: div { width: 100%; height: 400px; background-image: url('img_flowers.jpg'); background-size: 100% 100%; border: 1px solid red; }

 If the background-size property is set to "cover", the background image will scale to cover the entire content area. The "cover" value keeps the aspect ratio, and some part of the background image may be clipped div { width: 100%; height: 400px; background-image: url('img_flowers.jpg'); background-size: cover; border: 1px solid red; }

 We can load a totally different images for different viewport sizes /* For width smaller than 400px: */ body { background-image: url('img_smallflower.jpg'); } /* For width 400px and larger: only screen and (min-width: 400px) { body { background-image: url('img_flowers.jpg'); } }

 use min-device-width instead of min-width to check the device’s width instead of the browser’s width /* For width smaller than 400px: */ body { background-image: url('img_smallflower.jpg'); } /* For width 400px and larger: only screen and (min-device-width: 400px) { body { background-image: url('img_flowers.jpg'); } }

 HTML5 introduced the element, which lets us define more than one image. The first source that fits the preferences is the one being used. The srcset attribute is required, and defines the source of the image. The media attribute is optional. The element should be defined for browsers that do not support the element. The srcset attribute is required, and defines the source of the image. The media attribute is optional. The element should be defined for browsers that do not support the element.