How to properly style a text area with inner shadows and scrollbar

前端 未结 4 1815
生来不讨喜
生来不讨喜 2021-01-31 18:19

I\'m putting an inner-shadow on all my controls, inputs and textareas by using the following CSS:

input {
  padding: 7px;
  -webkit-box-shadow: inset 2px 2px 2px         


        
相关标签:
4条回答
  • 2021-01-31 18:40

    Getting the padding property to affect only the content but not the scrollbar is not possible using standard textarea elements. For that you can use a contenteditable DIV. For example, check this fiddle: http://jsfiddle.net/AQjN7/

    HTML:

    <div class="outer" contenteditable="true">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
    

    CSS:

    .outer {
        -webkit-box-shadow: inset 2px 2px 2px 0px #ffffdffffd;
        -moz-box-shadow: inset 2px 2px 2px 0px #ffffdffffd;
        box-shadow: inset 2px 2px 2px 0px #ffffdffffd;
        height: 200px;
        margin: 10px;
        overflow: auto;
        padding: 7px 10px;
        width: 300px;    
        font-family: tahoma;
        font-size: 13px;
        border: 1px solid #aaa;
    }
    ​
    
    0 讨论(0)
  • 2021-01-31 18:41

    You could wrap the textarea in a div:

    <div class="textarea-wrapper">
        <textarea>
    </div>
    

    css:

    .textarea-wrapper{
        box-shadow: inset 2px 2px 2px 0px #ffffd;
    }
    textarea {
        padding: 10px;
        background: transparent;
        border: none;
    }
    

    A jsFiddle here: http://jsfiddle.net/rXpPy/

    0 讨论(0)
  • 2021-01-31 18:43

    Additionally - rather than using simply input, which will target buttons, you can target text inputs specifically with

    input[type="text"]
    
    0 讨论(0)
  • 2021-01-31 18:56

    You can just add: padding-right: 0; to the textarea selector and it will line up your scrollbar with the side of the element. :)

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