简体   繁体   English

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

[英]HTML/CSS list image/bullet above/below

I have the following HTML/CSS containing a list and its alignment. 我有以下HTML / CSS包含列表及其对齐方式。 I managed to get the list elements at each corner of the div, now I want to try to get the image (that is basically used as the 'list-dot') to the top and bottom, so the top elements have their image centered above them and the bottom elements centered below them. 我设法在div的每个角落获取列表元素,现在我想尝试将图像(基本上用作'list-dot')到顶部和底部,因此顶部元素的图像居中在它们上方,底部元素位于它们下方。 Can someone help me here? 有人可以帮我吗?

 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> 

Short picutre to clarifiy: 简短的图片澄清:
在此输入图像描述

You can use the following 您可以使用以下内容

 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> 

You need to change background-position of list like below:- 您需要更改列表的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> 

As I understood your code now is displaying inline (bullet - Name - Letter). 据我所知,您的代码现在显示为内联(bullet - Name - Letter)。 And you want it one over the other. 你想要一个在另一个上面。

So a quick idea is. 所以一个快速的想法是。

Create a Div. 创建一个Div。 With 3 li inside. 里面有3里。 And add the bullet as an image or icon (themify icons for example) 并将子弹添加为图像或图标(例如,通知图标)

<div> 
<li>image dot</li>
<li> Text </li>
<li> text </li>
</div

Hope was this your need. 希望这是你的需要。 You can keep the css, should work 你可以保持CSS,应该工作

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM