如何定位特定的H1标头

时间:2019-08-24 23:00:26

标签: 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永远行不通。

1 个答案:

答案 0 :(得分:1)

您可以使用:

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

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

如果这不起作用,是否还有其他CSS规则可以在这里应用(例如单独的h1标签样式?)您可以像这样使它更具体:

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

在这里,>表示h1标签,它们是标头标签的直接子元素,并具有类入口标题。


如果您只想定位此特定的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 */
}