作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在为客户定制的 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/
我是一名优秀的程序员,十分优秀!