如何让GitHub README.md中项目符号居中且符号左对齐?
解决GitHub README列表居中且项目符号左对齐的问题
问题原因
你之前的方法无效,是因为GitHub对README中的HTML样式有一定限制,且混用markdown列表符号(-)和<br>标签的方式,会导致列表结构不规范,样式无法正确生效。
有效解决方案
使用规范的HTML列表标签配合内联样式,既能让整个列表块居中,又能保证项目符号左对齐成一条竖线:
<div align="center"> <small> <ul style="display: inline-block; text-align: left; margin: 0;"> <li>Total number of months included in the dataset</li> <li>Net total amount of profit/losses over the entire period</li> <li>Average of the changes in profit/losses over the entire period</li> <li>Greatest increase in profits (date and amount) over the entire period</li> <li>Greatest decrease in losses (date and amount) over the entire period</li> </ul> </small> </div>
代码说明
<div align="center">:让整个容器内的内容水平居中<ul style="display: inline-block; text-align: left; margin: 0;">:display: inline-block:让列表块根据内容宽度自适应,而非占满整行,确保能在父容器中居中text-align: left:让列表内的文字和项目符号保持左对齐margin: 0:去除列表默认的外边距,避免多余间距
<li>标签:用规范的列表项结构,保证项目符号自然对齐
内容的提问来源于stack exchange,提问作者Elliot
相关产品推荐
相关产品推荐

