Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a bottom border for every row in a textarea?

I am trying to figure out how to add a border-bottom line for every row within a <textarea>, however I am only able to get the very bottom row's border-bottom to do this.

Is there a way to accomplish this?

.input-borderless {
  width: 80%;
  border-top: 0px;
  border-bottom: 1px solid green;
  border-right: 0px;
  border-left: 0px;
  background-color: rgb(241,250,247);
  text-decoration: none;
  outline: none;
  display: block;
  padding: 10px 0;
  margin: 20px 0;
  font-size: 1.6em;
}
<textarea rows="3" class="input-borderless" placeholder="Describe the project"></textarea>
like image 683
Becky Avatar asked Jan 15 '16 02:01

Becky


People also ask

How do you put a border around text area?

To add a border to the textarea element, we use css() method. The css() method is used to change style property of the selected element. The css() in jQuery can be used in different ways.

How do I change the bottom length of a border?

You can go in to the HTML and add another element below the element you want to have the border-bottom and give it a background that is the color you want the border to be and then set the width and height, which is what I have done for years. Skip straight to the code.


2 Answers

You can use gradient as the background image to get an effect that looks like underline:

JSFiddle

textarea
{
  line-height: 4ch;
  background-image: linear-gradient(transparent, transparent calc(4ch - 1px), #E7EFF8 0px);
  background-size: 100% 4ch;
}
like image 125
Ofir A. Avatar answered Sep 28 '22 06:09

Ofir A.


The idea is to use layers, make the textarea as top layer, the multiple lines as bottom layer.

I'm using a pseudo element for the bottom layer, since :before and :after does not work on a textarea, so I set it on the container div element.

For the bottom lines, I simply use underscores _, with \A for a line break, you can have as many lines as needed with a number of \A. The height of each line will get updated automatically according to the font size.

Jsfiddle Example

.container {
  width: 200px;
  border: 1px solid green;
  position: relative;
  overflow: hidden;
}
.container:before, .container textarea {
  font-family: sans-serif;
  font-size: 20px;
}
.container textarea {
  width: 100%;
  box-sizing: border-box;
  background-color: transparent;
  border: 0;
  outline: none;
  display: block;
  line-height: 1.2;
}
.container:before {
  position: absolute;
  content: "____________________\A____________________";
  z-index: -1;
  left: 0;
  top: 0;
  width: 100%;
  color: silver;
  line-height: 1.4;  
}
<div class="container">
  <textarea rows="3" placeholder="Hello"></textarea>
</div>
like image 41
Stickers Avatar answered Sep 28 '22 04:09

Stickers