Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I try to center a <ul> the text in the <li> centers but the bullet points stay on the far left of the page. Is there any way to get the bullet points to stay with the text when it is centered?

#abc{text-align: center; }  <div id="section1"> <div id="abc"> <ul> <li>one</li> <li>two</li> <li>three</li> </ul> <div/> <div/> 
like image 531
a person Avatar asked Mar 11 '15 01:03

a person


People also ask

How do I move the UL dots to the center?

stackoverflow.com/questions/7516005/… You can use . parentOfUl{ text-align:center;} and then ul{ display:inline-block; }, and at last li{ text-align:center; }.

How do I center a list in UL?

Just give the list centered text (e.g. ul. nav { text-align: center; } ) and the list items inline-block (e.g. ul. nav li { display: inline-block; } ). If you want to do it with margin for whatever reason, look into width: fit-content; .

How do I center an unordered list?

To center align an unordered list, you need to use the CSS text align property. In addition to this, you also need to put the unordered list inside the div element. Now, add the style to the div class and use the text-align property with center as its value.


2 Answers

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>
like image 104
Josh Crozier Avatar answered Oct 02 '22 07:10

Josh Crozier


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

ul {     list-style-position: inside; } 

See working fiddle

like image 40
Michael P. Bazos Avatar answered Oct 02 '22 08:10

Michael P. Bazos