我想用html/Javascript将一些文本居中,然后在3秒的等待时间之后在可见和不可见之间切换它。我在包含setTimeout()
的JS中使用 函数来更改3秒后的显示属性。然而,尽管我已经尝试过无数的解决方案,但文本既不会出现也不会垂直居中以下是我迄今为止:中心文本和切换可见性
function myfunction() {
document.getElementsByClassName("parent-class").style.display = "table";
document.getElementById("h3").style.display = "table-cell";
setTimeout(function() {
document.getElementById("h3").style.display = "none";
}, 3000);
};
myfunction();
.parent-class {
width: 100%;
height: 100%;
text-align: center;
}
.parent-class>h3 {
vertical-align: middle;
}
<div class="parent-class" style="display:none">
<h3>+</h3>
</div>
如果我不设置属性“显示:无”父类,文本(跨)错误地出现在第一我的程序页面。不知道该从哪里出发,因为这感觉就像我尝试了许多显示器类型和元素配置。请帮忙!
H3是不该元素的ID - 这是一个标记 – Johannes