css - 如何定位特定的 h1 header

标签 css

我有一个特定的 h1 标题,我想用 css 作为目标,但不确定如何。

HTML

</div>
</header><!-- #masthead -->
<div id="content" class="main-container">
<div class="header-callout"></div>
<section class="content-area  pt0 ">
<div id="main" class="container" role="main">
<div class="row">
<div id="primary" class="col-md-8 mb-xs-24 sidebar. 
right">
<article id="post-9949" class="post-9949 page type-page 
status-publish hentry"><header class="entry-header">
<h1 class="entry-title">Showcase of the Month</h1>   
</header><!-- .entry-header -->

查看here

基本上我想把它居中。但是 margin: auto 从来没有用过。

最佳答案

您可以使用:

.entry-title {
    /* Your CSS */
} 

h1.entry-title {
    /* Your CSS */
} 

如果这不起作用,是否有其他 CSS 规则可能适用于此(例如单独的 h1 标记样式?)您可以像这样使其更具体:

header > h1.entry-title {
    /* Your CSS */
} 

这里,> 表示 h1 标签,它们是 header 标签的直接子标签并具有类 entry-title。


如果您只想定位这个特定的 h1 标签,请为其指定一个 ID:

<h1 class="entry-title" id="my-title">Text</h1>

可以使用 # 定位 ID:

#my-title {
    /* Your CSS */
} 

h1#my-title {
    /* Your CSS */
} 

您甚至可以确保只选择那些具有特定类别和特定 ID 的对象:

h1#my-title.entry-title {
    /* Your CSS */
} 

关于css - 如何定位特定的 h1 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57642077/

相关文章:

javascript - "store"折叠菜单的实际状态

asp.net - 如何删除 ASP.NET 中导航菜单的高亮边框?

css - 空白 : nowrap doesn't work in element UL

javascript - 如何将 html5 视频拉伸(stretch)到宽度 :600 and height 200?

html - Semantic-UI - 如何设置百分比大小

javascript - Bootstrap 4 导航栏事件类不工作

html - 如何在表格单元格中对链接进行自动换行,以免打断表格的流程?

html - 防止父 div 溢出时子 div 被剪裁 :auto (because of its dynamic content)

CSS 位置元素

css - 如何配置 nib 使用的供应商前缀?