1
我有一个包含16幅图像的网页。每个图像占用容器宽度的49.7%。所以基本上我有2列和8行。我写了一些jQuery代码,将您点击的图像展开为99.5%的宽度,以占用2列。如何将以前的图像放在展开图像下方
这很好,但是当我点击第二列上的图像时,它被放置在第一列图像的下方。我不希望发生这种情况,我希望图像位于第一列图像的顶部。希望这是有道理的。我将在下面提供我的代码。
$(document).ready(function() {
$('img').on('click', function() {
$(this).toggleClass('imgwidth');
});
});
img {
width: 49.7%;
display: inline;
vertical-align: top;
margin-top: 3px;
top: 100px;
}
.imgwidth {
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<main>
<div>
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
<img src="http://placehold.it/8x1" />
</div>
</main>
是的,我尝试了类似于你的建议,但我不能完美。感谢您的输入,即使您的代码也存在缺陷。我想我会继续尝试,除非有人通过一个更简单的方式来完成。 – temowemo