HTML / CSS列表图像/上方/下方项目符号

时间:2018-09-18 07:21:17

标签: html css

我有以下HTML / CSS,其中包含一个列表及其对齐方式。我设法在div的每个角上获取了列表元素,现在我想尝试使图像(基本上用作“列表点”)位于顶部和底部,因此顶部元素的图像居中在它们上方,底部元素居中于它们下方。 有人可以帮我吗?

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: beige;
}
.container > div {
  min-height: 100vh;
  border:1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}
.half-width {
  width:50%;
}
.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.list-div {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 75%;
    height: 75%;
}

.list-div ul {
  padding: 0;
  margin-top: 15%;
  width: 75%;
}

.list-div li {
  position: absolute;
}

.list-div li:nth-child(1){
  top: 0;
  left: 0;
    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;
    background-position-y: 50%;
}
.list-div li:nth-child(2){
  top: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=B);
      list-style-type: none;
    margin: 0;
    padding: 10px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-y: 50%;
}
.list-div li:nth-child(3){
  bottom: 0;
  left: 0;
  background: url(https://fakeimg.pl/30x30/?text=C);
      list-style-type: none;
    margin: 0;
    padding: 10px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-y: 50%;
}
.list-div li:nth-child(4){
  bottom: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=D);
      list-style-type: none;
    margin: 0;
    padding: 10px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-y: 50%;
}



@media max-width:768px{
  
  
  .list-div li.animate{
  visibility: visible;
}
  .list-div {
  display: flex;
  justify-content: center;
  align-items: center;
}
}
<div class="container">
<div class="half-width">
    <div class="half-width-content" id="list-cont">
      <div class="list-div">
        <ul>
          <li>Entry A</li>
          <li>Entry B</li>
          <li>Entry C</li>
          <li>Entry D</li>
        </ul>
      </div>
    </div>
  </div>
</div>

需要澄清的简短图片:
enter image description here

3 个答案:

答案 0 :(得分:2)

您可以使用以下

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: beige;
}
.container > div {
  min-height: 100vh;
  border:1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}
.half-width {
  width:50%;
}
.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.list-div {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 75%;
    height: 75%;
}

.list-div ul {
  padding: 0;
  margin-top: 15%;
  width: 75%;
}

.list-div li {
  position: absolute;
}

.list-div li:nth-child(1){
  top: 0;
  left: 0;
    background: url(https://fakeimg.pl/30x30/?text=A);
      list-style-type: none;
   
   padding-top: 40px;
    box-sizing: border-box;
    text-align:center;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-x: 50%;
    width:100px;
}
.list-div li:nth-child(2){
  top: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=B);
     list-style-type: none;
   
   padding-top: 40px;
    box-sizing: border-box;
    text-align:center;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-x: 50%;
    width:100px;
}
.list-div li:nth-child(3){
  bottom: 0;
  left: 0;
  background: url(https://fakeimg.pl/30x30/?text=C);
    list-style-type: none;
   
   padding-bottom: 40px;
    box-sizing: border-box;
    text-align:center;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-x: 50%;
    background-position-y: 100%;
    width:100px;
}
.list-div li:nth-child(4){
  bottom: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=D);
    list-style-type: none;
   
   padding-bottom: 40px;
    box-sizing: border-box;
    text-align:center;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position-x: 50%;
    background-position-y: 100%;
    width:100px;
}



@media max-width:768px{
  
  
  .list-div li.animate{
  visibility: visible;
}
  .list-div {
  display: flex;
  justify-content: center;
  align-items: center;
}
}
<div class="container">
<div class="half-width">
    <div class="half-width-content" id="list-cont">
      <div class="list-div">
        <ul>
          <li>Entry A</li>
          <li>Entry B</li>
          <li>Entry C</li>
          <li>Entry D</li>
        </ul>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:1)

您需要更改列表的background-position,如下所示:-

body {
  margin:0;
}
.container {
  display:flex;
  flex-wrap:wrap;    
  flex-direction:row;    
  height:100vh;
  background-color: beige;
}
.container > div {
  min-height: 100vh;
  border:1px solid black;
  box-sizing:border-box;
  background-color: inherit;
}
.half-width {
  width:50%;
}
.half-width > .half-width-content{
  position: relative;
  margin-top: 0;
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.list-div {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 75%;
    height: 75%;
}

.list-div ul {
  padding: 0;
  margin-top: 15%;
  width: 75%;
  text-align: center;
}

.list-div li {
  position: absolute;
}

.list-div li:nth-child(1){
  top: 0;
  left: 0;
    background: url(https://fakeimg.pl/30x30/?text=A);
      list-style-type: none;
    margin: 0;
    padding: 41px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position: 55px 2px;
}
.list-div li:nth-child(2){
  top: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=B);
      list-style-type: none;
    margin: 0;
    padding: 41px 10px 10px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position: 55px 2px;
}
.list-div li:nth-child(3){
  bottom: 0;
  left: 0;
  background: url(https://fakeimg.pl/30x30/?text=C);
      list-style-type: none;
    margin: 0;
    padding: 10px 10px 42px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position: 50px 54px;
}
.list-div li:nth-child(4){
  bottom: 0;
  right: 0;
    background: url(https://fakeimg.pl/30x30/?text=D);
      list-style-type: none;
    margin: 0;
    padding: 10px 10px 42px 48px;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position: 50px 54px;
}



@media max-width:768px{
  
  
  .list-div li.animate{
  visibility: visible;
}
  .list-div {
  display: flex;
  justify-content: center;
  align-items: center;
}
}
  <div class="container">
    <div class="half-width">
        <div class="half-width-content" id="list-cont">
          <div class="list-div">
            <ul>
              <li>Entry <br>A</li>
              <li>Entry <br>B</li>
              <li>Entry <br>C</li>
              <li>Entry <br>D</li>
            </ul>
          </div>
        </div>
      </div>
    </div>

答案 2 :(得分:0)

据我了解,您的代码现在正在显示内联(项目符号-名称-字母)。 而您想要它一个。

一个简单的主意是。

创建一个Div。里面有3李并将子弹添加为图像或图标(例如,将其图标化)

Code

希望这是您的需要。 您可以保留CSS,应该可以工作

谢谢