我想用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