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

Time:06-13

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  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 >
      <input type="submit" value="Submit" name="selectedvalue"  align="right">
    </div>
  </form>
</body>
</html>

CodePudding user response:

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" >
    <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 >
        <input type="submit" value="Submit" name="selectedvalue"  align="right">
      </div>
  </form>
</body>
</html>

  • Related