简体   繁体   English

在li内垂直对齐文本

[英]align text inside li vertically

I have custom list item markers and when I displaying them text aligned in bottom . 我有自定义列表项标记,当我显示它们时,文本在底部对齐。 How to align it vertically in the center . 如何将其垂直居中对齐。 Display flex and align items doesn't help. 显示弹性和对齐项目无济于事。 Here you can check in sandbox: https://codesandbox.io/s/spring-sun-1yx9k 在这里您可以签入沙箱: https : //codesandbox.io/s/spring-sun-1yx9k

在此处输入图片说明

li {
        list-style-position: outside;
        list-style-image: url("/static/images/list.svg");
    }

I had a similar issue not too long ago and solved it by using a background-image instead of list-style-image since you can't do much for alignment with those. 不久前,我遇到了类似的问题,并通过使用background-image而不是list-style-image background-image来解决了该问题,因为您不能为对齐这些list-style-image做很多事情。

li {
        background-image: url(/static/images/list.svg);
        background-repeat: no-repeat;
        background-position: left;
        list-style-type: none;
        padding: 15px 0 15px 50px;
    }

What about adding a height to the li element eg 如何向li元素添加高度,例如

li {
  height: whateverValueYouWant;
  line-height: whateverValueYouPut;
}

So that it centers it vertically. 使其垂直居中。

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

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