悬停期间 html 对齐不正确
我的网页上有一个菜单,我想在鼠标悬停的元素上添加一些强调。 在我将鼠标悬停之前,菜单看起来不错并且对齐方式看起来不错。为了添加强调,我添加了一个小箭头(或“>”符号)。问题是现在文本向右跳了 2 个字符。
我想添加“>”没有我的菜单文本向右跳转的字符。正确的行为是文本保留在 p 中 花边和箭头出现在悬停菜单项左侧 2 个空格处。
请注意,我试图改变我的对齐方式,但整个事情看起来很糟糕。只有 text-align: left
才能提供正确的对齐方式。
#leftMenu {
position: absolute;
top:28%;
left:24%;
height: 20%;
width: 20%;
font-weight:400
font-size:0.5em;
}
#leftMenu a:hover:before {
content: "> ";
}
如何添加箭头而不使文本跳到右侧?
I have a menu on a web page and I want to add some emphais onto the element that my mouse is hovering over.
Before I hover my mouse the menu looks good and the alignment looks good. To add emphsis, I added a small arrow (or '>' sign). The problem is that now the text jumps to the right by 2 characters.
I want to add the '>' character without my menu text jumping the right. The correct behavior is that the text remains in p
lace and the arrow appears 2 spaces to the left of the hovered menu item.
Note I tried to change my alignment and the whole thing looks like crap. Only text-align: left
gives it the correct alignment.
#leftMenu {
position: absolute;
top:28%;
left:24%;
height: 20%;
width: 20%;
font-weight:400
font-size:0.5em;
}
#leftMenu a:hover:before {
content: "> ";
}
How can I add the arrow without the text jumping to the right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要有“>”已经存在,只是不可见。这样,它将占据菜单上的空间,因此当它出现时,任何内容都不会移动。这是一个小例子:
CSS:
HTML:
我不太确定菜单的确切布局,但我认为上面的内容涵盖了总体思路。
Just have the ">" already exist, just not visible. This way it will take up the real estate on the menu, so nothing will move when it appears. Here is a small example:
CSS:
HTML:
I'm not really sure of the exact layout of your menu, but I think the above gets across the general idea.
您可以为正常条目添加一个左填充,其宽度与箭头稍后的宽度完全相同,并在将鼠标悬停在箭头上时将其删除。
然而,这可能会很混乱,因为箭头在每个浏览器中可能不具有相同的宽度(即使使用相同的字体和字体大小)。
另一种可能性是使用定位属性将箭头移动到正确的位置。例如,如果您在其上使用
position:absolute;
,它将不再移动其他东西。请注意,它将绝对定位在没有标准位置(静态)的下一个父级内部。You could add a padding-left for normal entries that takes exactly the width the arrow would have later and remove it when hovered in favor of the arrow.
However this could be quite a mess since the arrow may not have the same width in every browser (even with same font and font-size).
An other possibility is to use positioning properties to move the arrow to the right location. If you for example use
position: absolute;
on it, it will no longer move other things around. Be aware that it then will be positioned absolutely inside the next parent that does not have standard position (static).