marktext 文字居中,如何在Gitlab markdown中居中显示文本?

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 and for the longest time I've liked how nicely I could make my README.md file look, having a centered icon, title and description for my project. When they switched the engine all my markdown files that relied on having such stylings look really bad.

How do I center text in Gitlab after the transition to CommonMark?

解决方案

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

tags as well!

So, the simplest solution for centering is currently (note the empty line after the opening

:

# This is gonna be centered!

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

element in the table.

Project icon

# MyProject

Description for my awesome project

... More content

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

74e5e7f5b949a1ca3df9c54ed281bd4a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值