|
ID & Class
Next articles: Font Style - These elements are very similar to the FONT tag of HTML3.2. Fonts can be specified by type (family), style...
Text Style - How do you align text and images? How do you specify text colors? What about other text tricks?...
Link Style - You may have noticed some sites have links that change color or do not have an underline below them...
Background Style - Background colors and images can be placed as a main page background, a table or cell background, or even a...
List Style - Ever wanted to be more creative with the " bullets " used when creating O rdered L ists and U nordered L ists?...
|
ID and CLASS are commands used to give a "name" to a certain CSS format. These are used when you want to apply a certain formatting style at specified areas only. Not as a common style.
ID Elements The ID is used to apply a general format style to a single instance or HTML tag. It places a NAME on a certain style. Using an ID or CLASS element requires the code to be specified in the HEAD area (embeded) or on an external css page. The "using" code is in an HTML tag in the BODY area (inline).
| HEAD area |
<style type="text/css"> <!- #abc {color: #ff0000;} -> </style> |
|
| BODY area |
<p id="abc"> First </p> <p> Second </p> |
First Second | The # is used to specify an ID element. It says "when this ID is found in a tag, use this format". The ID can only be used by one element. This limits the usage on this type of formatting, but at times, that is all you need. For a more versatile formatting, CLASS is used.
Class Elements CLASS elements are very similar to ID elements. ID elements are used for a single instance or area. The CLASS elements are used for many instances or a larger area. Using an ID or CLASS element requires the code to be specified in the HEAD area (embeded) or on an external css page. The "using" code is in an HTML tag in the BODY area (inline).
| HEAD area |
<style type="text/css"> <!- .abc {color: #ff0000;} -> </style> |
|
| BODY area |
<p class="abc"> First </p> <p> Second </p> <h3 class="abc"> Third </h3> |
First Second Third | Differences between ID and CLASS ?
- The . is used in place of the #
- class is used in place of id
- ID is for single instances or tags.
- CLASS is used for multiple instances or tags.
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.
|
Link to this article, just copy and paste following code:
<a href=http://www.torroid.com/article1461.html>ID & Class</a>
|
Article viewed 341 time(s). Read more: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | |