link 悬停时展开项目符号
Expanding bullets on link hover
我正在尝试制作一个 link 在悬停时扩展伪元素 before。
.open-link::before {
content: '•';
position: relative;
display: inline-block;
width: 10px;
transition: width .3s;
margin-right: 10px;
}
.open-link:hover::before {
content: '• • •';
width: 30px;
}
<a class="open-link" href="#">Link</a>
但是过渡很奇怪,看起来点是从底部跳出来的。如何平滑它,让它看起来像是从左边展开的?
Fiddle https://jsfiddle.net/1u0tzxfg/
更新
这里有一个更好的过渡:
.open-link {
display: flex;
align-items: center;
text-decoration: none;
}
.open-link::before {
content: '• • •';
overflow: hidden;
width: 10px;
position: relative;
display: inline-block;
transition: all 0.3s ease;
margin-right: 10px;
white-space: nowrap;
}
.open-link:hover::before {
width: 50px;
}
<a class="open-link" href="#">Link</a>
只需添加:white-space: nowrap;
到 .open-link::before 标签。
<style>
.open-link::before {
content: '•';
position: relative;
display: inline-block;
width: 10px;
transition: width .3s;
margin-right: 10px;
white-space: nowrap;
}
.open-link:hover::before {
content: '• • •';
width: 30px;
}
</style>
<a class="open-link" href="#">Link</a>
我正在尝试制作一个 link 在悬停时扩展伪元素 before。
.open-link::before {
content: '•';
position: relative;
display: inline-block;
width: 10px;
transition: width .3s;
margin-right: 10px;
}
.open-link:hover::before {
content: '• • •';
width: 30px;
}
<a class="open-link" href="#">Link</a>
但是过渡很奇怪,看起来点是从底部跳出来的。如何平滑它,让它看起来像是从左边展开的?
Fiddle https://jsfiddle.net/1u0tzxfg/
更新
这里有一个更好的过渡:
.open-link {
display: flex;
align-items: center;
text-decoration: none;
}
.open-link::before {
content: '• • •';
overflow: hidden;
width: 10px;
position: relative;
display: inline-block;
transition: all 0.3s ease;
margin-right: 10px;
white-space: nowrap;
}
.open-link:hover::before {
width: 50px;
}
<a class="open-link" href="#">Link</a>
只需添加:white-space: nowrap;
到 .open-link::before 标签。
<style>
.open-link::before {
content: '•';
position: relative;
display: inline-block;
width: 10px;
transition: width .3s;
margin-right: 10px;
white-space: nowrap;
}
.open-link:hover::before {
content: '• • •';
width: 30px;
}
</style>
<a class="open-link" href="#">Link</a>