【发布时间】:2011-04-24 04:25:47
【问题描述】:
我想结束:
Hello there!
<image>
This is an image
Hi!
图片和文字This is an image在页面的中心位置。如何使用 Markdown 完成此任务?
编辑:请注意,我希望将页面上的图像和文本水平居中。
【问题讨论】:
我想结束:
Hello there!
<image>
This is an image
Hi!
图片和文字This is an image在页面的中心位置。如何使用 Markdown 完成此任务?
编辑:请注意,我希望将页面上的图像和文本水平居中。
【问题讨论】:
我想我只需要在我想要水平对齐任何东西的地方使用 HTML。
所以我的代码看起来像这样:
Hello there!
<center><img src="" ...></center>
<center>This is an image</center>
Hi!
【讨论】:
<center> 元素自 1998 年起在 HTML4 中被弃用。只需使用 CSS 使其或其包装器成为具有固定宽度和 margin: 0 auto; 的块元素即可。
<center>。
如果您可以定义 CSS,我想我有一个简单的解决方案。它也不需要任何扩展或 HTML!首先是您的降价图像代码:

注意添加的 url 哈希 #center。
现在在 CSS 中添加这条规则:
img[src*='#center'] {
display: block;
margin: auto;
}
您应该能够使用这样的 url 哈希,几乎就像定义类名一样。
要查看实际情况,请查看我的 JSFiddle,使用 SnarkDown 解析文本区域中的 MarkDown - https://jsfiddle.net/tremor/6s30e8vr/
【讨论】:
如果你使用kramdown,你可以这样做
Hello there!
{:.center}

This is an image
Hi!
.center {
text-align: center;
}
【讨论】:
在Mou(也许还有 Jekyll)中,这很简单。
-> This is centered Text <-
因此,考虑到这一点,您可以将其应用于 img 语法。
-><-
此语法不适用于仅实现 Daring Fireball 中记录的内容的 Markdown 实现。
【讨论】:
您需要一个具有定义高度的块容器,行高和图像的值相同,垂直对齐:中间; 它应该可以工作。
Hello there !
<div id="container">
<img />
This is an image
</div>
Hi !
#container {
height:100px;
line-height:100px;
}
#container img {
vertical-align:middle;
max-height:100%;
}
【讨论】:
div中使用Markdown语法吗?
我很惊讶没有人这样提到:
Hello there!
<p align="center">
<img src="">
This is an image
</p>
Hi!
【讨论】:
使用 kramdown(由 githubpages 使用)
{: style="text-align:center"}
That is, while there is value in the items on
the right, we value the items on the left more.
或者使用@(Steven Penny) 的回复
{:.mycenter}
That is, while there is value in the items on
the right, we value the items on the left more.
<style>
.mycenter {
text-align:center;
}
</style>
【讨论】:
这是一个简单的解决方案,不使用任何已弃用的标签或属性:
Hello there!
<img style="display: block; margin: auto;"
src="https://stackoverflow.design/assets/img/logos/so/logo-print.svg">
<p style="text-align: center;">
This is an image
</p>
Hi!
【讨论】: