textarea label vertical-align: middle

前端 未结 5 1503
甜味超标
甜味超标 2021-02-14 02:45

I\'m trying to align the label for this text area in the middle of the text box, but it just isn\'t working. The output looks something like this:

          xxxx         


        
相关标签:
5条回答
  • 2021-02-14 03:24

    This will always work and you have the flexibility of placing the label at either; top, middle or bottom

    HTML:

    <div id="mydiv">
        <label for="mytextarea">My Label</label>
        <textarea name="mytextarea"></textarea>
    </div>
    

    CSS:

    #mydiv{
        display: table-cell;
    }
    
    label, textarea{
        display: inline-block;
        vertical-align: middle; /** Can be switched to 'top' if you so wish **/
    }
    
    0 讨论(0)
  • 2021-02-14 03:26

    This worked for me. First the textarea is floated right, then the word "address" appears before it. It's in reverse order, but displays correctly

    <p>
    <span style="float:right;"><textarea rows="3" cols="32" name="Add"></textarea></span>
    <span style="float:right;">Address</span>
    </p>
    

    To show:

    Address┌──────────────┐
    
    0 讨论(0)
  • 2021-02-14 03:29

    you forgot : ","

        <style>
    label, textarea{
     vertical-align: middle;
    }
    </style>
    
    <label>Synopsis: </label> <textarea style="border: 1" rows="3" cols="10"></textarea>
    
    0 讨论(0)
  • 2021-02-14 03:35

    you can do it like this:

    label { display:inline-block; vertical-align:central; }
    
    textarea { display:inline-block; vertical-align:middle; }
    
    0 讨论(0)
  • 2021-02-14 03:40

    CODEPEN DEMO

    HTML

     <div>
      <label for="textarea">Textarea:</label>
      <textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
    </div>
    

    CSS

    label,
    textarea{
      display:inline-block;
      vertical-align:middle;
    
    }
    
    0 讨论(0)
提交回复
热议问题