Tuesday 20 May 2014

Html css Psecudo Class

:first-child Selector

We can use the style for first of every div paragraph or anything else.

For it we can use the selector :first-child

like for paragraphs <p>

and we want to make the first paragraph with red color 

we can make it as in css

p:first-child{ color: red; }

this property will make the first line of every paragraph will show in red color 


Here is the example .





<!DOCTYPE html>
<html>
<head>
<style>
p:first-child
{
background-color:red;
}
</style>
</head>
<body>

<p>This paragraph is the first child of its parent (body).</p>

<h1>Welcome world</h1>
<p>This paragraph is not the first child of its parent.</p>

<div>
<p>This paragraph is the first child of its parent (div).</p>
<p>This paragraph is not the first child of its parent.</p>
</div>


</body>
</html>

After running the code you will see that the first paragraph and and first paragraph of every div is red 

No comments:

Post a Comment