CSS “顶部”和“左侧”属性的 CSS3 过渡不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8109109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:09:11  来源:igfitidea点击:

CSS3 transition for "top" and "left" properties not working

csspositioncss-transitions

提问by user701510

I have a list with one item on the list transitioning to the northeast when I hover over it. Using margin-topand margin-leftproperty transitions worked but the item being hovered over kept pushing other elements so I added position:relativeand tried using topand lefttransition properties but it didn't seem to be working.

我有一个列表,当我将鼠标悬停在它上面时,列表中的一个项目会过渡到东北。使用margin-topmargin-left属性转换有效,但悬停在上面的项目不断推动其他元素,所以我添加position:relative并尝试使用topleft转换属性,但它似乎没有工作。

Here is the jsfiddle:

这是jsfiddle:

list hover

列表悬停

采纳答案by uadrive

Have you tried setting the parent of your list. I know sometimes relative has issue unless the underlying item is also relative or absolute. Just a thought.

您是否尝试过设置列表的父级。我知道有时相对会有问题,除非基础项目也是相对或绝对的。只是一个想法。

回答by nghiepit

Add left, top default link demo

添加左、上默认 链接演示

left: 0px

回答by COBOLdinosaur

Use position:absolute and it will take it out of the normal document flow. You could also give it z-index:5 to make sure it floats over other elements.

使用 position:absolute 会脱离正常的文档流。你也可以给它 z-index:5 以确保它浮动在其他元素上。