HTML input element wider than Containing Div

前端 未结 7 1293
一个人的身影
一个人的身影 2020-12-13 23:43

I have an html element that is contained within a div. Height are dictated by the outer div and the height and width of the input control are 100%. At the most basic level,

7条回答
  •  不知归路
    2020-12-14 00:02

    I know this post is fairly old, but it's a common problem and no one posted any good answers...

    The following HTML code looks fine. But when I add the doctype, the problem appear

    div.field_container
    {
        height: 25px;
        width: 150px;
        border: 1px solid red;
    }
    div.field_container input
    {
        height: 100%;
        width: 100%;
    }
    

    To fix the width / height problem, you can add padding to your field_container, but that will make the container bigger.

    div.field_container
    {
        height: 25px;
        width: 150px;
        padding-bottom: 6px;
        padding-right: 4px;
        border: 1px solid red;
    }
    div.field_container input
    {
        height: 100%;
        width: 100%;
    }
    

    If you can't change the container width, you can also use the following trick, but that will still increase the height

    div.field_container
    {
        height: 25px;
        width: 150px;
        padding-bottom: 6px;
        border: 1px solid red;
    }
    div.field_container input
    {
        height: 100%;
        width: 100%;
    }
    

提交回复
热议问题