•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 392,068 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,271 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 1136 | Replies: 1
![]() |
Hello, welcome to the forum. Please do us all the favor of using complete sentences with proper spelling and punctuation. "Abbreviated" speech is strongly discouraged.
An "id selector" will apply to a specific element, the element with that id. They start with a "#" sign.
So in this style declaration, the second paragraph would apply the style.
A class selector on the other hand, is generic, and can be applied to multiple elements of differing types. Class declaractions begin with a ".", and are applied using an element's "class" attribute:
Note that ID selectors are more specific in the cascading hierarchy. Thus if the "myStyle" declaration also specified a color, the "myStyle" paragraph would be that color rather than green.
An "id selector" will apply to a specific element, the element with that id. They start with a "#" sign.
So in this style declaration, the second paragraph would apply the style.
<html>
<head>
<title>ID selector</title>
<style type="text/css">
#myStyle { letter-spacing: 0.3em }
</style>
</head>
<body>
<p id="noStyle">Normal width</p>
<p id="myStyle">Wide text</p>
</body>
</html> <html>
<head>
<title>ID selector</title>
<style type="text/css">
#myStyle { letter-spacing: 0.3em };
.greenStyle { color: green };
</style>
</head>
<body>
<h1 class="greenStyle">Everything is Green</h1>
<p id="noStyle" class="greenStyle">Normal width</p>
<p id="myStyle" class="greenStyle">Wide text</p>
</body>
</html>![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb HTML and CSS Marketplace
- Layout Tables to CSS (HTML and CSS)
- CSS center vertical (HTML and CSS)
- CSS Quicky (HTML and CSS)
Other Threads in the HTML and CSS Forum
- Previous Thread: getElementById is not a function
- Next Thread: Help wih CSS



Linear Mode