Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get a submit button with select aligned in a row in a form using bootstrap?

I’m trying to get a submit button aligned right in a form with Bootstrap. I’ve tried float-right, text-right and align="right" but none of them works. Here is the code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
      <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0-beta1/css/bootstrap.min.css" rel="stylesheet">
      <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0-beta1/js/bootstrap.min.js"></script>
      <title>Document</title>
    </head>
    <body>
  <form role="form" id="sendAddress" action=/sendAddress method="post">
    <select class="form-select" aria-label="Default select example" name="role">
      <option value="r">随机</option>
      <option value="w">战士</option>
      <option value="t">坦克</option>
      <option value="a">刺客</option>
    </select>
    <div class="float-right text-right">
      <input type="submit" value="Submit" name="selectedvalue" class="btn btn-primary" align="right">
    </div>
  </form>
    </body>
    </html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could add d-flex class from Bootstrap on <form>, I think you will get what you want, like so:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0-beta1/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0-beta1/js/bootstrap.min.js"></script>
  <title>Document</title>
</head>
<body>
  <form role="form" id="sendAddress" action=/sendAddress method="post" class="d-flex">
    <select class="form-select" aria-label="Default select example" name="role">
      <option value="r">r</option>
      <option value="w">w</option>
      <option value="t">t</option>
      <option value="a">a</option>
    </select>
     <div class="text-right ">
        <input type="submit" value="Submit" name="selectedvalue" class="btn btn-primary ms-3" align="right">
      </div>
  </form>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading