CSS 選取器 (Selector). Selector  selector {property: value; …}  h1 {color: #cc3333;}  選取器種類  元素選取器 (type/element selector)  類別選取器 (class selector) 

Slides:



Advertisements
Similar presentations
CSS-Formatting Review Cascading Style Sheets addstyle to your HTML web pages.
Advertisements

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.
Cascading Style Sheets
CSS Digital Media: Communication and design 2007.
Introducing CSS CIS 133 mashup Javascript, jQuery and XML 1.
CSS. Intro to CSS Cascading Style Sheets – styles and enhances appearance of webpage.css extension.
NSWI142 – Web Applications Lecture 3 – CSS (Part 1) Martin Nečaský, Ph.D. Web Applications (NSWI142 ), Lecture 31.
Lecture 5 Use Cases and Style Sheets
Introduction to HTML/XHTML Yen-Cheng Chen National Chi Nan University
Some SpotLight in CSS. CSS element>element Selector div>p.
Very quick intro HTML and CSS. Sample html A Web Title.
Cascading Style Sheets (CSS): Pixel-Level Control with HTML Ease
FORMATTING IN CONTEXT. FOLLOW UPS ANCHOR POINTS MUST BE UNIQUE  If you have more than one, how does it know where to go?  They can be repeated across.
CHAPTER 8 ADVANCED CSS. LEARNING OBJECTIVES Assign formatting styles to a CSS class definition Use a tag’s class attribute to apply the styles defined.
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.
CSS 應用設計. 網頁排版規劃 1. 使用 div 規劃區域 * 或使用 HTML5 Semantic Elements:
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.
Cascading Style Sheets CSS. What is it? Another file format ! its not like html Describes the looks of “selectors” in a.css file (example.css) in the.
Today’s objectives  Element relations – tree structure  Pseudo classes  Pseudo elements.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
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.
Using CSS (Cascading Style Sheets) Effie Nadiv Edited by permission from author by Amir Kirsh.
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.
Cascading Style Sheet CSS CS1520 Ali Alanjawi. 2 TA Information Ali Alanjawi Homepage: Office:
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.
1/18 ITApplications XML Module Session 5: Extensible Stylesheet Language (XSL)
LIS650 lecture 4 Minor CSS, accessibility Thomas Krichel
CSS: Beyond the Code Karen Perone Rodman Public Library
1 Dreamweaver CS5 intermediate class by Cookie Setton Build a CSS website WITHOUT TABLES Just when you thought you were starting to understand HTML coding,
CSW131 Steven Battilana 1 CSW 131 – Chapter 5 (More) Advanced CSS Prepared by Prof. B. for use with Teach Yourself Visually Web Design by Ron Huddleston,
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} //
© 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,
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
Cascading Style Sheets Scripting with Style. CSS versus HTML  Ways to format in HTML –HTML Tag extensions –Converting Text to images –Page Layout with.
Chapter 10 m-way 搜尋樹與B-Tree
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Review: Three parts to a webpage: - Content - Structure  XHTML - Presentation  CSS In this chapter we will focus on introducing and examining the mechanics.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
Creating Your Own Webpage COSC Cascading Stylesheets Think of: HTML: content of your webpage HTML has tags CSS: presentation and appearance of your.
>> More on CSS Selectors. Pre-requisite Open the file called sample.txt Copy the all the text from the file Open your browser and go to codepen.io Paste.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Cascading Style Sheets. HTML 專有名詞 組成要素 : 段落 標籤 : 段落 屬性 : 段落 屬性名稱 : 段落 屬性值 : 段落 組成要素內容 : 段落 組成要素名稱 : 段落.
CSS: Cascading Style Sheets Part II. Style Syntax.
WebD Introduction to CSS By Manik Rastogi.
Cascading Style Sheets
HTML & CSS Jan Janoušek.
CSS for Styling By Jinzhu Gao.
Cascading Style Sheets™ (CSS)
Creating Your Own Webpage
>> The “Box” Model
Chapter 3 Style Sheets: CSS
Introduction to Web programming
CSS Style Sheets: Intro
Cascading Style Sheets Color and Font Properties
Cascading Style Sheets
The Internet 10/20/11 CSS Layout
Cascading Style Sheets
Focusing Your CSS Selectors
Cascading Style Sheets™ (CSS)
Presentation transcript:

CSS 選取器 (Selector)

