Styling Textarea with Background that Scrolls with Text?

随声附和 提交于 2019-12-25 05:22:30

问题


I'm trying to create a textarea with a notepad background (like this: http://www.bookofzeus.com/articles/css-styling-textarea-give-notebook-notepad-look/) but I'm running into the same problem in that example of when the text goes to multiple lines past the height and is able to be scrolled through, the background doesn't scroll with it, so it looks bad with just the text floating over all the lines. Is there any way to get the background to move with the text as it scrolls and look like real writing on paper?


回答1:


Maybe:

<html>
  <head>
    <style>
      #fake_textarea{
        width:925px; 
        min-height:100%;
        background-repeat: repeat-y;
        background: url(http://www.artsinmotion.net/notebook_paper.jpg);
        padding-left:100px;
        font-family:arial;
      }

      #wrapper{
        width:1025px; 
        height:500px;
        overflow: auto;
      }
    </style>
  </head>
  <body>
    <div id='wrapper'>
      <div id='fake_textarea' contenteditable></div>
    </div>
  </body>
 </html>  



回答2:


I do not know if there is a CSS-only method. Here is a way that uses jQuery.

It realigns the background y position with the scroll position.

http://jsfiddle.net/WTCUK/



来源:https://stackoverflow.com/questions/12790831/styling-textarea-with-background-that-scrolls-with-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!