Unusual shape of a textarea?

后端 未结 10 786
無奈伤痛
無奈伤痛 2020-11-29 15:03

Usually textareas are rectangular or square, like this:

\"Usual

But I want a custom-shaped

相关标签:
10条回答
  • 2020-11-29 15:36

    You could work with a contenteditable div, with two corners divs:

    <div style="border:1px blue solid ; width: 200px; height: 200px;" contenteditable="true">
      <div style="float:left; width:50px; height: 50px; border: 1px solid blue" contenteditable="false"></div>
      <div style="float:right; width:50px; height: 50px;  border: 1px solid blue" contenteditable="false"></div>
      hello world, hello worldsdf asdf asdf sdf asdf asdf
    </div>
    
    0 讨论(0)
  • 2020-11-29 15:39

    You can use Google web designer tool for creating complex shapes using HTML5-canvas and CSS.

    More over you will get other tools like typing tools to enter texts inside these shapes.

    As the output file contains much code, providing a fiddle of a sample demo created using Google Web Designer tool

    FIDDLE DEMO>>

    0 讨论(0)
  • 2020-11-29 15:42

    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 result with Firefox 28

    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>

    0 讨论(0)
  • 2020-11-29 15:43

    If you combine CSS shapes with contenteditable this can be done in webkit browsers.

    First you have to enable the flag: enable-experimental-web-platform-features

    Then restart your webkit browser and then check this FIDDLE out !

    This method will work for non-standard shapes as well.

    Markup

     <div class="shape" contenteditable="true">
        <p>
         Text here
        </p>
      </div>
    

    CSS

    .shape{
      -webkit-shape-inside: polygon(71.67px 204.00px,75.33px 316.47px,323.67px 315.47px,321.17px 196.00px,245.96px 197.88px,244.75px 87.76px,132.33px 87.53px,132.50px 202.26px);
      shape-inside: polygon(71.67px 204.00px,75.33px 316.47px,323.67px 315.47px,321.17px 196.00px,245.96px 197.88px,244.75px 87.76px,132.33px 87.53px,132.50px 202.26px);
      width: 400px;
      height: 400px;
      text-align: justify;
      margin: 0 auto;
    }
    

    So how on earth did I get that polygon shape?

    Go to this site and make your own custom shape!

    Notes about enabling the flag: (from here)

    To enable Shapes, Regions, and Blend Modes:

    Copy and paste chrome://flags/#enable-experimental-web-platform-features into the address bar, then press enter. Click the 'Enable' link within that section. Click the 'Relaunch Now' button at the bottom of the browser window.

    0 讨论(0)
提交回复
热议问题