我正在做一个网站,每月发表文章的问题。这很简单,我认为使用Markdown编辑器(如Stack Overflow中的WMD)将是完美的。

然而,他们确实需要在给定的段落中使图像右对齐的能力。

我看不出在目前的体制下有什么办法能做到这一点——有可能吗?


当前回答

嵌入CSS是不好的:

![Flowers](/flowers.jpeg)

CSS在另一个文件:

img[alt=Flowers] { float: right; }

其他回答

更简洁的方法是将p#给定的img {float: right}放在样式表中,或者放在<head>中并包装在样式标签中。然后,只需使用markdown ![Alt text](/path/to/img.jpg)。

最简单的方法是用一个中心标签来包装图像,就像这样…

<center>![Alt test](http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png)</center>

任何与Markdown有关的东西都可以在这里测试- http://daringfireball.net/projects/markdown/dingus

当然,<center>可能已弃用,但它很简单,而且可以工作!

在警告框内,将图像和文本作为单个块中的段落的一部分并排对齐。

<div class="warning" style='background-color:#EDF2F7; color:#1A2067; border-left: solid #718096 4px; border-radius: 4px;'>
<p style='padding:0.7em; margin-left:0.7em; display: inline-block;'>
<img src="typora_images/image-20211028083121348.png" style="zoom:70%;  float:right; padding:0.7em"/>
<b>isomorphism</b>  &rarr;  In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping.<br>
</p>
</div>

输出:

我喜欢超级懒地用垂直管道(|)语法使用表格来对齐图像。这是支持一些Markdown口味(也支持纺织,如果这浮动你的船):

| I am text to the left  | ![Flowers](/flowers.jpeg) |

or

| ![Flowers](/flowers.jpeg) | I am text to the right |

这不是最灵活的解决方案,但它适合我的大多数简单需求,易于阅读的markdown格式,你不需要记住任何CSS或原始HTML。

我有同样的任务,我把我的图像向右对齐,添加了这个:

<div style="text-align: right"><img src="/default/image/sms.png" width="100" /></div>

要将图像对齐到左侧或中心,请替换

<div style="text-align: right">

with

<div style="text-align: center">
<div style="text-align: left">