简体   繁体   English

'textarea' 内的样式文本

[英]Style text inside a 'textarea'

I'm working in this form.我正在以这种形式工作。 Its design is exactly like this:它的设计是这样的:

在此处输入图像描述

Right now I'm at this stage, so I am working on some little details:现在我正处于这个阶段,所以我正在研究一些小细节:

在此处输入图像描述

As you will be able to see, the "Your text..." is stuck to the top left corner of the textarea .如您所见,“您的文字...”粘在textarea的左上角。 I'm trying to find a way to manipulate this via CSS if possible.如果可能的话,我正试图找到一种通过 CSS 来操作它的方法。 I just need to apply some margin/padding to the text inside the textarea .我只需要对textarea内的文本应用一些边距/填充。 If this is not possible with CSS I'm open for suggestions.如果 CSS 无法做到这一点,我愿意接受建议。

How can I manipulate the text inside the textarea via CSS?如何通过 CSS 操作 textarea 内的文本?

You can use CSS padding property:您可以使用 CSS padding属性:

textarea {
    padding: 5px;
}

Use:利用:

textarea {
    padding: 5px;
    box-sizing: border-box;
}

Note : box-sizing is a CSS 3 property.注意:box-sizing 是一个 CSS 3 属性。 It's very useful, because without it width: 100% or other will not work as you expected.它非常有用,因为没有它 width: 100% 或 other 将无法按您的预期工作。

You can use CSS to create the desired effect您可以使用 CSS 创建所需的效果

 textarea { padding: 20px; margin: 10px; }
 <textarea></textarea>

Yes, the padding from CSS applied to textarea is correct.是的,来自 CSS 的填充应用于textarea是正确的。 But then you need to change the "rows" and the "columns" as the dimensions of the whole textarea changes.但是随着整个文本区域的尺寸发生变化,您需要更改“行”和“列”。

You can use the code below:您可以使用以下代码:

line-height: _px;

Use the same value as the height of the textarea.使用与文本区域高度相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM