Unusual shape of a textarea?

后端 未结 10 869
無奈伤痛
無奈伤痛 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:28

    You could also do this with CSS Regions

    With Regions, you can use CSS properties to flow content into existing styled containers, specifying any container order you choose, regardless of their position on the page.

    (Web Platform)

    enter image description here

    [Currently supported in WebKit Nightly, Safari 6.1+ and iOS7 and already usable in chrome and opera after enabling the flag: enable-experimental-web-platform-features - caniuse, Web Platform ]

    FIDDLE

    So you could make that textarea shape by flowing the text through 2 regions, and edit it by adding contenteditable on the content.

    Markup

    text here

    (Relevant) CSS

    #content {
         -ms-flow-into: article;
        -webkit-flow-into: article;
    }
    
    .region {
        -ms-flow-from: article;
        -webkit-flow-from: article;
        box-sizing: border-box;
        position: absolute;
        width: 200px;
        height: 200px;
        padding: 0 1px;
        margin: auto;
        left:0;right:0;
        border: 2px solid lightBlue;
    }
    
    #box-a {
        top: 10px;
        background: #fff;
        z-index: 1;
        border-bottom: none;
    }
    
    #box-b {
        top: 210px;
        width: 400px;
        overflow: auto;
        margin-top: -2px;
    }
    

    The result:

    enter image description here

    For more info about regions - here's a good aricle: CSS3 regions: Rich page layout with HTML and CSS3

提交回复
热议问题