27

This might seem like a dumb question, but I've added an UL to a basic page and the list seems to be off-centered. There's nothing special about the list. No specific css added: just a list. When I load live it's slightly off center.
Is there a default margin or padding on the left side?

<h3>Title Heading</h3>
   <ul id="listItems">
       <li>itemOne</li>
       <li>itemTwo</li>
       <li>itemThree</li>
   </ul>

The main body has all the css code for centering, aligning, float, etc. The 'Title Header' align perfectly. Just list is a little off.

Thank you.

Oh, don't know if this is important, but I added the 'id' cause... wanted to use 'first-of-type' to give 1st item em(bold).

shim
  • 9,289
  • 12
  • 69
  • 108
JZeig1
  • 403
  • 1
  • 6
  • 13

2 Answers2

23

The problem is that by default, browsers have custom css - in chrome for example:

ul, menu, dir {
   display: block;
   list-style-type: disc;
   -webkit-margin-before: 1em;
   -webkit-margin-after: 1em;
   -webkit-margin-start: 0px;
   -webkit-margin-end: 0px;
   -webkit-padding-start: 40px;
}

You'll have to use a custom rule for your ul:

element.style {
    margin-left: 0px;
    /* set to 0 if your not using a list-style-type */
    padding-left: 20px;
}
Michael Wilson
  • 1,548
  • 3
  • 21
  • 44
  • 1
    OK, the padding seems to work. I just feel strange adding padding to a default setting that I have no control over or that I can't recognize in my code. But I guess, whatever works. – JZeig1 May 24 '15 at 14:24
10

Lists will always align so the text remains in line with the edge of the parent element. This means the bullet points will by default sit outside (to the left) of the element. You can force the alignment to happen to the bullet point, not the text like so:

ul {
  list-style-position: inside; }

Alternatively you can just add your own margin to push the entire list element like so:

ul {
  margin-left: 20px; }
CaribouCode
  • 13,998
  • 28
  • 102
  • 174
  • Ok, I tried the suggestion two ways. I added the code to css under the selector #itemList. I also added a section around the ul entitled id="bodyList" (I was trying not to mess with my specific code to change f-o-t). Nothing happen. I would use the margin-left, but not sure how it will affect float during resize; additionally there aren't any bullets. – JZeig1 May 24 '15 at 14:18
  • @JZeig1 well it looks like your problem there is applying the CSS to `#itemList ` when it's meant to be `#listItems` – CaribouCode May 24 '15 at 14:28
  • Thanks, this worked, but only when I used the following syntax in my Wordpress website:
      – Ulisses Braga-Neto Sep 15 '20 at 16:03