Presentation is loading. Please wait.

Presentation is loading. Please wait.

การจัดรูปแบบเว็บด้วย CSS การเขียนโปรแกรมเว็บ. Selectors & cascading PatternMeaning *Universal selector: matches any element. EType selector: matches any.

Similar presentations


Presentation on theme: "การจัดรูปแบบเว็บด้วย CSS การเขียนโปรแกรมเว็บ. Selectors & cascading PatternMeaning *Universal selector: matches any element. EType selector: matches any."— Presentation transcript:

1 การจัดรูปแบบเว็บด้วย CSS การเขียนโปรแกรมเว็บ

2 Selectors & cascading PatternMeaning *Universal selector: matches any element. EType selector: matches any E element (i.e., an element of type E; e.g. H1 or P). E FDescendant selector: matches any F element that is a descendant of an E element. E > FChild selector: matches any F element that is a child of an element E. E + FAdjacent siblings selector: Matches any F element immediately preceded by an element E. E[foo]Attribute selector: matches any E element with the "foo" attribute set (whatever the value). E[foo="warning"]Attribute selector: matches any E element whose "foo" attribute value is exactly equal to "warning". E[foo~="warning"] Attribute selector: matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning". E[lang|="en"] Attribute selector: matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en“ (e.g. en-US). DIV.warningHTML only. The same as DIV[class~="warning"]. E#myidID selector: matches any E element ID equal to "myid". E:lang(c) Pseudo-class selector: matches element of type E if it is in (human) language c (the document language specifies how language is determined). E:first-childPseudo-class selector: matches element E when E is the first child of its parent. E:link, E:visited Pseudo-class selector: matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). E:active, E:hover, E:focusDynamic Pseudo-class selector: matches E during certain user actions. E:first-line, E:first-letterPseudo-element selector: matches the first formatted line or letter of element E. Works in most browsers (incl. IE)

3 Measurement Values UnitDescription %percentage ininch cmcentimeter mmmillimeter em 1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses ex one ex is the x-height of a font (x-height is usually about half the font-size) ptpoint (1 pt is the same as 1/72 inch) pcpica (1 pc is the same as 12 points) pxpixels (a dot on the computer screen)

4 Working with Selector Patterns  On a Web page, elements are nested within other elements, forming a hierarchical tree structure New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 4

5 Working with Selector Patterns  To take advantage of this tree structure, CSS allows you to create contextual selectors that express the location of an element within the hierarchy of elements parent descendant {styles} li b {color: blue} li b, h2 {color: blue} #notes b {color: blue} * {color: blue} p > b {color: blue} New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 5

6 Working with Selector Patterns  On occasion you might also need to select elements based on their attribute values element[att] {styles} a[href] {color: blue} New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 6

7 Using Selector Patterns  To apply a style to all elements in the document, use the * selector  To apply a style to a single element, use the e selector, where e is the name of the element  To apply a selector to a descendant element, f, use the e f selector, where e is the name of the parent element and f is an element nested within the parent  To apply a selector to a child element, f, use the e > f selector, where e is the name of a parent element and f is an element that is a direct child of the parent  To apply a selector to a sibling element, use the e + f selector, where e and f are siblings and f immediately follows e in the document tree New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 7

8 Applying Styles to Lists  To specify the list marker displayed by the browser, you can apply the style list-style-type: type New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 8

9 Applying Styles to Lists New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 9

10 Applying Styles to Lists  Most browsers place the list marker to the left of the block, lining up the markers with each list item list-style-position: position New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 10

11 Working with Classes  The class attribute is used when you want to identify elements that share a common characteristic...  You can use the class attribute to assign the same style to multiple elements sharing the same class value.class {styles} New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 11

12 Using Pseudo-Classes and Pseudo-Elements  A pseudo-class is a classification of an element based on its current status, position, or use in the document selector:pseudo-class {styles} New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 12

13 Using Pseudo-Classes and Pseudo-Elements New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 13

14 Using Pseudo-Classes and Pseudo-Elements  Pseudo-elements are abstracted from what we know of an element’s content, use, or position in the document selector:pseudo-element {styles} New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 14

15 Positioning Objects with CSS New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 15

16 Positioning Objects with CSS  Create div containers for each note  Add a class attribute to apply a common set of styles  Each note should have a unique id New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 16

17 Positioning Objects with CSS  CSS-P (CSS-Positioning) became part of the specification for CSS2, and positioning styles were some of the first CSS2 styles to be adopted by browsers position: type; top: value; right: value; bottom: value; left: value;  Absolute positioning enables you to place an element at specific coordinates either on a page or within a containing element position: absolute; left: 100px; top: 50px New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 17

18 Positioning Objects with CSS  Relative positioning is used to move an element relative to its default position on the page position: relative; left: 100px; top: 50px  You can fix an element at a specific spot in the document window while the rest of the page scrolls by setting the value of the position style to fixed  You can assign the inherit position style to an element so that it inherits the position value of its parent element New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 18

19 Positioning Objects with CSS New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 19

20 Working with Overflow and Clipping  If you want to force an element into a specified height and width, you have to define how the browser should handle a situation where content overflows the space allotted to the object overflow: type New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 20

21 การสร้างฟอร์มด้วย HTML การเขียนโปรแกรมเว็บ

22 Creating a Web Form Forms are created using the form element, structured as follows: elements  Where attributes are the attributes that control how the form is processed and elements are elements places within the form. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 22

23 Creating a Web Form Form attributes usually tell the browser the location of the server-based program to be applied to the form’s data. Always specify an id or name for the form. Two attributes are available to identify the form: id and name. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 23

24 Creating a Web Form The syntax of the id and name attributes are as follows: …  Where name is the name of the form and id is the id of the form. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 24

25 Creating a Field Set  HTML and XHTML allow you to organize option buttons into a group of fields called field sets. controls where id identifies the field set and controls are the control elements associated with fields within the field set New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 25

26 Creating a Field Set  To add a caption to a field set, add the following tag after the opening tag: text Where text is the text of the field set caption. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 26

27 Creating Input Boxes  The general syntax of input elements is as follows: Where type specifies the type of input control, and the name and id attributes provide the control’s name and id. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 27

28 Creating Input Boxes New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 28

29 Working with Field Labels  You can also expressly link a label with an associated text element for scripting purposes.  The syntax for creating a form label is as follows: label text Where id is the value of the id attribute for a field’s control element, and label text is the text of the label. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 29

30 Setting the Width of an Input Box  To change the width of an input box, use the width attribute, which is displayed as follows: #id{width: value} Where id is the id of the control and value is the width you want to apply to the input box New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 30

31 Setting the Width of an Input Box New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 31

32 Creating Option Buttons  Option buttons, or radio buttons allow users to make selections.  Unlike selection lists, option buttons only allow the user to select one option at a time. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 32

33 Creating a Group of Option Buttons  To create a group of option buttons associated with a single field, add the elements: to the Web form, where name identifies the field associated with the collection of option buttons; id1, id2, id3, etc. identify the specific options; and value1, value2, value3, etc. are the field values associated with each option.  To specify the default option, add the following attribute to the tag: checked="checked" New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 33

34 Creating a Selection List  A selection list is a list box from which a user selects a particular field value or set of field values.  Selection lists are useful when there are a fixed set of possible responses from the user.  You can create a selection list using the element.  You can specify each individual selection item using the element. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 34

35 Setting the Selection List Size  You can change the number of options displayed in the selection list by modifying the size attribute. The syntax is as follows: … Where value is the number of items that the selection list displays in the form. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 35

36 Setting the Selection List Size New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 36

37 Making Multiple Selections  Add the multiple attribute to the select element to create multiple selections: … New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 37

38 Working with Check Boxes  To create a check box, use:  Where the name and id attributes identify the check box controls and the value attribute specifies the value sent to the server if the check box is selected.  To specify that a check box be selected by default, use the checked attribute as follows: New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 38

39 Specifying the Tab Order  Users typically navigate through a form with the tab key.  You can specify an alternate tab order by adding the tabindex attribute to any control element in your form.  The syntax is as follows: This syntax assigns the tab index number “1” to the fname field from the registration form. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 39

40 Working with Text Area Control  Text area boxes allow users to enter comments.  An input box would be too small to accommodate the length of text for this use. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 40

41 Working with Text Area Control  To create a text area box, use the textarea element:... Where the rows and cols attributes define the dimensions of the input box and the rows attribute indicates the number of lines in the input box. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 41

42 Working with Text Area Control New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 42

43 Working with Text Area Control New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 43

44 Working with Form Buttons  Buttons are a type of control element that performs an action.  Types of buttons:  Command button  Submit button  Reset button New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 44

45 Creating a Command button  Command buttons are created using the tag:  Submit buttons submit forms to the server for processing when clicked. Syntax is as follows:  Reset buttons reset forms to their original (default) values. Syntax is as follows: New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 45

46 Completed Form New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 46

47 Designing a Custom Button  Use the button element for greater artistic control over the appearance of a button. content Where the name and value attributes specify the name of the button and the value sent to a server-based program, the id attribute specifies the button’s id, the type attribute specifies the button type, and the content is page content displayed within the button. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 47

48 Creating File Buttons  File buttons are used to select files so that their contents can be submitted for processing to a program. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 48

49 Working with Hidden Fields  Hidden fields are added to a form, but not displayed in the Web page. The syntax is as follows: New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 49

50 Working with Form Attributes  After adding the elements to your form, you’ll need to specify where to send the form data and how to send it. Use the following attributes: … Where url specifies the filename and location of the program that processes the form and the method attribute specifies how your Web browser sends data to the server. The enctype attribute specifies the format of the data stored in the form’s field. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 50

51 Working with Form Attributes  The method attribute can have one of two values:  Post  Get  The get method is the default; get appends the form data to the end of the URL specified in the action attribute.  The post method sends form data in a separate data stream, allowing the Web server to receive the data through “standard input.” New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 51

52 Using the mailto Action  The mailto action accesses the user’s own e-mail program and uses it to mail form information to a specified e-mail address.  Bypasses the need for server-based programs.  The syntax is as follows: <form action-mailto:e-mail method=“post” enctype=“text/plain”> …  Where e-mail_address is the e-mail address of the recipient in the form. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 52

53 Tips for Creating Effective Forms  Mark fields that are required, but also limit the number of unrequired fields. Don’t overwhelm your users with requests for information that is not really essential. Keep your forms short and to the point.  If you need to collect a lot of information, break the form into manageable sections spread out over several pages. Allow users to easily move backward and forward through the forms without losing data. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 53

54 Tips for Creating Effective Forms  Provide detailed instructions about what users are expected to do. Don’t assume that your form is self-explanatory.  If you ask for personal data and financial information, provide clear assurances that the data will be secure. If possible, provide a link to a Web page describing your security practices.  Clearly indicate what users will receive once the form is submitted, and provide feedback on the Web site and through e-mail that tells them when their data has been successfully submitted. New Perspectives on HTML, XHTML, and Dynamic HTML, 4e 54


Download ppt "การจัดรูปแบบเว็บด้วย CSS การเขียนโปรแกรมเว็บ. Selectors & cascading PatternMeaning *Universal selector: matches any element. EType selector: matches any."

Similar presentations


Ads by Google