jquery - 在 jQuery 中存储和加载字段

标签 jquery css field

我需要存储每个 <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";
});

jsFiddle

关于jquery - 在 jQuery 中存储和加载字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23076949/

相关文章:

android - Android 版 Chrome 中奇怪的框阴影错误

jquery - 如何使用 jQuery 在多个 ID 上设置属性?

jquery - 如果屏幕低于 800 运行这个 CSS,否则运行这个 CSS

javascript - 自动添加新号码页

html - Burger-Button 的点击区域未固定到实际的 Buttonarea

mysql - MySQL 中的 Field() 配置单元中的任何函数?

c# - ThreadSafety 和静态字段 - 混淆?

python - Elasticsearch 未显示字段

jquery - 将 bootstrap col-md-3 div 设置为相同的高度

javascript - 如何在 Javascript 中用空格替换?