css - 选择 css 中的第一个 dl 元素

标签 css css-selectors

我有这个 html:

<div id="gallery-1" class="gallery galleryid-39 gallery-columns-3 gallery-size-thumbnail gallery1">

<script type="text/javascript"></script>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<br style="clear: both"></br>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<br style="clear: both"></br>

</div>

和这个 CSS:

.gallery dl:first-child {
display: none;
}

不知道是什么原因,没用

最佳答案

dl:first-child<dl> 不匹配元素,因为它不是其父元素的第一个子元素。 (实际上 .gallery 的第一个子元素是 <script> 元素)

为了定位第一个<dl>元素,你可以使用 :first-of-type 伪类代替:

.gallery > dl:first-of-type {
    display: none;
}

关于css - 选择 css 中的第一个 dl 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25888797/

相关文章:

css - 仅对颜色使用背景重复的缺点?

css - Chrome 模拟器和 iphone 5 显示错误的媒体查询样式,但正在调整窗口大小

html - 在所有页面上显示边栏上的编辑

html - 可滚动的 div 移动 IE10 和 -ms-viewport

html - 如何在HTML页面中添加灰色垂直线

css - 元素父元素的第一个兄弟是否有 CSS 选择器?

基于通配符的属性名称的 CSS 选择器

python - 如何通过 Selenium 和 Python 点击​​某个元素

css - 如何在不重复完整路径的情况下选择多个 sibblings CSS 类?

CSS 简单图片库问题