How do you center text in Gitlab markdown?

前端 未结 1 2093
失恋的感觉
失恋的感觉 2021-02-18 18:59

After Gitlab switched its markdown engine to CommonMark it\'s no longer as easy to add things like custom styling to your markdown files.

I\'ve used Gitlab for some time

相关标签:
1条回答
  • 2021-02-18 19:21

    Update

    I checked out an old project of mine and noticed that it was already centered. It turns out that CommonMark allows you to set align="center" on <div> tags as well!

    So, the simplest solution for centering is currently (note the empty line after the opening <div>:

    <div align="center">
    
    # This is gonna be centered!
    </div>
    

    Original

    The only CommonMark html object that supports centering (as far as I know) is when you center a table cell. First you might've thought about just making a table and then using align="center", but the table won't take up the entire width of the page, so you'd get a small table on the left hand side of the page, which wouldn't solve our problem of wanting to center stuff relative to the page rather than the table.

    To get around this we set the table width (not using CSS with an inline style tag since it's not supported in CommonMark at the time of writing) to a large value that will take up way more than the total width of the page. Since the max-width: CSS property of tables in Gitlab markdown is 100% it means that by setting a ridiculously high width="" we're essentially setting the table width: to 100% by using only the allowed pure html width="" property.

    The markdown below if placed in e.g. README.md in your Gitlab project will result in a 100% width table with a centered image, title and description. The most notable part is that we're setting width="9999" on the <td> element in the table.

    <table align="center"><tr><td align="center" width="9999">
    <img src="/icon.png" align="center" width="150" alt="Project icon">
    
    # MyProject
    
    Description for my awesome project
    </td></tr></table>
    
    ... More content
    

    Below you can see an example of how your README.md file could look on Gitlab using the above markdown.

    0 讨论(0)
提交回复
热议问题