我有一个带有 position:relative
的 Div,其中包含“一个或多个”图像,带有 postion:absolute
以及一些顶部和左侧值。我需要使用 JS 或 JQuery 使用按钮一次在 Absolute
和 Auto/Relative
之间切换所有图像的位置属性。
有没有办法同时处理所有这些子图像?
最佳答案
尝试以下操作:
html
<div class="wrapper">
<img src="http://dummyimage.com/15x15/000/fff" class='absPosition'>
</div>
<input type="button" value="change position">
CSS
.wrapper {
height:300px;
position:relative;
}
.absPosition {
position:absolute;
bottom:0;
}
jQuery
$(":button").click(function() {
$("img").toggleClass("absPosition")
});
关于javascript - 使用 JS 或 JQuery 更改 DIV 中每个元素的 CSS 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7646364/