我正在尝试使用 javascript 在屏幕底部插入一些居中对齐的文本。
目前为止
var toInsert = document.createElement("div");
toInsert.innerHTML = "text to insert";
toInsert.style.position = "absolute";
toInsert.style.bottom = "0px";
这会按照我的意愿将它放在屏幕底部,但是当我尝试使用它时
toInsert.style.textAlign="center";
居中对齐似乎被上面的“绝对”属性覆盖,文本左对齐。
我怎样才能将文本放在屏幕底部,并使其居中? 谢谢。
附言。 javascript 而非 jquery,用于 iOS 设备上的 UIWebView。
最佳答案
确保您的 div 宽度为 100%。
toInsert.style.width = "100%";
var toInsert = document.createElement("div");
toInsert.innerHTML = "text to insert";
toInsert.style.position = "absolute";
toInsert.style.bottom = "0px";
toInsert.style.textAlign = "center";
toInsert.style.width = "100%";
document.body.appendChild(toInsert);
关于Javascript将居中文本放在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26981201/