Is there a simple way to make html textarea and input type text equally wide?

前端 未结 12 3089
萌比男神i
萌比男神i 2021-02-18 19:29

Is there a simple way of getting a HTML textarea and an input type=\"text\" to render with (approximately) equal width (in pixels), that works in different browsers?

A C

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-18 20:02

    To answer the first question (although it's been answered to death): A CSS width is what you need.

    But I wanted to answer Gaius's question in the answers. Gaius, you're problem is that you are setting the width's in em's. This is a good think to do but you need to remember that em's are based on font size. By default an input area and a textarea have different font faces & sizes. So when you are setting the width to 35em, the input area is using the width of it's font and the textarea is using the width of it's font. The text area default font is smaller, therefore the text box is smaller. Either set the width in pixels or points, or ensure that input boxes and textareas have the same font face & size:

    .mywidth {
      width: 35em;
      font-family: Verdana;
      font-size: 1em;
    }

    Hope that helps.

提交回复
热议问题