how do I get the bullet points of a
    to center with the text?

后端 未结 4 1117
野性不改
野性不改 2020-12-14 06:05

When I try to center a

    the text in the
  • centers but the bullet points stay on the far left of the page. Is there any way to ge
相关标签:
4条回答
  • 2020-12-14 06:38

    You can do that with list-style-position: inside; on the ul element :

    ul {
        list-style-position: inside;
    }
    

    See working fiddle

    0 讨论(0)
  • 2020-12-14 06:52

    I found the answer today. Maybe its too late but still I think its a much better one. Check this one https://jsfiddle.net/Amar_newDev/khb2oyru/5/

    Try to change the CSS code : <ul> max-width:1%; margin:auto; text-align:left; </ul>

    max-width:80% or something like that.

    Try experimenting you might find something new.

    0 讨论(0)
  • 2020-12-14 06:55

    Here's how you do it.

    First, decorate your list this way:

    <div class="p">
    <div class="text-bullet-centered">&#8277;</div>
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    </div>
    <div class="p">
    <div class="text-bullet-centered">&#8277;</div>
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text text text 
    </div>
    

    Add this CSS:

    .p {
        position: relative;
        margin: 20px;
        margin-left: 50px;
    }
    .text-bullet-centered {
        position: absolute;
        left: -40px;
        top: 50%;
        transform: translate(0%,-50%);
        font-weight: bold;
    }
    

    And voila, it works. Resize a window, to see that it indeed works.

    As a bonus, you can easily change font and color of bullets, which is very hard to do with normal lists.

    .p {
      position: relative;
      margin: 20px;
      margin-left: 50px;
    }
    
    .text-bullet-centered {
      position: absolute;
      left: -40px;
      top: 50%;
      transform: translate(0%, -50%);
      font-weight: bold;
    }
    <div class="p">
      <div class="text-bullet-centered">&#8277;</div>
      text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
      text text text text text text text text text text text text text
    </div>
    <div class="p">
      <div class="text-bullet-centered">&#8277;</div>
      text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
      text text text text text text text text text text text text text
    </div>

    0 讨论(0)
  • 2020-12-14 06:59

    Add list-style-position: inside to the ul element. (example)

    The default value for the list-style-position property is outside.

    ul {
        text-align: center;
        list-style-position: inside;
    }
    <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>

    Another option (which yields slightly different results) would be to center the entire ul element:

    .parent {
      text-align: center;
    }
    .parent > ul {
      display: inline-block;
    }
    <div class="parent">
      <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
      </ul>
    </div>

    0 讨论(0)
提交回复
热议问题