Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

html - How to set a padding only for new lines of a textarea (while keeping the line-height constant)?

The goal is to have several lines in an HTML textarea that keep the line-height (e.g. 100%). However, when using enter and going to the next line, there should be a padding.

The suggestion to use line-height:20px; will have an effect on all lines. However, I need only a padding after a line break.

JSFiddle https://jsfiddle.net/9bsu74fw/ ← It does apply the line-height to all lines. Not just the line break.

screenshot fiddle textarea padding issue

What is needed:

textarea mockup

How to achieve this with CSS?

question from:https://stackoverflow.com/questions/65936221/how-to-set-a-padding-only-for-new-lines-of-a-textarea-while-keeping-the-line-he

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use ::first-line pseudo selector to apply style on first line only

textarea::first-line {
  line-height: 20px;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...