gpt4 book ai didi

jQuery 根据内容的高度放置按钮

转载 作者:太空宇宙 更新时间:2023-11-03 18:54:50 25 4
gpt4 key购买 nike

我有工作演示在这个link .标记是这样的,但它仅适用于第一行。在演示链接中,我给出了所有代码

<div id="content">
<ul class="products">
<li class="product pro first">
<a href="#">
<span class="onsale">Sale!</span>
<img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://web-vassets.ea.com/Assets/Resources/Image/FeaturedGame/battlefield-bad-company-2-thumb.png?cb=1340391602">
<h3>Lorem Ipsum is simply dummy </h3>
<span class="price"><span class="strike-through"><span class="striked-text"><span class="amount">$&nbsp;67.00</span></span></span> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
</a>
<a class="add_to_cart_button button product_type_simple" data-product_id="185" rel="nofollow" href="#">Add to cart</a>
</li>

<li class="product pro">
<a href="#">
<span class="onsale">Sale!</span>
<img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://web-vassets.ea.com/Assets/Resources/Image/FeaturedGame/battlefield-bad-company-2-thumb.png?cb=1340391602">
<h3>Battle Field</h3>
<span class="price"><span class="strike-through"><span class="striked-text"><span class="amount">$&nbsp;67.00</span></span></span> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
</a>
<a class="add_to_cart_button button product_type_simple" data-product_id="185" rel="nofollow" href="#">Add to cart</a>
</li>

<li class="product pro last">
<a href="#">
<span class="onsale">Sale!</span>
<img width="100" height="140" title="battlefield" alt="battlefield" class="attachment-shop_catalog wp-post-image" src="http://web-vassets.ea.com/Assets/Resources/Image/FeaturedGame/battlefield-bad-company-2-thumb.png?cb=1340391602">
<h3>Battle Field</h3>
<span class="price"><span class="strike-through"><span class="striked-text"><span class="amount">$&nbsp;67.00</span></span></span> <ins><span class="amount">$&nbsp;23.00</span></ins></span>
</a>
<a class="add_to_cart_button button product_type_simple" data-product_id="185" rel="nofollow" href="#">Add to cart</a>
</li>
</div>

在这里您可以看到一行有 3 列,另一行有 3 列。现在每个内容部分在页面底部都有一个添加到购物车按钮。现在我想让所有的按钮都放在我的内容的底部,它不会介意文本的长度。为此,我只是在这里使用了一些 jQuery 的东西。现在在该演示中,您可以看到它正在获取一个元素的最大高度并根据它设置 css。但我想在每一行中保留它。您可以看到第一行内容较少,第二行内容较多。所以在第二行中,可以将按钮放在底部,并且它会占用该行的最大高度。但是首先应该有类似的东西。在那里它应该检查最大高度内容并且应该根据那个放置按钮。那么有人可以告诉我如何为每一行做到这一点吗?很抱歉告诉您我无法更改我的标记。它将保持不变

最佳答案

在 jQuery 中只使用这个

(function($) {
function normalizeHeight(items) {
var maxHeight = 0, itemHeight;

items.each(function() {
itemHeight = $(this).height();
if (itemHeight > maxHeight) {
maxHeight = itemHeight;
}
}).height(maxHeight + 'px');
}

$(document).load(function(){
var itemsPerRow = 3,
items = $('ul.products li'),
rows = items.length / itemsPerRow,
r, min, max;

if (rows < 1) rows = 1;

for(r = 0; r < rows; r++) {
min = itemsPerRow * r,
max = min + itemsPerRow;
normalizeHeight(items.slice(min, max));
}
});
});</script>

这将使所有的 li 高度相等,它会检查该行中最高的 li 并使另一个 i 在那个 roe 中达到那个高度。希望它对您有用。

关于jQuery 根据内容的高度放置按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13776614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com