textarea label vertical-align: middle

陌路散爱 提交于 2019-12-04 19:04:07

问题


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:

          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx      
          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
          xxxxxxxxxxxxxxxxxxxxxxxxxxxxx    
Synopsis: xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Here's the code I've been trying. TY!

<style>
label textarea{
 vertical-align: middle;
}
</style>

<label>Synopsis: <textarea style="border: none" rows="7" cols="60">$v_Synopsis</textarea></label> 

回答1:


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;

}



回答2:


you can do it like this:

label { display:inline-block; vertical-align:central; }

textarea { display:inline-block; vertical-align:middle; }



回答3:


you forgot : ","

    <style>
label, textarea{
 vertical-align: middle;
}
</style>

<label>Synopsis: </label> <textarea style="border: 1" rows="3" cols="10"></textarea>



回答4:


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 **/
}



回答5:


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┌──────────────┐


来源:https://stackoverflow.com/questions/19522830/textarea-label-vertical-align-middle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!