|
CSS Home
CSS TutorialIntroductionCSS Advantages CSS Syntax Implementing CSS CSS Class CSS ID CSS Font CSS Text CSS Background Code CSS Border CSS Margin CSS Padding CSS Lists CSS Height & Width CSS Positioning CSS Float CSS Layers CSS Summary CSS CodesCSS AlignCSS bgcolor CSS Cellpadding CSS Cellspacing CSS Floating Menu CSS Hyperlinks CSS Leading Inline Style Sheets Embedded Style Sheets External Style Sheets CSS Scrollbars CSS Table Width CSS Print Version CSS Table-layout CSS ExamplesCSS ExamplesCSS Table-layout Example CSS ReferenceCSS Mini TutorialCSS Properties CSS Color Codes CSS Template CSS Media Types
$1.99 Domain Names
With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99. |
CSS idIDs allow you to assign a unique identifier to an HTML element. This allows you to define a style that can only be used by the element you assign the ID to. CSS ID SyntaxThe syntax for declaring a CSS ID is the same as for classes - except that instead of using a dot, you use a hash (#).
Again, similar to classes, if you want to use the same id name for multiple elements, but each with a different style, you can prefix the hash with the HTML element name.
CSS ID Example
This results in: CSS IDCSS IDs can be very useful IDs vs ClassesGiven classes and IDs are very similar, you may be wondering which one to use. This depends on the situation. When to use classesYou should use classes when your style needs to be applied multiple times on the same page. For example, you might have many h1 elements that need the same style applied. When to use IDsYou should use IDs if only one element on the page should have the style applied, and/or you need a unique identifier for that element. For example, you might assign an ID to a div tag which contains your left menu. The styles for this ID could contain the position, background-color, float properties, size etc. You probably wouldn't want any other element on the page to use this particular style. Another useful thing about IDs is that you can use the Document Object Model (DOM) to refer to them. This enables you to use JavaScript/DHTML techniques to build a much more interactive web site. |
Need Website Content?
Get unique, quality digital content for your website.
|