Select first occurring element after another element(在另一个元素之后选择第一个出现的元素)
问题描述
我在一个页面上有以下 HTML 代码:
<h4>一些文字</h4><p>还有一些文字!</p>在我的 .css 中,我有以下选择器来设置 h4 元素的样式.上面的 HTML 代码只是整个代码的一小部分;有几个 div 更多地包裹在属于 shadowbox 的周围:
#sb-wrapper #sb-wrapper-inner #sb-body #myDiv h4{颜色:#614E43;边距顶部:5px;左边距:6px;}所以,我的 h4 元素具有正确的样式,但我还想在我的 HTML 中设置 p 标记的样式.
这可以通过 CSS 选择器实现吗?如果是,我该怎么做?
#many .more.selectors h4 + p { ... }这称为相邻兄弟选择器.p>
I've got the following HTML code on a page:
<h4>Some text</h4>
<p>
Some more text!
</p>
In my .css I've got the following selector to style the h4 element. The HTML code above is just a small part of the entire code; there are several divs more wrapped around belonging to a shadowbox:
#sb-wrapper #sb-wrapper-inner #sb-body #myDiv h4
{
color : #614E43;
margin-top : 5px;
margin-left : 6px;
}
So, I have the correct style for my h4 element, but I also want to style the p tag in my HTML.
Is this possible with CSS-selectors? And if yes, how can I do this?
#many .more.selectors h4 + p { ... }
This is called the adjacent sibling selector.
这篇关于在另一个元素之后选择第一个出现的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在另一个元素之后选择第一个出现的元素
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
