Javascript jQuery在.css()方面遇到了问题

Javascript jQuery在.css()方面遇到了问题,javascript,jquery,html,css,Javascript,Jquery,Html,Css,好的,这是我的代码: $(document).ready(function() { $('.topbuttons').mouseenter(function() { $(this).css("margin-bottom", "65px").height(60).width(110); }); $('.topbuttons').mouseleave(function() { $(this).height(50).width(100);

好的,这是我的代码:

$(document).ready(function() {
    $('.topbuttons').mouseenter(function() {
        $(this).css("margin-bottom", "65px").height(60).width(110);
    });
    $('.topbuttons').mouseleave(function() {
        $(this).height(50).width(100);
    });
});

如果我去掉.css(“margin bottom”,“65px”),一切都很好,当鼠标移到div(.topbuttons)上时,div会变大。但是,下面的div。topbuttons每次都被按下。topbuttons的高度增加。所以我想我可以将.topbuttons的底部边距降低10px,因为我们正在将.topbuttons的大小增加10px。然而,它似乎不起作用,我也不知道为什么。请帮助我,我会用纯CSS:

.topbuttons{
   /* OTHER STYLES HERE*/
   height: 60px;
   width: 110px;
   margin-bottom:65px;
   transition: all 0.4s; /* if you want to apply some animation :) */
}
.topbuttons:hover{
   height: 50px;
   width: 100px;
   margin-bottom:75px; /* increase margin bottom if you don't want
                          to make move the div below*/
}

使用.height和.width与.css是错误的 试试这个:

   $(this).css({'margin-bottom':'65px', width: '110px', height: '60px' });

若问题出在利润底部,那个么为什么你们不把这条线分开呢

$(document).ready(function() {
    $('.topbuttons').mouseenter(function() {
        $(this).css("margin-bottom", "65px");
        $(this).height(60).width(110);
    });
    $('.topbuttons').mouseleave(function() {
        $(this).height(50).width(100);
    });
});
或者删除jquery并使用css执行它

.topbuttons:hover{
    margin-bottom:65px;
    height:60px;
    width:100px;
}

我推荐了第二个选项…

我想出来了,我的代码最终是这样的,在css中: #顶部按钮显示分区:悬停{ 颜色:栗色; 背景色:#f05e35; 高度:60px; 宽度:110px; 利润率:50px 25px 65px 25px


#topbuttonsrow是我5岁时的一个小角色。topbuttons

如@Roko C.Bulijan所写,如果css可行,那么就使用css吧。;)到目前为止,有三个答案和大量的评论,但仍然没有JSFIDLE…。@Dean.DePue我发现测试和部署更好更快。不管怎样,都不需要小提琴(最好有小提琴)但最重要的是,至少要获得再现问题所需的代码。这没关系,但它并没有解决OP在按钮悬停时内容被按下的问题。不,他说,对于按下问题,他减少了底部边距。为此,他使用了底部边距。他试图增加高度10px,减少底部边距边距10px…真的吗?“如果我去掉.css(“边距底部”,“65px”),一切都很好,当鼠标移到上方时,div(.topbuttons)会变大。但是下面的div。topbuttons每次都被按下。topbuttons的高度会增加。”@JayBlanchard“如果我去掉.css(“边距底部”,“65px”)”@JayBlanchard他已经去掉了
页边距底部
,这就是这种行为的原因。同样,他只说“如果我去掉.css(“页边距底部”,“65px”)”。
height(xy)
.css({height:xy})的缩写
@Roko C.Buljan。我知道这是一个速记……但是,根据我的说法,如果我们使用的是.css,那么我们应该在.css中写宽度和高度,而不是分开。