devkoustav
Posted on October 14, 2022
Method 1 : Using <dfn>..</dfn>
Tag in HTML with the title
attribute and styling the title
attribute with CSS
HTML
<dfn title="Official website is dev.to">Dev</dfn> is a community
of software developers getting together to help one another out.
The text(Here Dev) within the <dfn>
tag will be in italic by default.
We will style title="Official website is dev.to"
attribute to our requirements.
CSS
dfn[title] {
position: relative;
}
dfn[title]::after {
content: attr(title);
position: absolute;
display: block;
background-color: #121b22;
color: #c8cccf;
font-size: 16px;
bottom: 100%;
white-space: nowrap;
padding: 10px;
border-radius: 6px;
left: 30%;
transform: scale(0);
transition: ease-out 300ms;
}
dfn[title]:hover::after {
transform: scale(1);
}
Method 2 : Using Only Pseudo Elements ::before
or ::after
with Pseudo class :hover
We will display a text over the word dev.
HTML
<span id="dev-describe">Dev</span> is a community of software developers getting together to help one another out.
We will use this sequence -
element --> on hover --> display ::before
or ::after
CSS
#dev-describe:hover::before {
content: "Official website is dev.to";
background-color: #ff746b;
color: #ffffff;
position: absolute;
bottom: 10px;
padding: 6px 12px;
border-radius: 6px;
}
And then position your content as per your requirements!
Method 3 : Using the attribute data-*
for the element
HTML
<a href="https://dev.to/" data-explain="A community of software developers getting together to help one another out">Dev</a>
CSS
a[data-explain] {
position: relative;
}
a[data-explain]::after {
content: attr(data-explain);
position: absolute;
display: block;
background-color: #121b22;
color: #c8cccf;
font-size: 16px;
bottom: 100%;
white-space: nowrap;
padding: 10px;
border-radius: 6px;
left: 30%;
transform: scale(0);
transition: ease-out 300ms;
}
a[data-explain]:hover::after {
transform: scale(1);
}
Check out the whole series!
Share itš with someone who may benefit from this
ā¤ļø Happy Coding!
Follow for more!
š šŖ š
š©
devkoustav
Posted on October 14, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.