我有以下包含列表及其对齐方式的 HTML/CSS。我设法在 div 的每个 Angular 落获取列表元素,现在我想尝试将图像(基本上用作“列表点”)放在顶部和底部,因此顶部元素的图像居中在它们上方,底部元素在它们下方居中。 有人可以帮我吗?
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>
最佳答案
您可以使用以下内容
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>
关于HTML/CSS 列表图像/元素符号上方/下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52381014/