[英]Absolute positioned li overlapping text
So I have a strange problem here, where my text animation requires the li element to be positioned absolute. 所以我在这里有一个奇怪的问题,我的文本动画需要将li元素放置在绝对位置。 This is causing it to flow out of the document flow and I am unable to align the text properly underneath the li without adding padding. 这导致它从文档流中流出,并且在不添加填充的情况下,我无法在li下方正确对齐文本。 I want to display the i element directly underneath the ul. 我想直接在ul下面显示i元素。 I've made a small example of the code https://jsfiddle.net/m479w3sj/ 我已经做了一个代码https://jsfiddle.net/m479w3sj/的小例子
<div id="head">
<ul>
<li>Text 1</li>
<li>Text 2</li>
<li>Text 3</li>
<li><span style="color: #00a9ac">Text 4</span></li>
</ul>
<a class="arrow" href="#main"><i class="fa fa-arrow-down"></i></a>
</div>
CSS 的CSS
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#head ul {
list-style-type: none;
}
#head ul li {
position: absolute;
margin: 0 auto;
width: 100%;
text-align: center;
transition: opacity .5s ease-in;
font-size: 50px;
font-weight: bold;
color: #E3E3E3;
}
#head li + li {
opacity: 0;
}
JS JS
var current = 0,
slides = document.querySelectorAll("#head ul li");
setInterval(function() {
for (var i = 0; i < slides.length; i++) {
slides[i].style.opacity = 0;
}
current = (current != slides.length -1) ? current + 1 : 0;
slides[current].style.opacity = 1;
}, 2000);
I believe this is due to the default css of the ul tag. 我相信这是由于ul标签的默认CSS所致。
https://www.w3schools.com/cssref/css_default_values.asp https://www.w3schools.com/cssref/css_default_values.asp
By setting the padding to zero in the * selector, you are able to place the ul in the center of the page. 通过在*选择器中将padding设置为零,您可以将ul放在页面的中央。
Hope this is what you were looking for! 希望这就是您想要的!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.