使用背景图像设置有序列表的样式

时间:2017-02-22 10:56:31

标签: html css

.color-overlap-right {
	background-color : #d93;
	margin-right : -25%;
}

ol {
	margin-left:0; 
	padding-left:0; 
	counter-reset: ol-item
}

ol li {
	margin-left:0; 
	padding-left:0; 
	list-style-type:none; 
	counter-increment: ol-item;
}

ol li:before {
	content:counter(ol-item) " ";
	background-image: url('../img/square.png');
	background-position: 0 -20px;
  background-repeat: no-repeat;
}
<html lang="en">
<div class="container">
  <div class="color-overlap-right">
			<div class="left-text">
        <ol style="list-style: aliceblue;">
            <li>Earn</li>
						<li>Transfer</li>
						<li>Apply</li>
        </ol>
      </div>
	</div>
</div>

我想在HTML中创建一个看起来像这样的有序列表

enter image description here

这应该有没有“点”的有序列表 编号应使用斜体和字体大小进行自定义。 应该具有显示的背景图像/颜色。有人可以帮忙吗?我目前能够删除“点”并添加背景颜色。但是,我无法调整背景图像和数字之间的边距,使其看起来类似于下面显示的内容。有人可以帮忙吗?

3 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

<强> HTML:

<ol class="mylist">
  <li>
    <div>&nbsp;</div><span>Earn</span></li>
  <li>
    <div>&nbsp;</div><span>Transfer</span></li>
  <li>
    <div>&nbsp;</div><span>Apply</span></li>
</ol>

<强> CSS:

body {
  background-color: #d93;
}

.mylist {
  font-size: 25px;
}

.mylist li {
  position: relative;
  counter-increment: section;
  list-style: none;
  margin-left: -20px;
  z-index: 0;
}

.mylist li span {
  font-size: 17px;
  font-family: arial;
  color: #FFFFFF;
}

.mylist li div {
  position: absolute;
  left: 0px;
  bottom: 0px;
  display: inline-block;
  width: 15px;
  height: 15px;
  background-color: #D25F15;
  z-index: 1;
  border-radius: 2px;
}

.mylist li:before {
  position: relative;
  font-style: italic;
  font-weight: bold;
  color: #FFFFFF;
  content: counter(section) " ";
  margin-left: 12px;
  z-index: 2;
}

Demo

答案 1 :(得分:0)

html {
    background-color : #d93;

}

ol {
    margin-left:0; 
    padding-left:0; 
    counter-reset: ol-item;
  color:#fff;
  font-family: arial;
}

ol li {
    margin-left:0; 
    padding-left:0; 
    list-style-type:none; 
    counter-increment: ol-item;

}

ol li:before {
    font-size:40px;
  background:  #d25f14;
  content: counter(ol-item) ;
  width:28px;
  height:24px;
  overflow:show;
  display:inline-block;
  background:url(place your image here);
  text-align:right;
  margin-bottom:20px;
  margin-right:10px;
}

使用此CSS并按照您希望的方式制作图像

答案 2 :(得分:0)

我猜您只需添加一些 CSS 属性即可实现此设计, 在 ol li:before 选择器

中添加这些css
ol li:before {
  font-size: 39px;
  color: #fff;
  font-weight: bold;
  padding-left: 15px;
  text-shadow: -4px 2px 7px #504747;
  font-style: italic;
  font-family: sans-serif;
}

<强>被修改

/*This is for square box*/
    ol li:after{
      content: "";
      display: block;
      background: #ab6b0b;
      position: absolute;
      top: 17px;
      left: 3px;
      height: 18px;
      width: 17px;
    }

结果将是这样的:

enter image description here

您可以根据用户界面修改字体颜色和阴影

.color-overlap-right {
  background-color: #d93;
  margin-right: -25%;
}

ol {
  margin-left: 0;
  padding-left: 0;
  counter-reset: ol-item
}

ol li {
  margin-left: 0;
  padding-left: 0;
  list-style-type: none;
  counter-increment: ol-item;
  position: relative;
}

ol li:before {
  content: counter(ol-item) " ";
  background-image: url('../img/square.png');
  background-position: 0 -20px;
  background-repeat: no-repeat;
  font-size: 39px;
  color: #fff;
  font-weight: bold;
  padding-left: 25px;
  text-shadow: -4px 2px 7px #504747;
  font-style: italic;
  font-family: sans-serif;
}

ol li:after{
    content: "";
    display: block;
    background: #ab6b0b;
    position: absolute;
    top: 17px;
    left: 3px;
    height: 18px;
    width: 17px;
}
<html lang="en">
<div class="container">
  <div class="color-overlap-right">
    <div class="left-text">
      <ol style="list-style: aliceblue;">
        <li>Earn</li>
        <li>Transfer</li>
        <li>Apply</li>
      </ol>
    </div>
  </div>
</div>