html - 如何在 Kramdown Markdown 中水平居中 HTML 元素?

标签 html css markdown kramdown

我的 Markdown 文件 (kramdown) 中有一个 HTML 元素,它基本上只有两列。这是一个例子:https://codepen.io/KidPiano/pen/NWWzLjE .

<div style="-webkit-column-count: 2; -moz-column-count: 2; column-count: 2; -webkit-column-rule: 1px dotted #e0e0e0; -moz-column-rule: 1px dotted #e0e0e0; column-rule: 1px dotted #e0e0e0;">

<div style="display:inline-block">
<h2 style="text-align:center">Good</h2>
<pre><code class="language-c">int foo (void)    
{
    int i;
}
</code></pre>
</div>

<div style="display:inline-block">
<h2 style="text-align:center">Bad</h2>
<pre><code class="language-c">int foo (void) {
    int i;
}  
<span style="background-color:cyan">test</span>
</code></pre>
</div>

</div>

有什么方法可以让这些列在页面中间水平居中吗?

编辑:在下面回答 - 不要使用列数

最佳答案

试试这个

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

  <div style="display:inline-block;text-align:left;">
    <h2 style="text-align:center">Good</h2>
    <pre>
        <code class="language-c">
          int foo (void)    
          {
          int i;
          }
        </code>
    </pre>
  </div>

  <div style="display:inline-block;text-align:left;">
    <h2 style="text-align:center">Bad</h2>
    <pre>
        <code class="language-c">
        int foo (void) 
        {
        int i;
        }  
        <span style="background-color:cyan">test</span>
       </code>
   </pre>
  </div>

</div>

关于html - 如何在 Kramdown Markdown 中水平居中 HTML 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58778827/

相关文章:

html - 如何仅使用 css 创建一个三 Angular 形的 div?

在 Doxygen 中使用 @file 进行 Markdown

markdown - 如何在 Markdown 中插入换行符 <br>

javascript - 悬停时 Bootstrap 下拉,但主下拉仍然是一个链接

javascript - jquery - 获取 html 表中 <tr> 的值

javascript - Bootstrap : Better way of lining up elements in columns and rows when you have to skip some

r - 如何让\bm{} 在 R markdown(到 HTML)文件中工作?

html - 子菜单创造额外空间

javascript - 在 contenteditable 按钮中输入空格时 Chrome 触发 onClick

html - 如何在使用垂直对齐属性 html 时删除边框