在HTML文本区域中添加行

3

在HTML文本框中添加行是可能的。当我说行时,我是指纸质笔记本中的行。类似于这样:







你的目标浏览器是什么?你只计划支持HTML5 + CSS3还是CSS2 + HTML4? - elad.chen
仅支持Chrome浏览器,所有版本的html和css。 - user3758257
你考虑过使用图像背景吗? - Christofer Eliasson
是的,但它必须仅限于CSS。 - user3758257
2个回答

5
您可以使用以下内容:
HTML:
```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
当需要滚动时,行应该跟随移动,不是吗? - George G
Lines should follow the text - user3758257

0
使用一些基本的图像工具创建一条线形图像,并将其作为background添加到文本区域中。
添加CSS:
textarea {
 background: url('path of image') repeat-y;
}

注意:制作图像时,高度应与您将在文本区域中使用的字体相对应。
希望能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接