简体   繁体   English

如何垂直对齐li标签

[英]How to align a li tag vertically

How i can align to center my "li" tag?我如何对齐以将我的“li”标签居中?

    const succes = <a href="#" className='succes'>✓</a>
    const fail = <a href="#" className="fail"></a>
   

   <div className="goals">
      <li>Collect 5 thousand subscribers</li>
      <li>Learn ReactJS </li>
      <li>{succes} Move to apartment</li>
      <li>Start speaking english fluently</li>
  </div>

I need something like this https://imgur.com/S3HVo0h我需要这样的东西https://imgur.com/S3HVo0h

  1. Put li in ulli放入ul
  2. Check what goals class has.检查类有什么goals Does it have text-align:center ?它有text-align:center吗?

 .centered { text-align: center; }
 <ul> <li>First</li> <li>second</li> <li>Third</li> </ul> <div class="centered"> <li>First</li> <li>second</li> <li>Third</li> </div> <!-- UL vs DIV --> <ul class="centered"> <li>First</li> <li>second</li> <li>Third</li> </ul>

Try wrapping all of your list items in a UL element:尝试将所有列表项包装在 UL 元素中:

 <div className="goals">
      <ul>
      <li>Collect 5 thousand subscribers</li>
      <li>Learn ReactJS </li>
      <li>{succes} Move to apartment</li>
      <li>Start speaking english fluently</li>
      </ul>
  </div>

Generally speaking you should always use a list tag to start and close any lists that you are using.一般来说,您应该始终使用列表标签来启动和关闭您正在使用的任何列表。

Take a look at this for further clarification: https://www.w3schools.com/html/html_lists.asp看看这个进一步澄清: https : //www.w3schools.com/html/html_lists.asp

It also may also depend on your CSS too so double check that as well.它也可能也取决于你的 CSS,所以也要仔细检查一下。

You could just nest another <ul> in between, like你可以在中间再嵌套一个<ul> ,比如

<div className="goals">
 <ul>
  <li>Collect 5 thousand subscribers</li>
  <li style="list-style: none;">
    <ul>
      <li>Learn ReactJS </li>
      <li>{succes} Move to apartment</li>
    </ul>
  </li>
  <li>Start speaking english fluently</li>
 </ul>
</div>

I'd like to point out that you can't put a li directly inside a div , because it is not allowed for some reason.我想指出的是,您不能将li直接放在div ,因为出于某种原因不允许这样做。 You should put it in a ul instead to keep the validators happy.你应该把它放在一个ul而不是让验证器高兴。 Like this:像这样:

<div className="goals"> 
    <ul>
        <li>Collect 5 thousand subscribers</li> 
        <li>Learn ReactJS </li> 
        <li>{succes} Move to apartment</li> 
        <li>Start speaking english fluently</li> 
    </ul>
</div>

We can then use a bit of flexbox to center this ul :然后我们可以使用一些 flexbox 来使这个ul居中:

div {
    display: flex;
    justify-content: center;
}

This should hopefully center it!这应该是中心的! Hooray!万岁!

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

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