<div class="hover-1" data="Text"></div>
<div class="hover-2" data="Text"></div>
<div class="hover-3" data="Text"></div>
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
height: 100vh;
background: #eee;
}
div {
margin: auto;
width: 200px;
padding: 20px;
text-align: center;
box-sizing: border-box;
}
// ここからhoverコード
.hover-1{
position: relative;
background: #fff;
&::before{
content: attr(data);
display: block;
}
&::after{
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
height: 5px;
background-color: #333;
transition: width 300ms;
width: 0;
}
&:hover{
&::after{
width: 100%;
}
}
}
.hover-2{
position: relative;
background: #fff;
&::before{
content: attr(data);
display: block;
}
&::after{
content: '';
display: block;
position: absolute;
bottom: 0;
right: 0;
height: 5px;
background-color: #333;
transition: width 300ms;
width: 0;
}
&:hover{
&::after{
width: 100%;
left: 0;
}
}
}
.hover-3{
position: relative;
background: #fff;
&::before{
content: attr(data);
display: block;
}
&::after{
content: '';
display: block;
position: absolute;
bottom: 0;
right: 0;
left: 0;
margin: auto;
justify-content: center;
height: 5px;
background-color: #333;
transition: width 300ms;
width: 0;
}
&:hover{
&::after{
width: 100%;
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.