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

发布于 2024-12-15 11:30:24 字数 306 浏览 4 评论 0原文

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

这是 jsfiddle:

列表悬停

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

Here is the jsfiddle:

list hover

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏见 2024-12-22 11:30:24

添加左侧、顶部默认值
链接演示

left: 0px

Add left, top default
link demo

left: 0px
笨死的猪 2024-12-22 11:30:24

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

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.

别闹i 2024-12-22 11:30:24

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

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.

岁月无声 2024-12-22 11:30:24
.transition{
    transition: all .4s;
    -moz-transition: all .4s;
    -webkit-transition:all .4s;
    -o-transition: all .4s;
    
    margin-top:20px;
    border:1px solid gray;   
    width:80px;
    padding:10px;
    margin-left:50px;
    position:relative; 
    cursor:pointer;
}

.hover_top{ 
    top:0;
}
.hover_top:hover{
    top:-10px;
}

.hover_left{    
    left:0;
}
.hover_left:hover{
    left:-10px;
}

.hover_right{   
    right:0;
}
.hover_right:hover{
    right:-10px;
}
 

 <div class="hover_top transition"> Hover Top </div>
 <div class="hover_left transition"> Hover Left </div>
 <div class="hover_right transition"> Hover Right </div>

 

.transition{
    transition: all .4s;
    -moz-transition: all .4s;
    -webkit-transition:all .4s;
    -o-transition: all .4s;
    
    margin-top:20px;
    border:1px solid gray;   
    width:80px;
    padding:10px;
    margin-left:50px;
    position:relative; 
    cursor:pointer;
}

.hover_top{ 
    top:0;
}
.hover_top:hover{
    top:-10px;
}

.hover_left{    
    left:0;
}
.hover_left:hover{
    left:-10px;
}

.hover_right{   
    right:0;
}
.hover_right:hover{
    right:-10px;
}
 

 <div class="hover_top transition"> Hover Top </div>
 <div class="hover_left transition"> Hover Left </div>
 <div class="hover_right transition"> Hover Right </div>

 

时光倒影 2024-12-22 11:30:24

您必须定义要应用过渡效果的属性。例如:

.box { position: relative; transition: all 0.4s ease;}
.box:hover { top: -1rem;}

那是行不通的。因此,您必须默认定义 top: 0,然后在悬停时定义 top -1rem。这样

.box { position: relative; transition: all 0.4s ease; top:0}
.box:hover {top: -1rem}

就可以了。

You have to define the property where you want to apply the transition effect. For example:

.box { position: relative; transition: all 0.4s ease;}
.box:hover { top: -1rem;}

that will not work. So you have to define top: 0 by default then top -1rem on hover. like

.box { position: relative; transition: all 0.4s ease; top:0}
.box:hover {top: -1rem}

that will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文