调整浏览器大小时,jQuery按钮元素会移动

调整浏览器大小时,jQuery按钮元素会移动,jquery,html,css,Jquery,Html,Css,我有一个div元素,它附加了一些jQuery来给它一个反弹效果。元素的位置绝对与其父元素相对。调整浏览器大小时,子元素将移动,并且在重新调整浏览器大小时不会保持在中心位置,直到停止重新调整浏览器大小 请给我一些建议,如何阻止这种情况的发生 HTML 请看我的代码笔,看看它的行动 您需要应用边距:0自动;到包含div而不是到buttonbounce。这就解决了问题 .test {position:relative; margin:0 auto; width: 45px;

我有一个div元素,它附加了一些jQuery来给它一个反弹效果。元素的位置绝对与其父元素相对。调整浏览器大小时,子元素将移动,并且在重新调整浏览器大小时不会保持在中心位置,直到停止重新调整浏览器大小

请给我一些建议,如何阻止这种情况的发生

HTML

请看我的代码笔,看看它的行动


您需要应用边距:0自动;到包含div而不是到buttonbounce。这就解决了问题

.test {position:relative;
      margin:0 auto;
      width: 45px;
      height: 45px;}

#buttonbounce {
    width: 45px;
    height: 45px;
    position: relative
    top:30px;    
    background-image: url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    }

您需要应用边距:0自动;到包含div而不是到buttonbounce。这就解决了问题

.test {position:relative;
      margin:0 auto;
      width: 45px;
      height: 45px;}

#buttonbounce {
    width: 45px;
    height: 45px;
    position: relative
    top:30px;    
    background-image: url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    }
请试试这个:

.test {position:relative;
      margin:0 auto;
      width: 45px;
      height: 45px;}

#buttonbounce {
    width: 45px;
    height: 45px;
    position: relative
    top:30px;    
    background-image: url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    } url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    }

请试试这个:

.test {position:relative;
      margin:0 auto;
      width: 45px;
      height: 45px;}

#buttonbounce {
    width: 45px;
    height: 45px;
    position: relative
    top:30px;    
    background-image: url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    } url(http://cdn.flaticon.com/png/256/26037.png);
    background-size: 45px;
    cursor: pointer;
    }

它保持中心位置,你只需等待一点点提示:有
jqueryui.min.js
而没有
jqueryui.min.js
它保持中心位置,你只需等待一点点提示:有
jqueryui.min.js
而没有
jqueryui.min.js