Monday, January 13, 2025
HomeProgrammingAdd hover text without JavaScript like we hover on a user's profile...

Add hover text without JavaScript like we hover on a user’s profile using HTML and CSS.

Add hover text without JavaScript like we hover on a user’s profile using HTML and CSS.

To display hover text (often called a tooltip) without JavaScript, you can use the title attribute in HTML or the :hover pseudo-class in CSS. Here’s how:

Using the title attribute:

See also  Difference Between Abstract Class and Interface in Java

User Profile

When you hover over the link, the browser will display the tooltip with the text “Click here to view the profile.”

Using CSS :hover for custom styling:

User Profile
Click here to view the profile

.tooltip {
position: relative;
display: inline-block;
}

See also  Implementation of a Stack in JavaScript

.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: white;
text-align: center;
border-radius: 5px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 100%;
left: 50%;
margin-left: -60px;
}

.tooltip:hover .tooltiptext {
visibility: visible;
}

This example shows a custom tooltip when you hover over the “User Profile” link, all without JavaScript.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x