我希望最终得到的结果是:
Hello there!
<image>
This is an image
Hi!
如何使用Markdown实现图像和文本This is an image
在页面上居中显示?
编辑:注意,我想要水平居中图像和文字。
我发现我只需要在想要水平对齐的地方使用HTML。
因此,我的代码看起来像这样:
Hello there!
<center><img src="" ...></center>
<center>This is an image</center>
Hi!
<center>
元素已被废弃。只需使用CSS将其或其包装器设置为具有固定宽度和margin:0 auto;
的块级元素即可。 - BalusC<center>
。 - Med我认为我有一个简单的解决方案,只要你能定义CSS,它就能运行。它也不需要任何扩展或HTML!首先你的Markdown图像代码:
![my image](/img/myImage.jpg#center)
请注意新增的url哈希值#center。
现在在CSS中添加以下规则:
img[src*='#center'] {
display: block;
margin: auto;
}
你应该能够像定义类名一样使用网址哈希。
要看到这个效果,请查看我的JSFiddle,在文本区中使用SnarkDown解析MarkDown - https://jsfiddle.net/tremor/6s30e8vr/
Hello there!
{:.center}
![cardinal](/img/2012/cardinal.jpg)
This is an image
Hi!
.center {
text-align: center;
}
-> This is centered Text <-
->![alt text](/link/to/img)<-
你需要一个定义了高度的块级容器,行高与图像垂直居中:middle;样式属性值相同;这样应该就可以正常工作了。
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语法吗? - Chetan我很惊讶没有人提到这种方法:
Hello there!
<p align="center">
<img src="">
This is an image
</p>
Hi!
{: 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!