我在:before属性中添加'>'到链接,但是当应用:hover效果时也要采用样式, text-decoration: underline;
因此,我需要不要在:before中添加的内容中应用效果,我试图解决此问题选项
a:before {
content: '> ';
position: relative;
display: inline-block;
margin-right: 5px;
pointer-events: none;
}
a:before:hover {
content: '>';
pointer-events: none;
}
a:before:hover {
text-decoration:none;
}
但没有办法。
这就是链接与悬停的行为方式
这是我的代码示例,结构,<a>
里面<p>
是因为内容来自文本编辑器
.super {
color: rgb(40, 40, 40);
background-color: rgb(239, 239, 239);
margin-bottom: 35px;
padding: 10px;
}
p {
position: relative;
word-break: break-word;
font-size: 17px;
padding: 0px;
}
a {
left: 0px;
display: flex;
position: relative;
left: 0;
display: flex;
text-decoration: none;
}
a::before {
content: '> ';
position: relative;
display: inline-block;
margin-right: 5px;
}
a:hover{
text-decoration:underline;
}
<div class='super'>
<p>
<a href='https://google.com' target='_blanck'>Example to link</a>
</p>
</div>
如果无法正常工作,您的代码中有两件事会停止:
display:flex
:hover:before
但这没关系,因为display:flex
无论如何它都无法工作。对于a
元素的默认显示,文本下划线不会影响使用:before
伪元素添加的内容。但是,使用display:flex
更改将改变其显示方式,并导致将文本下划线添加到添加的内容a:before
以及链接文本中:
工作示例:
更新:满足您对长链接上缩进的新新要求,并且无法更改HTML。
.super {
color: rgb(40, 40, 40);
background-color: rgb(239, 239, 239);
margin-bottom: 35px;
padding: 10px;
}
p {
position: relative;
word-break: break-word;
font-size: 17px;
padding: 0px;
}
a {
position: relative;
text-decoration: none;
display: block;
padding-left: 15px;
}
a:before {
content: '>';
position:absolute;
left:0;
top: 0;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
a:hover:before{
text-decoration:none;
}
<div class='super'>
<p>
<a href='https://google.com' target='_blanck'><span>This is a very long link This is a very long link This is a very long link This is a very long link This is a very long link This is a very long link This is a very long link This is a very long link This is a very long link</span></a>
</p>
</div>
另外,仅供参考,使用:hover
和:before
在一起的正确方法是:hover:before
,但是在这种情况下,使用时并没有什么不同,display:flex
如下所示:
例如使用正确的CSSa:hover:before
用 display:flex
(正如你可以看到它不工作):
.super {
color: rgb(40, 40, 40);
background-color: rgb(239, 239, 239);
margin-bottom: 35px;
padding: 10px;
}
p {
position: relative;
word-break: break-word;
font-size: 17px;
padding: 0px;
}
a {
left: 0px;
display:flex;
position: relative;
text-decoration: none;
}
a::before {
content: '> ';
position: relative;
display: inline-block;
margin-right: 5px;
text-decoration:none!important;
}
a:hover{
text-decoration:underline;
}
a:hover::before {
text-decoration:none!important;
}
<div class='super'>
<p>
<a href='https://google.com' target='_blanck'>Example to link</a>
</p>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句