How to force Firefox to render textarea padding the same as in a div?

后端 未结 5 1551
时光说笑
时光说笑 2020-12-10 08:07

I\'m attempting to provide a consistent width per line in pixels inside of a textarea across IE8, Firefox and Safari, so that text content wraps lines as predictably and con

5条回答
  •  感情败类
    2020-12-10 08:44

    Wow, I don't know the answer yet but I did try some stuff, and it appears as though a textarea, when you apply borders, margins and padding to it, doesn't change its width but puts the borders etc. on the inside. Try this:

    .testbox {
        padding: 10;
        margin: 10;
        border: 5px solid black;
        background: red;
        width: 40px;
        height: 40px;
        font-size: 12px;
        line-height: 16px;
    }
    

    You could work around this by using something like this:

    css:

    .testbox {
        padding: 0;
        margin: 0;
        border: 0;
        background: red;
        width: 40px;
        height: 40px;
        font-size: 12px;
        line-height: 16px;
    }
    
    .testarea {
        padding: 0;
        margin: 0 -1px;
        border: 0;
        background: red;
        width: 100%;
        height: 100%;
        font-size: 12px;
        line-height: 16px;
    }
    

    This also seems to work in IE, except for the -1px, which throws the layout off (by one).

提交回复
热议问题