Selector  selector {property: value; …}  h1 {color: #cc3333;}  選取器種類  元素選取器 (type/element selector)  類別選取器 (class selector)  識別碼選取器 (id selector)  關聯選取器 (contextual selector)  屬性選取器 ( attribute selector)  虛擬類別選取器 ( pseudoclass selector)  虛擬元素選取器 ( pseudoelement selector)

元素選取器 (type selector) h1 {text-align: center;} p {color: green; font-size: 36px;} div {border: 2px solid blue;} h2, h3 {font-size: 2.5em} h1, p, div {border-bottom: dashed 5px green} body {background-color: lime;} h1 {color: red;} h2 {color: blue;} p {color: green; font-size: 36px;} … 元素選取器 ※ ※

類別選取器 (class selector).setcolor {color: red;} h1.setcolor {color: blue;} p.setcolor {color: green;} … XHTML CSS JavaScript SMIL RSS XML PHP.classname {…} …

識別碼選取器 (id selector) #idname {…} … #header {color: blue;} #content {color: green;} #footer {color: red;} #sidebar {color: olive;} … XHTML CSS XML JavaScript

關聯選取器 (Contextual Selector) 後代 (Descendant) E F Any F element that is a descendant of an E element. 子代 (Child) E > F Any F element that is a child of an E element. 相鄰 (Adjacent) E + F Any F element immediately preceded by a sibling element E. Paragraph 1 XHTML JavaScript CSS XML PHP ASP.NET Paragraph 2 ul em li a li a em h2 > em li > a h2 > em h1 + p h1 + h2 h3 + p ul a > em

後代選取器 (Descendant Selector) li {color: green;} li em {color: red;} li a em {color: silver;} em {color: blue;} h1 em, h2 em {color: olive;} … XHTML JavaScript CSS XML PHP ASP.NET

子代選取器 (Child Selector) li {color: green;} li > em {color: red;} em {color: blue;} 網頁技術 XHTML JavaScript CSS

相鄰選取器 (Adjacent Sibling Selector) h1 {color: blue;} h1 + p {color: red;} h2 + p {color: silver;} p {color: green;} … 網頁技術 XHTML CSS JavaScript XML PHP

屬性選取器 (Attribute Selector) E[att] 任何 E 元素,其 att 屬性有設定者 Any E element that has an att attribute, regardless of its value. E[att = "val"] 任何 E 元素,其 att 屬性值等於 val 者 Any E element whose att attribute value is exactly equal to val. E[att ~= "val"] 任何 E 元素,其 att 屬性中含有 val 者 Any E element whose att attribute value is a list of space- separated values, one of which is exactly equal to val. E[att |= "val"] 任何 E 元素,其 att 屬性等於 val 或以 "val-" 開頭者 Any E element whose att value is either exactly val or beginning with "val" immediately followed by "-" ex. link[hreflang|="en"] "en", "en-US", "en-cockney"

Attribute Selector (CSS 3) [ attr ]  Ex: [title], [name], [value], … [ attr ^= val ] “starts with”  Ex: [id^=Sec], [href^=mailto], [title^=fish] [ attr *= val ] “contains”  Ex: [title~=fish], [href~=ncnu] [ attr $= val ] “ends with” * Ex: [href$=tw], [title$=fish] “fish food” “fish food”, “sword fish” “sword fish”

img[title] {border: 4px solid green;} img[title="first image"] {border: 10px dotted red;} img[title~="fish"] {border: 6px dashed blue;} …

虛擬類別選取器 ( pseudoclass selector)  a a:link 尚未連結過 a:visited 已連結過 a:hover 滑鼠移至連結上時 a:active 正連結中  :focus 應用到能接受焦點的元素  :first-child 應用到父元素之第一個子元素  :lang( ) 應用到指定語言的元素上

a 之虛擬類別 a:link {color: red; text-decoration: underline;} a:visited {color: blue; text-decoration: blink;} a:hover {color: green; text-decoration: overline;} a:active {color: oliver; text-decoration:line-through;} … 連結到其他網站 : 文魁資訊 Yahoo! 奇摩 台灣微軟

虛擬元素選取器 ( pseudoelement selector) :first-line :first-letter :before :after

p.pfirst:first-letter { font-size: 200%; font-style: italic; font-weight: bold} p.pquote:before, p.pquote:after {content: "\""; font-weight:bold} span {text-transform: uppercase} p.pquote span {text-transform: lowercase} T he few words of an article in The Economist. Other words of an article in The Economist. The other words of an article in The Economist.

Universal Selector * {color: purple;} DIV.danger * {color: red;} body * UL {color: gray;} body * * UL {border-right: thin solid green;}

Selector typePatternDescription Universal*Matches any element. TypeEMatches any E element. Class.infoMatches any element whose class attribute contains the value info. ID#footerMatches any element with an id equal to footer. DescendantE FMatches any F element that is a descendant of an E element. ChildE > FMatches any F element that is a child of an E element. AdjacentE + FMatches any F element immediately preceded by a sibling element E. AttributeE[att]Matches any E element that has an att attribute, regardless of its value. AttributeE[att=val]Matches any E element whose att attribute value is exactly equal to val. AttributeE[att~=val]Matches any E element whose att attribute value is a list of space-separated values, one of which is exactly equal to val. AttributeE[att|=val]Matches any E element whose att attribute has a hyphen-separated list of values beginning with val. pseudo-classE:first-childMatches element E when E is the first child of its parent. pseudo-classE:link E:visited Matches not yet visited (:link) or already visited (:visited) links. dynamic pseudo-class E:active E:hover E:focus Matches E during certain user actions. pseudo-classE:lang(c)Matches elements of type E that are in language c. pseudo-elementE:first-lineMatches the contents of the first formatted line of element E. pseudo-elementE:first-letterMatches the first letter of element E. pseudo-elementE:before E:after Used to insert generated content before or after an element’s content.

CSS Selector Reference :last-of-typep:last-of-typeSelects every element that is the last element of its parent :only-of-typep:only-of-typeSelects every element that is the only element of its parent :only-childp:only-childSelects every element that is the only child of its parent :nth-child(n)p:nth-child(2)Selects every element that is the second child of its parent :nth-last-child(n)p:nth-last-child(2) Selects every element that is the second child of its parent, counting from the last child :nth-of-type(n)p:nth-of-type(2)Selects every element that is the second element of its parent :nth-last-of-type(n)p:nth-last-of-type(2) Selects every element that is the second element of its parent, counting from the last child :last-childp:last-childSelects every element that is the last child of its parent

odd & even img:nth-of-type(odd) { float: left; … } img:nth-of-type(even) { float: right; … }