[英]Center absolute UL's LI
I'm trying to center the dots on my absolute UL. 我试图将点放在我的绝对UL上。 I've had a lot of trouble after trying lots of different answers around the web.
在网上尝试了许多不同的答案后,我遇到了很多麻烦。
Here's the CSS (.new-dots is the UL): 这是CSS(.new-dots是UL):
.photos {
.new-dots {
width: 100%;
position: absolute;
top: 0;
text-align: center;
li {
display: inline;
color: rgba(202, 202, 202, 0.78);
margin-right: 5px;
button {
background: rgba(202, 202, 202, 0.75);
border-width: 0;
width: 16px;
height: 16px;
border-radius: 8px;
color: transparent;
}
button:focus {
outline: none;
}
}
.slick-active {
button {
background: #FFF !important;
}
}
}
.photo {
height: 100vw;
}
}
Add this to the elemet and it will center the child element inside the parent element. 将其添加到要素中,它将子元素居于父元素内部。
Code Example 代码示例
body { position: relative; height: 100vh; } .new-dots { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
<div class="new-dots">Test Content</div>
display: inline-block;
display: inline-block;
in li
from display: inline;
li
从display: inline;
. By default ul
have their own padding
and margin
, so you need to remove that. 默认情况下,
ul
有其自己的padding
和margin
,因此您需要删除它们。 in your case, you have to set padding-left: 0
. 在您的情况下,您必须设置
padding-left: 0
。
In addition, you can also remove width: 100%
from the ul
and set left
and right
to 0
so that it occupy it's parents full width. 此外,您还可以删除
width: 100%
从ul
删除width: 100%
,并将left
和right
设置为0
,以使其占据其父母的全角。
.photos .new-dots { position: absolute; top: 0; left: 0; right: 0; text-align: center; padding-left: 0; } .photos .new-dots li { display: inline-block; color: rgba(202, 202, 202, 0.78); margin-right: 5px; } .photos .new-dots li button { background: rgba(202, 202, 202, 0.75); border-width: 0; width: 16px; height: 16px; border-radius: 8px; color: transparent; } .photos .new-dots li button:focus { outline: none; } .photos .new-dots .slick-active button { background: #fff !important; } .photos .photo { height: 100vw; }
<div class="photos"> <ul class="new-dots"> <li><button>123</button></li> <li><button>456</button></li> <li><button>789</button></li> </ul> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.