Align center list items using background image as bullets

允我心安 提交于 2020-01-04 02:29:06

问题


I've been trying to fix this for an hour now and can't find a solution.

What I want is a centered list with background image as "ticks".

I want this:

Works as it should except the dots are aligned to the left of the list ul (1140px wide) and not the left of the list item li which is centered.


回答1:


If you want the dots to be aligned to the left of ul, Use dot image as background:

ul li {
  text-align: center;
  background: url(path/to/dot.png) 0 center no-repeat;
}

JSBin Demo #1

Update

If you need the dots to be aligned to the left of list items, use the following:

ul {
  list-style-type: none;
  padding: 0;
  text-align: center;
  white-space: pre-line;
}

ul li {
  display: inline-block;
  padding-left: 15px;
  background: url(path/to/dot.png) 0 center no-repeat;
}

JSBin Demo #2




回答2:


You can use the css :before pseudo-class:

ul {
  list-style: none;
  text-align: center;
}

li:before {
  content: "\2022";
}

http://jsfiddle.net/e6y9d/



来源:https://stackoverflow.com/questions/18450920/align-center-list-items-using-background-image-as-bullets

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