jQuery 等高
我正在尝试根据 h3 的兄弟姐妹的最高版本来设置 h3 的高度。这一点并不太棘手。但我需要做的是仅由某些兄弟姐妹创建它。
我有一个 CSS 放入 3 行的列表。每行的最后一个 li 具有“endRow”类。我认为我需要做的是找到“endRow”,然后使用each()并返回两个元素并检查h3高度。有人知道一种简单的方法吗?
Ta
更新 这是标记的示例。不是每个 h3 的高度相等,而是每行的高度相等
<ul>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 2</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li class="endrow">
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 3</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li class="endrow">
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
I'm trying to set a height on an h3 based on the tallest version of it's siblings. That bit's not too tricky. But what I need to do is to create it by only certain siblings.
I have a list that CSS puts into row's of 3. The last li on each row has the class of 'endRow'. What I need to do, i think, is to find the 'endRow', then use each() and go back two elements and check the h3 heights. Anyone know of a simple(ish) way of doing it?
Ta
Update
here's a sample of the markup. It's not an equal height for every h3, just in each row
<ul>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 2</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li class="endrow">
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 3</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li>
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
<li class="endrow">
<a href="#"><img src="images/x.jpg" alt=""></a>
<h3><a href="#">Item 1</a></h3>
<div class="productOptions">
<p>Info</p>
<p>More info</p>
<p>Even more info</p>
</div>
</li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
.map()
的 jQuery 文档有一个演示(最后一个)这个函数运行良好:The jQuery documentation for
.map()
has a demo (last one) with this function that works nicely:您可以按如下方式获取元素的高度:
You can get the height of an element as follows:
这是jquery插件
http://www.filamentgroup.com/lab/ setting_equal_heights_with_jquery/
这对于复杂到简单的问题很有用。
here is jquery plugin
http://www.filamentgroup.com/lab/setting_equal_heights_with_jquery/
This would be good for complex to simple problem.
如果没有一些示例标记,就很难准确地遵循您想要的内容。
起初我以为你有类似的东西:
你需要查看每个
的高度并将前面的
设置为最高。
为此,我将使用 prevUntil ,例如:
请注意,这只是伪,它完全取决于你的标记。
然后我想也许你的意思是你有多个列,看起来像:
如果是这样的话,那么我会使用 nth 子选择器 和一些如下所示的代码:
Without some example markup it is a little hard to follow what you want exactly.
At first I thought you had something like:
and you needed to look at the height of each
<li>
and set the preceding<h3>
to the tallest.For that I would be using prevUntil with something like:
Note that is just pseudo and it entirely depends on your markup.
Then I thought maybe you meant you had multiple columns, that looked like:
If that is the case, then I would use the the nth child selector and some code that looks like:
您可以尝试我前段时间编写的以下功能,应该可以正常工作。
传递容器元素,它会查找您指定的item元素并获取最大高度值,设置容器元素高度。和/或者您也可以设置内部元素。
用法:
功能:
You can try the following function I wrote some time ago, should work fine.
Pass the container element, it looks for the item element you specify and gets the biggest height value, sets the container element height. And/Or you can set the Inner Elements also.
Usage:
Function:
尝试使用此脚本,如果您想要相等的高度,请使用“AjaxHeight”类或将 AjaxHeight 更改为您的类
Try using This script, if you want equal height use "AjaxHeight" class or change AjaxHeight to your class
更新:您可以创建一个函数,使任何元素与任何匹配的选择器高度相等:
用法:
equalHeights('ul li h3');
Update: You could create a function to make any element equal height with any matched selector:
Usage:
equalHeights('ul li h3');