CSS 在文本输入中移动文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5707949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:18:29  来源:igfitidea点击:

Moving the text within a text input

cssinput

提问by MozazDesign

I've made a form, but where I've added a 0px margin to it, it has also applied that margin to text inside the input (e.g. where you would put your name, for a username input) meaning that it's against the left hand edge of the box.

我制作了一个表单,但是在我向它添加了 0px 边距的地方,它还将该边距应用于输入中的文本(例如,您将姓名输入的位置,用于用户名输入),这意味着它在左侧盒子的手边。

How can I added a margin to the text within the box, while keeping the margin on the box itself?

如何为框内的文本添加边距,同时保持框本身的边距?

Thanks in advance.

提前致谢。

采纳答案by locrizak

You're looking for padding not margin.

您正在寻找填充而不是边距。

Margin is outside of the element and padding is on the inside

边距在元素外部,填充在内部

回答by George Daniel

I dont think the people here understand your question completely. The OP is asking how he can apply a margin to the text inside the input form while also still having a margin on the input itself.

我不认为这里的人完全理解你的问题。OP 正在询问他如何在输入表单内的文本上应用边距,同时在输入本身上仍然有边距。

His question is stated a little wrong. What he's looking for is how to INDENT the text inside the input. Use:

他的问题陈述得有点错误。他正在寻找的是如何在输入中缩进文本。用:

text-indent: 10px; // or whatever size you need

EDIT: I do realize this is a 7 year old response, but there really aren't any other proper answers to this via google search.

编辑:我确实意识到这是一个 7 年前的回应,但通过谷歌搜索确实没有任何其他正确的答案。

回答by Naveed Ahmad

Set padding to the text box. Like:

将填充设置为文本框。喜欢:

input.text{padding:5px;}This means padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;

input.text{padding:5px;}这意味着 padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px;

Also, I'm assuming the class name of your text input is text

另外,我假设您的文本输入的类名是 text