HTML unit 2-3

Pseudo-classes:-

HTML pseudo-classes are used in CSS to select elements based on their state or a characteristic that's not inherent in the element. For example, you might want to select a link that has been visited or select an input element that is currently being hovered over with a mouse. Some common pseudo-classes include:

  • :hover: Selects an element when the user hovers over it with a mouse.
  • :active: Selects an element that is being activated, such as a button that is being clicked.
  • :focus: Selects an element that has focus, such as an input field that has been selected for typing.
  • :visited: Selects a link that has been visited.
  • :first-child: Selects an element that is the first child of its parent element.
  • :last-child: Selects an element that is the last child of its parent element.
  • :nth-child(n): Selects an element that is the nth child of its parent element.

Pseudo-classes are used in CSS in conjunction with selectors to apply specific styles to certain elements. For example, the following code would change the color of a link to red when it's being hovered over:

code:01

<html>
<head>
<style>
/* Selects the link when it's being hovered over */
a:hover {
color: red;
}

/* Selects the button when it's being clicked */
button:active {
background-color: yellow;
}

/* Selects the input field when it has focus */
input:focus {
border: 2px solid blue;
}

/* Selects the visited link */
a:visited {
color: green;
}

/* Selects the first child of the parent element */
li:first-child {
font-weight: bold;
}

/* Selects every 3rd child of the parent element */
li:nth-child(3) {
background-color: lightgray;
}
</style>
</head>
<body bgcolor="lightpink">
<a href="#">This is a link</a>
<br>
<button>Click me</button>
<br>
<input type="text">
<br>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</body>
</html>

output:-images-01-1, 01-2, 01-3,01-4. 

open browser only to see the color patterns


 

 

 

 

 

 

i move to link change the color to red but i cannot click the link

  







I click the link color change to green

 


 

 

 

 

 

write the search bar item 1 and i click the button(click me) the color will be change to the yellow

 







Pseudo-Elements:-

<html>
<head>
<style>
.example::before {
content: "Before ";
color: blue;
}

.example::after {
content: " After";
color: blue;
}

.example p::first-letter {
font-size: 200%;
color: green;
}

.example p::first-line {
font-weight: bold;
color: red;
}

::selection {
background: yellow;
}
</style>
</head>
<body>
<div class="example">
<p>This is a sample text.</p>
</div>
</body>
</html>

output:-images02-1,02-2. 

 open browser only to see the color patterns 

image-02-1


 

 



I drag the or select all the browser page color change to text

image-02-2


 

 

 

 

 

Comments

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

DBMS Degree Lab Records

Unit 2: Foundations of Ownership, Security Related Concepts in Blockchain

Unit-1 Foundations of Software Systems and Blockchain

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

6)what are the various service of internet and protocols ICT-unit-1