You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需Bootstrap实现textarea与按钮的行内显示

Fixing Inline Display for Textarea and Button

Hey there! I totally get the frustration when elements don’t line up like you want them to. Let’s get that textarea and button sitting neatly on the same line—here are a couple of solid solutions:

Flexbox is the easiest and most reliable way to align elements in a row these days. Just wrap your textarea and button in a parent container, then apply flexbox styling to it:

HTML

<div class="input-group">
  <textarea placeholder="Enter your text..."></textarea>
  <button type="submit">Submit</button>
</div>

CSS

.input-group {
  display: flex;
  gap: 10px; /* Adds space between the elements */
  align-items: center; /* Vertically centers them */
}

.input-group textarea {
  flex: 1; /* Let the textarea take up remaining space */
  min-height: 40px; /* Adjust as needed */
}

.input-group button {
  padding: 8px 16px; /* Adjust button sizing */
}

Solution 2: Convert Textarea to Inline-Block

By default, <textarea> is a block-level element, which means it takes up the full width of its container. Changing it to inline-block lets it sit next to the button:

CSS

textarea {
  display: inline-block;
  vertical-align: middle; /* Prevents vertical misalignment */
  width: 380px; /* Set a fixed width, or use % */
  min-height: 40px;
}

button {
  vertical-align: middle;
}

Pro Tip

Make sure neither element has a width that’s too large for their parent container—if their combined width exceeds the parent’s width, they’ll wrap to the next line. Double-check any margins or padding that might be adding extra space too!

内容的提问来源于stack exchange,提问作者Pablo DelaNoche

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:32:24