Css Selectors
Css Selectors
1
Batch 12
The universal selector selects the all the elements that are present in a
html document you can use this selector to apply the same rule to all the
elements of an html it is represented by an asterisk symbol (*{}).
SYNTAX: *{
margin:0;
padding:0;
The type selector matches all the elements specified in a list with the
given value to determine the elements to which the CSS rules
SYNTAX:
P, h2, h3 {font-size:30px}
The class selector allows you to apply CSS rules to the elements that
carry a class attribute whose value matches with the class attribute
specified in the selector
Applying the CSS rule to all the elements that have the class attribute of
the same value .The following code snippet shows how to apply the CSS
rule
Applying the CSS rule to the H1 element whose class attribute contains
into as its value the
Following code snippet shows how to apply the CSS style on H1element
2
Batch 12
THE ID SECTOR:
SYNTAX:
SYNTAX:
#selector{font-color:green}
The child selector matches the element that is an immediate child of another
element.
SYNTAX:
table>th{font-family: sans-serif}
Selector white space is used as the combinator as shown in the following code
snippet
3
Batch 12
SYNTAX:
H2+p{font-weight:bold}
Lets apply the preceding code snippet of a CSS file to the following HTML code
snippet
<H2>Heading</H2>
The CSS attribute selector selects elements on the basis of some specific
attributes or attribute values table lists the most common type of attribute
Selectors.
4
Batch 12
<html>
<head>
<title>css example</title>
<link rel="stylesheet"type="text/css"href="example.css">
</head>
<body>
<div id="div">
<p>this is paragraph</p>
</div>
<table border="0">
<tr>
<th>living being</th>
<th>sheleter</th>
5
Batch 12
</tr>
<tr>
<td class="code">lion</td>
</tr>
<tr>
<td class="code">man</td>
</tr>
<tr>
<td class="code">fish</td>
</tr>
<tr>
<td class="code">bird</td>
</tr>
</table>
</body>
</html>
6
Batch 12
Result:
*{margin:10; }
body
color:purple;
background-color:#fff00;
background-image:url(image3.jpg);
background-size:cover;
.code1
7
Batch 12
font-family:sans-serif;
h2,h3{font-style:italic}
p{font-size:12pt}
table
background-color:magneta;
border-style:solid;
border-width:2px;
border-color:magneta;
th
background-color:pink;
font-weight:bold;
padding:3px;
td{padding:3px}
.code
font-size:10pt;
font-family:fantasy;
8
Batch 12
font-weight:lighter;
#code2
text-decoration:overline;
p[id]
color:grey;
a[title]
color:grey;
div>p{color:orange}
table th{color:blue}
#div h3+p{background:grey}
<!doctype html>
<html>
<head>
9
Batch 12
</head>
<body>
</div>
<input id="text">
<script type="text/javascript">
if(document.querySelector)
var lb1=document.querySelector('#label1')
var lb2=document.querySelector('#label2')
var lb3=document.querySelector('#label3')
lb1.onmouseover=function()
10
Batch 12
document.querySelector('#text').value="this is
blue color";
document.querySelector('#text').style.color="blue";
document.querySelector('#div1').style.background="blue"
lb2.onmouseover=function()
document.querySelector('#text').value="this is
red color";
document.querySelector('#text').style.color="red";
document.querySelector('#div1').style.background="red"
lb3.onmouseover=function()
document.querySelector('#text').value="this is
yellow color";
document.querySelector('#text').style.color="yellow";
document.querySelector('#div1').style.background="yellow"
11
Batch 12
</script>
</body>
</html>
Result:
12
Batch 12
Code:
<!DOCTYPE HTML>
<head>
</HEAD>
<BODY>
<FORM id="myform">
<INPUT type="submit"/>
</FORM>
<SCRIPT type="text/javascript">
if(document.querySelector)
docment.queryselector('#myform').onsubmit=function()
13
Batch 12
var
checkflowers=this.querySelectorAll('input[name="flowers"]:checked')
</B></BR>")
for(vari=0;i<checkflowers.length;i++)
document.write("<LI>"+value+"<Li/>" )
return false
</SCRIPT>
</BODY>
</HTML>
Result:
14
Batch 12
15