Issue
I am noob here, learning new things. I am trying to make this center form.
This is what I have tried so far :-
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<style>
.container {
height: 100%;
width: 50%
}
.center-block {
margin: auto;
display: block;
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center fst-italic mt-5">CARD NUMBER CHECKER</h1>
<br>
<br>
<div class="inpCont ">
<div class="row g-3 align-items-center">
<div class="col-auto">
<label class="col-form-label text-center">Input Number</label>
</div>
<div class="col-auto">
<input type="text" class="form-control text-center">
</div>
</div>
</div>
<br>
<div class="d-grid gap-2 col-3 mx-auto">
<button class="btn btn-warning" type="button">Submit</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</body>
</html>
Getting something like this right now, with above code
Want exactly like this :-
Atleast Help me center the input box like an image :)
Solution
Bootstrap 5 has classes that can do all of that for you as opposed to adding other CSS:
https://getbootstrap.com/docs/5.0/utilities/flex/
https://getbootstrap.com/docs/5.0/utilities/spacing/
d-flex
sets the container div to a flexbox, flex-column
sets the direction of the box to a column, align-items-center
aligns everything to the horizontal center, and gap-4
gives you some spacing between all elements. You could even remove the input container all together unless you specifically need it for something else.
h1 {
font-family: Georgia, "Times New Roman", Times, serif;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<div class="d-flex flex-column align-items-center gap-4">
<h1 class="text-center mt-5">CARD NUMBER CHECKER</h1>
<div class="row g-3 align-items-center">
<div class="col-auto">
<label class="col-form-label text-center">Input Number</label>
</div>
<div class="col-auto">
<input type="text" class="form-control text-center">
</div>
</div>
<div class="d-grid gap-2 col-3 mx-auto">
<button class="btn btn-warning" type="button">Submit</button>
</div>
</div>
</body>
</html>
Answered By - AStombaugh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.