html - 在 <hX> 中定位 <small>

标签 html css css-selectors

我有一种有趣的元素需要在 CSS 中定位:它是 <small><h[1-6]> 里面在 <div> 中上课 alert-messageblock-message .

基本上是这样的:

<div class="alert-message block-message">
    <h3>
        Hello World
        <small>And Hello Universe, too!</small>
    </h3>
</div>

我试过:

div.alert-message.block-message h1,h2,h3,h4,h5,h6 small

div.alert-message.block-message h1 small, h2 small, h3 small, h4 small, h5 small, h6 small

但显然两者都不起作用。我只需要更改这些特定的字体颜色 <small> block 。我上述“查找”元素的方法有什么问题?

最佳答案

要专门针对这些,您的选择器必须是这样的:

div.alert-message.block-message h1 small,
div.alert-message.block-message h2 small,
div.alert-message.block-message h3 small,
div.alert-message.block-message h4 small,
div.alert-message.block-message h5 small,
div.alert-message.block-message h6 small {

}

我一直希望 h1-h6 有一个通用选择器,但不幸的是我们需要单独定位它们。

What's wrong with my approaches above in "finding" the elements?

记住逗号 , 分隔选择器,所以:

div.alert-message.block-message h1,h2,h3,h4,h5,h6 small {}

等同于:

div.alert-message.block-message h1 {/* styles */}
h2 {/* styles */}
h3 {/* styles */}
h4 {/* styles */}
h5 {/* styles */}
h6 small {/* styles */}

I wonder if there's a LESS shortcut?

据我所知,标题没有快捷方式,但看起来您可以像这样使用嵌套选择器:

div.alert-message.block-message {
    h1, h2, h3, h4, h5, h6 {
        small {/* your CSS */}
    }
}

关于html - 在 <hX> 中定位 <small>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7950533/

相关文章:

php - 如何在 Wordpress 上获取菜单数据

css - Bootstrap 3 - 列的划分

css - :nth-child within Bootstrap rows

javascript - 我想让我的按钮在点击时转到我的页面顶部

javascript - 如何将自动生成的 HTML 导出为 PDF

IE6 中的 ASP.net Web 应用程序设计器在 IE8 中存在兼容性问题

php - 我做错了什么 "scrolling text bar"

html - 我怎样才能得到一个相对的 div 来扩展以适应它的绝对内容?

css - 为了清晰起见,有没有一种方法可以对 CSS 选择器进行分组?

css - 如何更改 sass/compass 编译时的选择器布局?