2014-09-06 56 views
3

是否可以在html textarea中添加行。当我说线条时,我的意思是纸笔记本中的线条。事情是这样的:在HTML texarea中添加行






+0

你定位了哪些浏览器?你只打算只支持html5 + css3或者css2 + html4 – 2014-09-06 14:41:18

+0

只支持Chrome,所有版本的html和css都支持 – user3758257 2014-09-06 14:42:41

+0

你有没有考虑过使用图片背景? – 2014-09-06 14:43:28

回答

6

您可以使用以下方法:

HTML:

<textarea class="paperlines"></textarea> 

CSS:

.paperlines 
{ 
    background-image: -webkit-linear-gradient(left, white 10px, transparent 10px), -webkit-linear-gradient(right, white 10px, transparent 10px), -webkit-linear-gradient(white 30px, #ccc 30px, #ccc 31px, white 31px); 
    background-image: -moz-linear-gradient(left, white 10px, transparent 10px), -moz-linear-gradient(right, white 10px, transparent 10px), -moz-linear-gradient(white 30px, #ccc 30px, #ccc 31px, white 31px); 
    background-image: -ms-linear-gradient(left, white 10px, transparent 10px), -ms-linear-gradient(right, white 10px, transparent 10px), -ms-linear-gradient(white 30px, #ccc 30px, #ccc 31px, white 31px); 
    background-image: -o-linear-gradient(left, white 10px, transparent 10px), -o-linear-gradient(right, white 10px, transparent 10px), -o-linear-gradient(white 30px, #ccc 30px, #ccc 31px, white 31px); 
    background-image: linear-gradient(left, white 10px, transparent 10px), linear-gradient(right, white 10px, transparent 10px), linear-gradient(white 30px, #ccc 30px, #ccc 31px, white 31px); 
    background-size: 100% 100%, 100% 100%, 100% 31px; 
    border: 1px solid #ccc; 
    border-radius: 8px; 
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); 
    line-height: 31px; 
    font-family: Arial, Helvetica, Sans-serif; 
    padding: 8px; 
    width:300px; 
    height:500px; 
} 
.paperlines:focus 
{ 
    outline: none; 
} 

的jsfiddle例如:http://jsfiddle.net/jagmitg/7kteksez/


编辑:添加了另一个例子,共创美好的滚动方法

添加以下到paperlines

http://jsfiddle.net/jagmitg/7kteksez/1/

background-attachment: local; 
+2

当它滚动时,行应遵循,而不是? – 2014-09-06 14:47:55

+0

行应该按照文本 – user3758257 2014-09-06 14:49:59

+0

@ user3758257更新我的答案 – jagmitg 2014-09-06 15:03:52

0

创建像一个线图像使用一些基本的图像工具,并将其添加为background到文本区域

添加CSS:

textarea { 
background: url('path of image') repeat-y; 
} 

注:使图像的高度相应字体你要在文本区域使用

希望它有帮助