我正在創建一個用於動態添加學生和教師的簡單應用程序。在動態創建的div問題中垂直居中文本
我正在點擊動態地添加div。
我已將「userListUnit」類添加到該div。
這是JS:
SchoolAdmission.prototype.display = function(nameButton) {
var print = document.createElement("div");
print.className = "userListUnit";
print.innerHTML = "Name: " + this.name + ", age:" + this.age + ", depart: " + this.department + "<br><br><br>";
if (nameButton === "addStudent") {
document.getElementById('studentList').appendChild(print);
}
else {
document.getElementById('teacherList').appendChild(print);
}
clearFields();
};
這是CSS:
.userListUnit{
vertical-align: middle;
border: 1px solid;
text-align: center;
line-height: 10px;
box-shadow: 5px 5px 5px #888888;
margin-bottom: 2em;
}
我的小提琴:http://jsfiddle.net/LPu9x/7/
嘗試加入一個學生或老師,並檢查文本在動態創建的div內的位置,然後您將瞭解其不是垂直居中的。 Any1有任何想法可以解決這個問題嗎?
條件:
1)無位置是:絕對的。
2)Div的創建仍然應該低於一個接一個。
更新小提琴解決方案:http://jsfiddle.net/LPu9x/8/
使用直列標籤如何使用'顯示:表細胞;'[此](http://stackoverflow.com/questions/ 18649106/DIV-垂直對齊,中間的CSS/18649137#18649137)? –
我試過......塊出現在右側,而不是一個接一個下。 –
使用'display:table;'將結果換行爲''width:100%' –