Search code examples
htmlcsstextareashadow

Cannot set textarea inner border shadow (still need help)


EDIT: Hoping someone will see this one. I'm stuck and have tried several things since posting it, but to no avail.

I'm trying to display a textarea with a border shadow. For some weird reason, while other regular text input boxes on the page are displaying their inner shadows correctly, textareas do not show any inner shadows at all. How do I force textarea to display the shadow as the other input boxes do?

Here is the HTML I'm using.

<textarea class="form-control upladfieldset notes-field" rows="6"></textarea>

Note that when I remove the entire class attribute of

class="form-control upladfieldset notes-field"

the inner border shadow appears, but then of course all my other styling is gone which is not ideal. So I also tried commenting out individual lines of CSS in those classes to see which line is causing a conflict, but the only thing that gets the inner shadow to appear is if I remove the class attribute declaration altogether.

Here is the CSS I'm using.

.form-control
{
    color: #34495e;
    border-color: transparent;
    border: none !important;
    border-bottom-width: 0px;
    border-bottom: none;
    font-size: 16px;
    line-height: 1.467;
    padding: 8px 12px 8px 66px;
    height: 54px;
    -webkit-appearance: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    -webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
    transition: border .25s linear, color .25s linear, background-color .25s linear;
    background-repeat: no-repeat;
}

.uploadfieldset
{
    border: none;
    border-radius: 0;
    padding: 0;
}

.notes-field
{
    background-clip: border-box;
    background-size: contain
    border-radius:0;
    height: 54px;
    width: 680px;
    font-family: 'gotham_htfbook';
    font-size: 18px;
    color: #000000;
    text-transform: none;
    text-align: left;
    font-weight: normal;
}

input[type=text], textarea
{
    -webkit-appearance: none;
    -webkit-transition: all 0.30s ease-in-out;
    -moz-transition: all 0.30s ease-in-out;
    -ms-transition: all 0.30s ease-in-out;
    -o-transition: all 0.30s ease-in-out;
    box-shadow: 0 0 5px rgba(89, 89, 89, 1);
    padding: 3px 0px 3px 3px;
    margin: 5px 1px 3px 0px;
    border: 1px solid rgba(204, 204, 204, 1);
}

input[type=text]:focus, textarea:focus
{
    box-shadow: 0 0 5px rgba(89, 89, 89, 1);
    padding: 3px 0px 3px 3px;
    margin: 5px 1px 3px 0px;
    border: 1px solid rgba(204, 204, 204, 1);
}

