gpt4 book ai didi

javascript - 如果我的 h3 没有首先出现在页面上(PHP CSS 或 JS),则更改 CSS

转载 作者:行者123 更新时间:2023-11-28 09:08:51 25 4
gpt4 key购买 nike

我在为客户定制的 CMS 中工作,如果我的 h3 没有出现在它之前,我想对第一个 p 标签应用不同的 CSS。

解决方案似乎是这样的——“如果 h3 没有首先出现,则将 20px margin-top 添加到第一个 p 标签”之类的。我只是不确定如何用 php 或 js 编写它。

我的页面通常是这样的。

h1h2h3

但有时我的页面没有 h3,这会导致 p 离 h2 太近。

任何帮助都会很棒。

谢谢。

最佳答案

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>next demo</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<h1>Heading h1</h1>
<h2>Heading h2</h2>
<p>p tag will change if h3 is not found</p>

<p>Shouldn't affect this</p>


<script>
$( "h2" ).next( "p" ).css({"margin-top":"20px", "font-size":"25px" });
</script>

</body>
</html>

    <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>next demo</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<h1>Heading h1</h1>
<h2>Heading h2</h2>
<h3>Heading h3</h3>
<p>p tag will not change if h3 is found</p>

<p>Shouldn't affect this</p>


<script>
$( "h2" ).next( "p" ).css({"margin-top":"20px", "font-size":"25px" });
</script>

</body>

关于javascript - 如果我的 h3 没有首先出现在页面上(PHP CSS 或 JS),则更改 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26568883/

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