我试图用 div 中的相同文本覆盖 textarea 中的文本。我已经设法让它在除 FireFox 之外的所有浏览器中工作(我使用的是 8.0)。在 FireFox 中,textarea 中的文本向左移动 1px。
这是我的代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
div, textarea
{
position:absolute;
top: 0px;
left: 0px;
margin: 0px;
padding: 0px;
font-family: Consolas;
font-size: medium;
border:none;
border-width: 0px;
}
div {color:red;}
textarea {color: blue;}
</style></head>
<body>
<textarea>Stuff</textarea>
<div>Stuff</div>
</body>
</html>
最佳答案
我想我可以为此找到最优雅的解决方案。 Firefox 不会从文本区域中减去一个像素,而是减去一个半个像素。看看这个:
在最新版本的 Firefox、Chrome、Opera 和 Safari 中测试。
关于css - 在 FireFox 的文本区域内定位文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8293384/