Solution

  • Well... you have a lot of things going on here, but I believe I may have achieved your desired result (I'm not 100% sure I understand what you want, but I'm operating under the assumption that you want your textarea to include a border and box-shadow identical to your input field). I believe the main problem here is mainly to do with hierarchy fundamentals. Because of that, I feel like there's a few things that should be said before we tackle our actual code here. In principle, you should have more general rules towards the top of your stylesheet and more specific ones as you go down. Resets (the raw elements like textarea, input, etc.) should be at the top--or at the very least, above the classes you wish to apply to those elements.

    Also, I strongly encourage you to avoid using !imporant. If you find yourself needing to use !imporant, that generally means that your real problem lies elsewhere. It shows that you're now trying to work against the natural flow of CSS to force it to cover up something else. And what happens when you need to override that rule? You're going to have to write an even more specific rule, and the whole thing can very quickly turn into a mess.

    So with that said, for the sake of familiarity, I have taken your code and commented out the problematic lines and have included explanations as to why they're preventing you from achieving what you want.

    .form-control
    {
        color: #34495e;
        /*border-color: transparent;       Because of this, even if you had a border, you wouldn't be able to see it (assuming you didn't override it later). */
        /*border: none !important;         1. Use of !important. 2. Your border isn't showing because this is explicitly telling it not to. */
        /*border-bottom-width: 0px;        You're getting rid of the bottom border. */
        /*border-bottom: none;             You're getting rid of the bottom border. */
        font-size: 16px;
        line-height: 1.467;
        padding: 8px 12px 8px 66px;
        height: 54px;
        -webkit-appearance: none;
        /*-webkit-box-shadow: none;        Explicitly telling it not to have a box-shadow */
        /* box-shadow: none;               Explicitly telling it not to have a box-shadow */
        -webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
        transition: border .25s linear, color .25s linear, background-color .25s linear;
        background-repeat: no-repeat;
    }
    
    .uploadfieldset
    {
        /*border: none;                    Explicitly telling it not to have a border */
        border-radius: 0;
        padding: 0;
    }
    
    .notes-field
    {
        background-clip: border-box;
        background-size: contain
        border-radius:0;
        height: 54px;
        width: 680px;
        font-family: 'gotham_htfbook';
        font-size: 18px;
        color: #000000;
        text-transform: none;
        text-align: left;
        font-weight: normal;
    }
    
    input[type=text], textarea
    {
        -webkit-appearance: none;
        -webkit-transition: all 0.30s ease-in-out;
        -moz-transition: all 0.30s ease-in-out;
        -ms-transition: all 0.30s ease-in-out;
        -o-transition: all 0.30s ease-in-out;
        box-shadow: 0 0 5px rgba(89, 89, 89, 1);
        padding: 3px 0px 3px 3px;
        margin: 5px 1px 3px 0px;
        border: 1px solid rgba(204, 204, 204, 1);
    }
    
    input[type=text]:focus, textarea:focus
    {
        box-shadow: 0 0 5px rgba(89, 89, 89, 1);
        padding: 3px 0px 3px 3px;
        margin: 5px 1px 3px 0px;
        border: 1px solid rgba(204, 204, 204, 1);
    }
    

    However, here, I have re-ordered some of your lines in order to implement some of the principles I mentioned earlier. Because I don't know what you're going to use this for, I tried not to tamper with things when it was not directly necessary. I also did not delete any of your lines. Instead, I simply commented them out so you can follow along and see what I actually did. You can delete them yourself if you so wish to.

    input[type=text], textarea                       /* Moved to the top of your stylesheet */
    {
        -webkit-appearance: none;
        -webkit-transition: all 0.30s ease-in-out;
        -moz-transition: all 0.30s ease-in-out;
        -ms-transition: all 0.30s ease-in-out;
        -o-transition: all 0.30s ease-in-out;
        box-shadow: 0 0 5px rgba(89, 89, 89, 1);     /* Reminder: You're defining your box-shadow here */
        padding: 3px 0px 3px 3px;
        margin: 5px 1px 3px 0px;
        border: 1px solid rgba(204, 204, 204, 1);    /* Reminder: You're defining your border here */
    }
    
    input[type=text]:focus, textarea:focus           /* Moved to the top of your stylesheet */
    {    
        /*box-shadow: 0 0 5px rgba(89, 89, 89, 1);      No need to redefine in :focus. It will be in inherited. */
        padding: 3px 0px 3px 3px;                    /* See: padding in .uploadfieldset (below) */
        /*margin: 5px 1px 3px 0px;                      No need to redefine in :focus. It will be in inherited. */
        /*border: 1px solid rgba(204, 204, 204, 1);     No need to redefine in :focus. It will be in inherited. */
    }
    
    
    .form-control
    {
        color: #34495e;
        /*border-color: transparent;    This will hide previously defined border. */
        /*border: none !important;      This will override previously defined border. Remember, don't use !important.*/
        /*border-bottom-width: 0px;     This will get rid of the bottom border. */
        /*border-bottom: none;          This will get rid of the bottom border. */
        font-size: 16px;
        line-height: 1.467;
        padding: 8px 12px 8px 66px;
        height: 54px;
        -webkit-appearance: none;
        /*-webkit-box-shadow: none;     This will override previously defined box-shadows. */
        /* box-shadow: none;            This will override previously defined box-shadows. */
        -webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
        transition: border .25s linear, color .25s linear, background-color .25s linear;
        background-repeat: no-repeat;
    }
    
    .uploadfieldset
    {
        /*border: none;      This will override previously defined borders. */
        border-radius: 0;
        padding: 0;       /* This tells your text field to not have any padding. However, when you click on your textarea, the padding set by textarea:focus will override THIS. */
    }
    
    .notes-field
    {
        background-clip: border-box;
        background-size: contain
        border-radius:0;
        height: 54px;
        width: 680px;
        font-family: 'gotham_htfbook';
        font-size: 18px;
        color: #000000;
        text-transform: none;
        text-align: left;
        font-weight: normal;
    }
    

    If you try either of those with this markup:

    <textarea class="form-control upladfieldset notes-field" rows="6"></textarea>
    <input type="text">
    

    You can see that both fields are stylized likewise. I hope this helps.