简体   繁体   English

如何在 GitHub README.md 中使用边距/填充?

[英]How to use margin/padding in GitHub README.md?

Issue问题

I'm trying to display several images in GitHub's README.md with a margin of x px between them.我试图在 GitHub 的 README.md 中显示几个图像,它们之间的边距为x px。 But for some reason GitHub seems to strip away the margin-right: 30px style.但由于某种原因 GitHub 似乎剥离了margin-right: 30px样式。

Markdown Markdown

[<img style="margin-right: 30px" src=foo.svg height=30>](https://www.example.com/)
[<img style="margin-right: 30px" src=bar.svg height=30>](https://www.example.com/)
<!-- ...and so on -->

Note: I tried align="left" here which works fine but breaks on lg sm xs devices.注意:在这里尝试align="left" ,它工作正常,但在lg sm xs设备上中断。

It is not possible to use different types of styles in GitHub markdown. GitHub markdown中不能使用不同类型的styles

Github only allows to use of some attributes inside the HTML tag and also removes some attributes from the tag if the user puts them inside the HTML tag. Github 只允许使用 HTML 标签内的一些属性,如果用户将它们放在 HTML 标签内,也会从标签中删除一些属性。

Also, we cannot use CSS in GitHub markdown because it is part of the sanitization process.此外,我们不能在 GitHub markdown 中使用 CSS,因为它是清理过程的一部分。

The HTML is sanitized, aggressively removing things that could harm you and your kin—such as <script> tags, inline styles, and class or id attributes. HTML 经过消毒,积极删除可能伤害您和您的家人的东西,例如<script>标签、内联 styles 和classid属性。

source: https://github.com/github/markup#github-markup来源: https://github.com/github/markup#github-markup

If we use an HTML block in the markdown file something like如果我们在 markdown 文件中使用 HTML 块,例如


<div style="margin-right: 30px;">

Markdown content goes here.

</div>

Then, When GitHub rendered it, the style attribute was automatically removed and no CSS style was applied.然后,当 GitHub 渲染它时,样式属性被自动删除,并且没有应用 CSS 样式。 It will render it something like它会使它像

<div>

Markdown content goes here.

</div>

NB: In the case of positioning, the align attribute is the only way that will currently work.注意:在定位的情况下, align 属性是当前唯一可行的方法。 Despite being deprecated, it's still rendered.尽管被弃用,它仍然被渲染。

You could use &nbsp;你可以使用&nbsp; to make space instead of CSS margin.腾出空间而不是 CSS 边距。

At last, you can do it hacky way ✨最后,你可以用hacky的方式来做✨

While a bit hacky, you can use <dl> , <dt> and <dd> tags in combination to make indent without any enumeration (unlike <ul> / + / - / * or <ol> / 1. 2. 3. ).虽然有点 hacky,但您可以结合使用<dl><dt><dd>标签来进行缩进而不需要任何枚举(不像<ul> / + / - / *<ol> / 1. 2. 3. )。

The lines in preview below are generated by --- , but it works without those.下面预览中的行由---生成,但没有这些行。

See example below:请参见下面的示例:

This is normal text.

---

<dl>
  <dd>This gets indented, without enumeration nor dots.</dd>
</dl>

---

<dl>
  <dd>
    <dl>
      <dd>
        Multiple levels seems to be possible?
      </dd>
    </dl>
  </dd>
</dl>

---

<dl><dd><dl><dd><dl><dd><dl><dd>
Yes, but syntax gets messy, unless you write it single line :)
</dd></dl></dd></dl></dd></dl></dd></dl>

Result preview:结果预览: 结果预览

Check it directly in my GitHub gist here. 直接在我的 GitHub gist 中查看。

You can simply add您可以简单地添加

<div align="center">
<div align="center">
<div align="center">
<p>a</p>
</div>
<p>a</p>
<p>b</p>
</div>
<p>a</p>
<p>b</p>
<p>c</p>
</div>

By adding a div you can customize the position You refer the outcome in my GitHub通过添加一个 div,您可以自定义 position 您参考我的GitHub中的结果结果看起来像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM