Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button inside TextArea in HTML

Tags:

html

css

I am looking to create a structure, in which a button is aligned to the top right of a textarea. I was able to do that using CSS positioning. When I start typing inside the textarea, the text comes below the button. Is there a way so that the text normally occupies the full width of the text area, but on reaching the bounds of the button, gets wrapped to the next line?

like image 1000
saurabhsood91 Avatar asked May 30 '14 09:05

saurabhsood91


People also ask

How do I add a button to a text box?

for Simple purpose use this method, Set fixed width for both text box and button.. for eg: text width is 200px , button will be 40px and add margin-left:-40px (based on your need) so it will be fixed between 160-200px of input text box..

Can I put Div inside textarea?

You cannot place HTML elements inside a text area, only text content. only text content covers that part.

Can we add link in textarea in HTML?

You can't place any 'Active Link' inside a text area. A text area is designed to displaying text only content. Instead of that you can use div and using some css make div as a text area.


2 Answers

There is always an option to use contentEditable attribute on an inline element instead of <textarea> and put it next to a floating button.

HTML:

<div>
    <button>press me</button>
    <span contenteditable="true">editable</span>
</div>

CSS:

div {border: 1px solid gray; width: 15em; height: 5em; overflow-y: scroll;}
button {float: right;}

jsFiddle

like image 116
Aprillion Avatar answered Sep 25 '22 06:09

Aprillion


Fake it. Wrap the textarea and button in a containing div and position the elements. then style the container div to look like the text area. here's a rough mockup http://jsfiddle.net/LEkAJ/

HTML

<div class="container">
  <button>Button</button>
  <textarea>Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</textarea>
</div>

CSS

.container {
    position:relative;
    width: 300px;
    height: 100px;
    border: 1px solid #ddd;
}
button {
    position:absolute;
    top: 3px;
    right:3px;
    width: 60px;
}
textarea {
    position:relative;
    border:none;
    width:232px;
    height: 95px;
    resize: none;
    outline: none; /* add this to stop highlight on focus */
}
like image 28
Liam Avatar answered Sep 23 '22 06:09

Liam