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

前端 未结 12 2777
萌比男神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 19:51
    input[type="text"] { width: 60%; } 
    input[type="email"] { width: 60%; }
    textarea { width: 60%; }
    textarea { height: 40%; }
    
    0 讨论(0)
  • 2021-02-18 19:51

    you can also use the following CSS:

    .mywidth{
    width:100px;
    }
    textarea{
    width:100px;
    }
    

    HTML:

    <input class="mywidth" >
    <textarea></textarea>
    
    0 讨论(0)
  • 2021-02-18 19:55

    These days, if you use bootstrap, simply give your input fields the form-control class. Something like:

    <label for="display-name">Display name</label>
    <input type="text" class="form-control" name="displayname" placeholder="">
    
    <label for="about-me">About me</label>
    <textarea class="form-control" rows="5" id="about-me" name="aboutMe"></textarea>
    
    0 讨论(0)
  • 2021-02-18 19:56

    You should be able to use

    .mywidth {
      width: 100px;   
    }
    <input class="mywidth">
    <br>
    <textarea class="mywidth"></textarea>

    0 讨论(0)
  • 2021-02-18 20:00

    As mentioned in Unequal Html textbox and dropdown width with XHTML 1.0 strict it also depends on your doctype. I have noticed that when using XHTML 1.0 strict, the difference in width does indeed appear.

    0 讨论(0)
  • 2021-02-18 20:01

    Someone else mentioned this, then deleted it. If you want to style all textareas and text inputs the same way without classes, use the following CSS (does not work in IE6):

    input[type=text], textarea { width: 80%; }
    
    0 讨论(0)
提交回复
热议问题