我想在最近的li
中移動到新行並僅居中a
。我試過的每件事情都改變了以前的主播。我無法觸及標記,只有CSS。任何擅長CSS的人都知道如何只定位最後的a
?如何僅在特定HTML元素之後纔在CSS中居中?
的代碼是:
ol{
list-style:none;
font-family:sans-serif;
}
ol li{
padding:5px;
margin:1px;
background:#e6e6fa;
}
.classX{
text-align:center;
}
.classX a{
display: inline-block;
padding:.3em .5em;
margin:0 auto;
color:#000;
background:#fff;
border:1px solid #000;
}
time,
time + p{
display:inline-block;
font-size:.8em;
}
span + a{
display: inline-block;
padding:.3em .5em;
color:#000;
background:#fff;
border:1px solid #000;
}
<section>
<ol>
<li><!-- This link contain 'a' in first 'p' -->
<h3>Heading</h3>
<img src="http://placehold.it/350x150" />
<p>Primary description with
<a href="finally-styled.html">link</a>
inside</p>
</li>
<li class="classX"><!-- The most imptnt here is to center 'a' -->
<h3>Heading</h3>
<img src="http://placehold.it/350x150" />
<p>Some related content, is centered.</p>
<a href="one.html">One</a>
<a href="second.html">Two</a>
</li>
<li><!-- The most imptnt here is to center 'a' -->
<h3>Heading</h3>
<img src="http://placehold.it/350x150" />
<p>Primary description.</p>
<time>2038-01-19</time>
<p>Category</p>
<span><!-- Invisible element, yeah I know. But might help to target the 'a'. --></span>
<a href="this-1-should-be-centered.html">Link</a>
</li>
</ol>
</section>
能否請您分享您的代碼? –
你能告訴我們至少你的代碼,你到底做了什麼,以便我們能夠幫助你。 – vignesh
請提供您的HTML結構。如果'a'標籤後面的代碼不包含在另一個標籤中,那麼單獨使用CSS是不可能的。 – Shaggy