html - 自动调整文本区域旁边文本的宽度?

标签 html css autosize

我想为用户输入显示一个文本区域,并在它的右侧显示一个说明文本。我希望说明文本使用文本区域旁边的可用宽度,并且我希望它的行根据需要换行,但保持在文本区域的右侧。我希望文本与文本区域顶部对齐。

<div class="container">
  <textarea rows="10" cols="30">Text data</textarea>
  <div class="instructions">
    Please follow these instructions when entering data 
    into the textarea to the left. Blah blah blah..
  </div>
</div>

我如何使用适用于大多数现代浏览器的 HTML5 和 CSS3 实现这一点?

编辑:也许我应该补充一点,我尝试将 textareadiv.instructions 设置为 display: inline-block,但事实并非如此足够了,因为 div.instructions 没有换行。相反,当 textarea 右侧的可用空间太小而无法将说明文本放在一行中时,整个 div.instructions 会滑到 下方文本区域

JSFiddle:https://jsfiddle.net/0bh0mLej/

最佳答案

你可以使用display: table-cell:

<div class="container">
  <div style="display: table-cell">
      <textarea rows="10" cols="30">Text data</textarea>
  </div>
  <div style="display: table-cell; vertical-align: top;">
    Please follow these instructions when entering data 
    into the textarea to the left. Blah blah blah..
  </div>
</div>

关于html - 自动调整文本区域旁边文本的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32265999/

相关文章:

ios - 自动调整 View 大小会增加横向模式下 View 之间的距离

css - 这种自动拉伸(stretch)的场景能否在索引XHTML/CSS中实现?

javascript - 创建复杂的表结构

javascript - 滚动部分时是否有用于自定义转换的整页 js 代码?

html - Bulma CSS - 输入字段和选择元素之间的宽度不一致

ruby-on-rails - 在大型 Rails 元素中管理 CSS

c# - 窗口自动调整大小不起作用

html - 有没有机会使用 CSS/HTML 技巧创建图像,比如 CD Trey with CD Rings

javascript - 从js脚本发送数据到当前的php文件

python - 无法使用 ../返回文件树