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/>
stackoverflow.com/questions/7516005/… You can use . parentOfUl{ text-align:center;} and then ul{ display:inline-block; }, and at last li{ text-align:center; }.
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; .
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.
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>
You can do that with list-style-position: inside;
on the ul
element :
ul { list-style-position: inside; }
See working fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With