css - 也许只应用一次规则的子选择器?

标签 css

#mainContent .container{
    background-image:url("/images/index_33.jpg");
    background-repeat:no-repeat;
    padding-left:85px;
    margin-top:10px;
}

如何仅将这些规则应用于具有类容器的第一个 div?

最佳答案

要“将这些规则应用到带有类容器的第一个 div”,您需要更具体一些 div.container,然后使用 first-child 伪类。

#mainContent div.container:first-child {
    background-image:url("/images/index_33.jpg");
    background-repeat:no-repeat;
    padding-left:85px;
    margin-top:10px;
}

来自 w3scools.com :

The :first-child pseudo-class adds a style to an element that is the first child of another element.

关于css - 也许只应用一次规则的子选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4770441/

相关文章:

html - 我将如何使用 CSS 选择它?

php - 使用 CakePHP 跨 2 个 div 拆分表单

javascript - CSS 中的视差效果 - 尽管有 z 索引,但文本会溢出

html - 将侧边栏中的图像居中

html - 什么是 CSS 中的 flood-color 和 lighting-color 定义?

css - 如何在页面缩小时将 DIV 保持在同一位置

javascript - 如何在 JavaScript 中制作 if 条件的 css 高度

html - 如何正确重置网格模板列?

html - 有没有办法在 CSS 中使用 href ="tel"?

jquery - 如何让下拉导航子元素从顶部跟随父位置