假设您有一个使用Jekyll建立的博客站点,博客文章位于页面中心。我想要将内容(即段落、单词、代码等)左对齐,但是图片要居中。
我将文字等左对齐,但现在我正在努力让具有CSS样式max-height:80%
的图像也居中显示。
看起来Jekyll的博客生成器(从Markdown)将图像包装在<p></p>
标签中,因此margin:0 auto
无法将图像居中。 我在下面附上了代码片段:
<li>
<h2 class="post-title">Hello World</h2>
<div class="post-date"><span>May 21, 2014</span></div>
<div class="post-content">
<p><img src="/images/photos/blog/hello-world.jpg" alt="blog-image"></p>
</div>
</li>
ul#posts {
list-style-type: none;
margin: 0 auto;
width: 60%;
}
ul#posts > li {
margin-bottom: 35px;
text-align: center;
}
ul#posts > li div.post-content {
text-align: left;
}
ul#posts > li > div.post-date {
color: #A0A0A0;
font-style: italic;
margin-bottom: 15px;
}
ul#posts > li > div.post-content > p > img {
margin: 0 auto;
max-height: 80%;
max-width: 100%;
}
我该如何在博客文章中居中图片?
<p>
标签中的文本,我不希望那些文本居中显示。 - Andrew Tat