为文本区域制作一个标签,放在它旁边,但垂直居中对齐

发布于 2024-12-21 14:35:36 字数 339 浏览 3 评论 0原文

请看一下这个小提琴: http://jsfiddle.net/hughbe/QYGcq/

如您所见,标签对于 应该是在 textarea 旁边,但是,我想使标签垂直位于文本区域旁边,或位于文本区域的顶部,而不是像小提琴中那样位于底部。

我尝试将其 css 设置为 vertical-align: middle 但这不起作用。我必须做什么才能使标签在顶部或中间对齐?

谢谢。

Please take a look at this fiddle: http://jsfiddle.net/hughbe/QYGcq/

As you can see, the label for the <textarea id = "FooText"></textarea> is next to the textarea as it should be, however, I would like to make the label vertically next to the textarea, or at the top of the textarea, instead of at the bottom, like it is in that fiddle.

I have tried setting it's css to vertical-align: middle but that didn't work. What must I do to make the label aligned at the top or the middle?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又爬满兰若 2024-12-28 14:35:36

在文本区域上使用 vertical-align: middle http://jsfiddle.net/VxY6m/

因为垂直对齐意味着相对于文本行 - 在本例中为标签。

Use vertical-align: middle on the textarea http://jsfiddle.net/VxY6m/

Because vertical align meant to be relative to text line - label in this case.

猫九 2024-12-28 14:35:36

试试这个:

<style>
    label {
        display: block; 
        float: left; 
        padding-top: 8px
    }
    textarea {
        resize: none; 
        overflow-y: hidden;        
    }
</style>
<label for="FooText">Content:</label>
<textarea id="FooText"></textarea>

我所做的是将标签设为块元素并对其应用顶部填充。
另请参阅fiddle

Try this:

<style>
    label {
        display: block; 
        float: left; 
        padding-top: 8px
    }
    textarea {
        resize: none; 
        overflow-y: hidden;        
    }
</style>
<label for="FooText">Content:</label>
<textarea id="FooText"></textarea>

What I did was make the label a block element and apply a top padding to it.
See the fiddle also.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文