Warm tip: This article is reproduced from stackoverflow.com, please click
css html user-interface twitter-bootstrap

How can I append 2 button to textarea and align them automatically using bootstrap?

发布于 2020-03-27 10:16:37

I want to add 2 button to the right of textarea,one on top and another under it using bootstrap and align them automatically,is it possible to achive with just using orignal bootstrap class?

with https://getbootstrap.com/docs/4.3/components/input-group/ showed example I can code some like :

<div class="input-group-prepend">
    <span class="input-group-text">With textarea</span>
</div>
<textarea class="form-control" aria-label="With textarea"></textarea>
    <div class="input-group-append" id="button-addon4">
        <button class="btn btn-outline-secondary" type="button">Button</button>
        <button class="btn btn-outline-secondary" type="button">Button</button>
    </div>
</div>

which showed: ss But I want it like: ss and align them automatically (and maybe adjust their size by the size of textarea auto?) so is there a way could done it by just using orignal bootstrap class?

Questioner
Jason117
Viewed
137
Nandita Sharma 2019-07-03 19:26

Use d-flex flex-column on #button-addon4 div and also apply flex: 1 0 auto; on the buttons to expand button's height when the textarea's height is increased.

.input-group-text,
.btn-outline-secondary {
  flex: 1 0 auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="container">
  <div class="input-group-prepend">
    <span class="input-group-text">With textarea</span>
  </div>
  <div class="d-flex">
    <textarea class="form-control" aria-label="With textarea"></textarea>
    <div class="d-flex flex-column" id="button-addon4">
      <button class="btn btn-outline-secondary" type="button">Button</button>
      <button class="btn btn-outline-secondary" type="button">Button</button>
    </div>
  </div>


  <div class="input-group mt-4">
    <textarea class="form-control" aria-label="With textarea"></textarea>
    <div class="input-group-append d-flex flex-column">
      <span class="input-group-text">Button 1</span>
      <span class="input-group-text">Button 2</span>
    </div>
  </div>
</div>