html - 将 <li> 文本与列表图像对齐

标签 html css html-lists

我正在制作一个无序列表,并向其应用自定义 list-style-image。它看起来像这样:

My error list

列表从第二行开始。如您所见,文本与列表图像的对齐方式不正确。我怎样才能解决这个问题? 我已经尝试过:

  • 填充
  • 行高
  • 高度

CSS

.formErrorList {
    margin: 10px;
    padding-left: 35px;
    list-style-image: url("/icons/minus.png");
    line-height: 120%;
}

这些属性似乎都没有多大影响。

最佳答案

您可能应该只使用background-image

查看此问答以获取更多信息:Adjust list style image position?

.formErrorList 
{
  margin: 10px;
  line-height: 120%;

  /* get rid of any bullets etc. */
  list-style-type:none;

  /* positioning is: 2px horizontal, 6px vertical. adjust to your needs. 
     you can also use keywords (such as "left", "top") 
     or percentages (eg. 50%) */
  background: url("/icons/minus.png") no-repeat 2px 6px; 

  /* pad to your liking */
  padding: 3px 0px 3px 35px;
}

关于html - 将 <li> 文本与列表图像对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16436893/

相关文章:

css - 使特定 CSS 代码在 IE6 中适用于最新版本的 IE 的最佳方法是什么?

html - 100% 水平跨浏览器菜单 HTML/CSS?

javascript - div 中仅附加了一个 <br> 元素

javascript - 检查所选元素是否包含属性

Javascript onscroll 函数不起作用

html - Div 技巧内联文本?

jquery - Bootstrap 3 : dropdown not working only when fixed navbar is on top position

html - 如何指示带有链接的 LI 已被按下。

javascript - 按字母顺序排列带标题的 HTML 列表

javascript - 尝试用javascript制作座位预订系统并使用本地存储保存数据