How can I make a TextArea 100% width without overflowing when padding is present in CSS?

前端 未结 15 2194
失恋的感觉
失恋的感觉 2020-11-29 14:44

I have the following CSS and HTML snippet being rendered.

<
15条回答
  •  不知归路
    2020-11-29 15:09

    I came across another solution here that is so simple: add padding-right to the textarea's container. This keeps the margin, border, and padding on the textarea, which avoids the problem that Beck pointed out about the focus highlight that chrome and safari put around the textarea.

    The container's padding-right should be the sum of the effective margin, border, and padding on both sides of the textarea, plus any padding you may otherwise want for the container. So, for the case in the original question:

    textarea{
        border:1px solid #999999;
        width:100%;
        margin:5px 0;
        padding:3px;
    }
    .textareacontainer{
        padding-right: 8px; /* 1 + 3 + 3 + 1 */
    }
    

提交回复
热议问题