Issue
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
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>
Answered By – yousoumar
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0