【发布时间】:2014-05-23 00:25:38
【问题描述】:
假设您有一个使用 Jekyll 的博客站点,并且博客文章以页面为中心。我希望内容(即段落、单词、代码等)左对齐,但图像居中。
我有文本等左对齐,但现在我正在努力让图像(具有max-height: 80% 的 CSS 样式)也居中。
Jekyll 的博客生成器(来自 Markdown)似乎将图像包装在 <p></p> 标签中,因此 margin: 0 auto 不会使图像居中。我在下面附上了代码sn-ps:
<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>标签中也会有文字,我不希望该文字居中。