Class Selector and ID Selector
Class Selector and ID Selector
*{
color:#09F;
font-size: 20px;
line-height: 25px;
margin: 0;
padding: 0;
}
Style div
<p>This is some text.</p>
<div style="color:#936">
<h3>Sample heading wthin div tags</h3>
<p>This is some text in a div element.</p>
<p>This is another Paragraph .</p>
</div>
<div style="color:#F36">
<h3>Sample heading wthin div tags</h3>
<p>This is some text in a div element.</p>
<p>This is another Paragraph .</p>
</div>
ID selector
Used to uniquely identify that element from other elements on the page.
Giving an element a unique identity allows you to style it differently than any other instance of the
same element on the page.
It is important that no two elements on the same page have the same value for their id attributes
(otherwise the value is no longer unique).
Name preceded by a hash character (“#”)
#content
Example
#content {
margin: 30px;
padding-bottom: 20px;
text-align: justify;
width: 140px;
color: red;
background-color: #CFF;}
#samp {
height: 200px;
width: 140px;
background-color: #9F0;}
Cont’d
<div id="content"> <div id="samp">
<h1>sample id</h1> <h1>Content</h1>
<br> <p>ID can be used to identify one
element.one unique element</p>
<p>Any HTML element can have the id
attribute applied to it. The value of this <p>sample para</p>
attribute is the element's unique identifier</p>
</div>
<p> ID can be used to identify one
element</p>
</div>
CSS class and ID
ID's are unique
Each element can have only one ID
Each page can have only one element with that ID
p.myClass{
margin: 30px;
}
<p>Analog synthesizers are often said to have a "warmer" sound than their digital counterparts.</p>
<p class="myClass">Analog synthesizers are often said to have a "warmer" sound than their digital
counterparts.</p>
p{
Multiple classes
width: 200px;
border: 2px solid #0088dd;
padding: 10px;
background:#FCC;}
<p >You can use the same class on multiple elements as well as multiple classes in same
element.</p>
<p class="highlight indent">This paragraph contains the styles of highlight and indent
classes .</p>
p::first-letter {
color:#F00;
font-weight: bold;
}
Pseudo-class
A pseudo.-class is way of specify a state.