Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  64] [ 1]  / answers: 1 / hits: 14744  / 11 Years ago, sun, december 22, 2013, 12:00:00

Usually textareas are rectangular or square, like this:



Usual



But I want a custom-shaped textarea, like this, for example:



Custom-shaped



How is this possible?


More From » jquery

 Answers
1

Introduction



First, there are many solutions, proposed in other posts. I think this one is currently (in 2013) the one which can be compatible with the largest number of browsers, because it doesn't need any CSS3 properties. However, the method will not work on browsers which doesn't support contentdeditable, be careful.



Solution with a div contenteditable



As proposed by @Getz, you can use a div with contenteditable and then shape it with some div on it. Here is an example, with two blocks which float at the upper left and the upper right of the main div:



The



As you can see, you have to play a little with the borders if you want the same result as you requested in your post. The main div has the blue border on every side. Next, red blocks has to be sticked to hide top borders of the main div, and you need to apply border to them only on particular sides (bottom and left for the right block, bottom and right for the left).



After that, you can get the content via Javascript, when the Submit button is triggered for example. And I think you can also handle the rest of the CSS (font-size, color, etc.) :)



Full code sample





.block_left {
background-color: red;
height: 70px;
width: 100px;
float: left;
border-right: 2px solid blue;
border-bottom: 2px solid blue;
}

.block_right {
background-color: red;
height: 70px;
width: 100px;
float: right;
border-left: 2px solid blue;
border-bottom: 2px solid blue;
}

.div2 {
background-color: white;
font-size: 1.5em;
border: 2px solid blue;
}

.parent {
height: 300px;
width: 500px;
}

<div class=parent>
<div class=block_left></div>
<div class=block_right></div>
<div class=div2 contenteditable=true>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut...
</div>
</div>




[#49304] Friday, December 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;