Indent on second line of <li> text

两盒软妹~` 提交于 2021-02-17 05:34:47

问题


I need to use both discs and list-style-type: lower-roman; to style a list.

But because I'm using content: "•"; in a :before pseudo element to create the disc effect, the second line of the <li> text does not line up.

Is there an easier way to do this?

eg:

i•Some list text which
goes onto the second line            //need this to be in line with the text above
   i  sub list text1
   ii sub list text2

I'm currently using

ul>li:before {
    content: "•";
}
ol{
    margin-left: 24px;
}
ol, ul{
   list-style-type: lower-roman
}
<ul>
   <li>Some list text which goes onto the second line
       <ol>
           <li>sub list text1</li>
           <li>sub list text1</li>
       <ol>
   </li>
</ul>

回答1:


You can apply a padding-left to the ul > li to indent it as a whole, make it's position: relative and use position: absolute and left on the :before pseudo-element to adjust the horizontal position of the "•" in relation to the left end of the li:

ul>li {
  padding-left: 15px;
  position: relative;
}

ul>li:before {
  content: "•";
  position: absolute;
  left: 5px;
}

ol {
  margin-left: 24px;
}

ol,
ul {
  list-style-type: lower-roman
}
<ul>
  <li>Some list text which goes onto the second line. Some list text which goes onto the second line. Some list text which goes onto the second line
    <ol>
      <li>sub list text1</li>
      <li>sub list text1</li>
      <ol>
  </li>
</ul>



回答2:


You need to use list-style-position

ul>li:before {
    content: "•";
    margin-right:5px;

    
}
ul{
    list-style-position: inside;
}
ol{
    margin-left: 24px;
    list-style-position: outside;  /* or NOT, it depends on what you like  to do */
}
ol, ul{
   list-style-type: lower-roman
}
<ul>
   <li>Some list text which goes onto the second linegoes onto the second linegoes onto the second linegoes onto the second linegoes onto the second linegoes onto the second line
       <ol>
           <li>sub list text1</li>
           <li>sub list text1</li>
       <ol>
   </li>
</ul>


来源:https://stackoverflow.com/questions/61920249/indent-on-second-line-of-li-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!