html - 列表样式图像未显示为 li

标签 html css

我目前正在尝试使用 HTML 和 CSS 自定义列表,因此我尝试使用自定义图像作为 li“点”。 但是,它没有显示。有人能告诉我这段代码有什么问题吗?

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: white;
}
.container > div {
  min-height: 100vh;
  border: 1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}

container > div .content{
  height: 100vh;
  width: 100vw;
  background-color: inherit;
}
.full-width {
  width:100%;              
}
.half-width {
  width:50%;
}

.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
}

list-div {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.list-div ul {
  padding: 0;
  width: 75%;

}

.list-div li {
  position: relative;
  margin-bottom: 5px;
  padding: 10px;
  text-align: left;
  visibility: visible;
  text-transform: uppercase;
}

.list-div li:nth-child(1){
  list-style-image: url('https://fakeimg.pl/30x30/?text=A');
  list-style-position: outside;
}
 <div class="container">
<div class="half-width">
    <div class="half-width-content">
      <div class="list-div">
        <ul class="items-list" id="list">
          <li>List item A</li>
          <li>List item B</li>
          <li>List item C</li>
          <li>List item D</li>
        </ul>
      </div>
    </div>
	</div>
  </div>
</div>

最佳答案

使用 list-style-type: none;margin-left:40px;li

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: white;
}
.container > div {
  min-height: 100vh;
  border: 1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}

container > div .content{
  height: 100vh;
  width: 100vw;
  background-color: inherit;
}
.full-width {
  width:100%;              
}
.half-width {
  width:50%;
}

.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
}

list-div {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.list-div ul {
  padding: 0;
  width: 75%;

}

.list-div li {
  position: relative;
  margin-bottom: 5px;
  padding: 10px;
  text-align: left;
  visibility: visible;
  text-transform: uppercase;
list-style-type: none;
margin-left:40px;
}

.list-div li:nth-child(1){
  list-style-image: url('https://fakeimg.pl/30x30/?text=A');
list-style-position: outside;
 
}
 <div class="container">
<div class="half-width">
    <div class="half-width-content">
      <div class="list-div">
        <ul class="items-list" id="list">
          <li>List item A</li>
          <li>List item B</li>
          <li>List item C</li>
          <li>List item D</li>
        </ul>
      </div>
    </div>
	</div>
  </div>
</div>

编辑你的评论中心 liimage 使用如下 .list-div li:nth-child(1)

background: url(https://fakeimg.pl/30x30/?text=A);
    list-style-type: none;
    margin: 0;
    padding: 10px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: white;
}
.container > div {
  min-height: 100vh;
  border: 1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}

container > div .content{
  height: 100vh;
  width: 100vw;
  background-color: inherit;
}
.full-width {
  width:100%;              
}
.half-width {
  width:50%;
}

.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
}

list-div {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.list-div ul {
  padding: 0;
  width: 75%;

}

.list-div li {
  position: relative;
  margin-bottom: 5px;
  padding: 10px;
  text-align: left;
  visibility: visible;
  text-transform: uppercase;
list-style-type: none;
margin-left:40px;
}

.list-div li:nth-child(1){
background: url(https://fakeimg.pl/30x30/?text=A);
    list-style-type: none;
    margin: 0;
    padding: 10px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
 
}
 <div class="container">
<div class="half-width">
    <div class="half-width-content">
      <div class="list-div">
        <ul class="items-list" id="list">
          <li>List item A</li>
          <li>List item B</li>
          <li>List item C</li>
          <li>List item D</li>
        </ul>
      </div>
    </div>
	</div>
  </div>
</div>

关于html - 列表样式图像未显示为 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52352491/

相关文章:

javascript - HTML onchange 不会从 Ajax 插入中触发

css - simple_form 无法内联对齐 2 个集合选择

css - HTML TBODY 是的...... IE

html - 溢出:隐藏似乎不起作用

css - Bourbon/Neat Grid 问题 - 网格未正确对齐

javascript - if else条件用js改变div颜色

php - 从下拉框中获取选定值的下两个值

jquery - 可操作的列选择和排序问题

html - 修复水平滚动中的列

html - 确保图像被缩小