简体   繁体   English

下划线CSS链接移动宽度

[英]Underline CSS link mobile width

I have this css code and it works fine on large desktops. 我有此CSS代码,在大型桌面上也能正常工作。 Once i switch to mobile the underline is under the whole element. 一旦我切换到移动设备,下划线就位于整个元素的下方。 I would like to have the underline only under the words in sentence. 我只想在句子中加上下划线。 Any help to achive this will be welcomed. 为实现这一目标的任何帮助将受到欢迎。 Here is the HTML: 这是HTML:

a class="underline-link" 
        href="#">Made with Lorem Ipsum Dolor Sit Amed 

And here is the CSS:

.underline-link:after { background-color: #0982ae } .underline-link:hover { color: #0982ae } .underline-link:after { content: ""; height: 1px; left: 0; opacity: 0; pointer-events: none; position: absolute; top: 100%; transform: translateY(1px); transition: all .15s cubic-bezier(.39, .575, .565, 1); transition-property: opacity, transform; width: 100% } .underline-link:focus { outline: none } .underline-link { font-family: -apple-system, BlinkMacSystemFont, segoe ui, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, arial, sans-serif; -webkit-font-smoothing: subpixel-antialiased; text-decoration: underline; color: #b3b3b3; cursor: pointer; position: relative; display: inline-block; color: #087096; font-size: 14px; font-weight: 400; text-decoration: none; -moz-osx-font-smoothing: grayscale } .underline-link:hover { text-decoration: none } .underline-link:focus:after, .underline-link:hover:after { opacity: 1; transition-delay: .2s; transition-duration: .15s; transform: translateY(-3px) translateZ(0) }

Live preview: On Codepen 实时预览: 在Codepen上

Ok i found the issue, it's about position: absolute; 好的,我发现了问题,这与位置有关:绝对; you can check the line position if you change bottom: 0; 如果更改底部,则可以检查行的位置:0; to top: 0; 至顶部:0; i've to think how to trick over it and if there's some way to solve it, at the moment i don't have any solution on mind. 我必须考虑如何欺骗它,如果有解决方法,目前我还没有任何解决办法。

 h2 > a { position: relative; color: #000; line-height:50px; text-decoration: none; } h2 > a:hover { color: #000; } h2 > a:before { content: ""; position: absolute; width: 100%; height: 2px; bottom: 0; left: 0; background-color: #000; visibility: hidden; -webkit-transform: scaleX(0); transform: scaleX(0); -webkit-transition: all 0.3s ease-in-out 0s; transition: all 0.3s ease-in-out 0s; } h2 > a:hover:before { visibility: visible; -webkit-transform: scaleX(1); transform: scaleX(1); } h2 > a >span { position: relative; color: #000; text-decoration: none; } h2 > a >span:hover { color: #000; } h2 > a > span:before { content: ""; position: absolute; width: 100%; height: 2px; top: 40; left: 0; background-color: #000; visibility: hidden; -webkit-transform: scaleX(0); transform: scaleX(0); -webkit-transition: all 0.3s ease-in-out 0s; transition: all 0.3s ease-in-out 0s; } h2 > a > span:hover:before { visibility: visible; -webkit-transform: scaleX(1); transform: scaleX(1); } 
 <h2><a><span>Look at this large truncated text effect with css, it's magic! </span></a></h2> 

i tried with adding a span and setting the same but on top but i can't get rid on how moove this line, it keeps up due to display and positions so... i think this, as you thinked, can't work, sorry. 我尝试添加一个跨度并设置相同但在最上面,但是我无法摆脱这条线的移动方式,由于显示和位置的缘故,它保持不变,所以...我认为这就像您认为的那样是行不通的不好意思

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM