2014-06-12 81 views
2

好,所以,我的继承人代码:jQuery的麻烦的.css()

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

如果我拿出的.css( “下边距”, “65px”)一切完美,股利( .topbuttons)变得更大时,它的阴影。但是,每次按下.top按钮时都会下压div.topbuttons高度会增加。所以我想我可以将.topbuttons的底部边距降低10px,因为我们正在增加.topbuttons的大小10px。但它似乎没有工作,我不知道为什么。请帮助

+2

小提琴请??? –

+0

作为@Roko C. Bulijan写道,如果可能与CSS然后只使用CSS。 ;) –

+0

到目前为止的三个答案和很多意见,仍然没有jsfiddle ... –

回答

7

我会做它在纯CSS:jsBin demo

.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*/ 
} 
1

使用.height和.WIDTH的是用的CSS 错误的方法试试这个:

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

'height(xy)'是'.css({height:xy})的缩写' –

+0

@Roko C.Buljan。我知道这是一个简写......但是,如果我们使用.css ,那么我们应该在.css中写入宽度和高度而不是单独。 –

0

如果问题与边缘底部,那么为什么你不分开这条线。

$(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; 
} 

我推荐的第二个选项...

+0

这是好的,但它没有解决OP在按钮悬停时按下内容的问题。 –

+0

不,他说下降问题会降低底部利润。为此,他使用底部边距。他试图增加高度10px并减少底部边距10px .... – Shail

+0

真的吗? *“如果我取出.css(”margin-bottom“,”65px“),一切都可以正常工作,div(.topbuttons)在被遮盖时会变大。**但是,每次按下.topbutton时, “* –

0

我想通了,我的代码最终看上去像这样,在CSS: #topbuttonsrow a div:hover { color:maroon; background-color:#f05e35; height:60px; width:110px; margin:50px 25px 65px 25px;

#topbuttonsrow是我的5个div的顶部。顶部