我需要存储每个 <p>
的外部高度里面的元素<div>
在我的页面中使用某个类,然后在每个包装上使用它 <div>
作为负边距。
但是每个<p>
由于文本不同,高度不同。
<div margin="negative outerHeight of <p>">
<p>I need this outer height</p>
</div>
<div margin="negative outerHeight of <p>">
<p>I need this outer height so much</p>
</div>
<div margin="negative outerHeight of <p>">
<p>I need this outer height to destroy the world</p>
</div>
我正在考虑检查每个 <p>
并将其存储在字段中。然后从字段中加载高度。问题是我不知道如何用 jQuery 编写它。
最佳答案
使用.css()的函数重载.这假设只有一个 <p>
子元素:
$("div").css("margin", function() {
return "-" + $(this).find("p:first-child").outerHeight() + "px";
});
关于jquery - 在 jQuery 中存储和加载字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23076949/