Vertical center align for a button in panel header with Bootstrap - html

I'm working on a Bootstrap 4 HTML page. I put a button in a panel header:
I need to put the button (and the title) in the middle of the panel header. How can I achieve this goal?
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container p-4 ">
<div class="card">
<div class="card-header">
<p class="float-left display-4">Administrator</p>
<a href="#" class="btn btn-primary float-right" style="align-items: center" routerLink="../list" role="button">
<i class="fa fa-arrow-left"></i> Indietro</a>
</div>
<div class="card-body">
<form>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="form-group">
<label for="displayName">Display name:</label>
<input type="displayName" class="form-control" id="displayName">
</div>
<button type="submit" class="btn btn-primary float-right">Salva</button>
</form>
</div>
</div>
</div>
Thanks

Try using display: flex; for your card header which is available in bootstrap and also instead of using float-right you can use ml-auto to move the button to the right (With the use of flex there is no need to use float properties). Hope this code helps
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container p-4 ">
<div class="card">
<div class="card-header d-flex flex-row align-items-center">
<p class="float-left display-4">Administrator</p>
<a href="#" class="btn btn-primary ml-auto" style="align-items: center" routerLink="../list" role="button">
<i class="fa fa-arrow-left"></i> Indietro</a></div>
<div class="card-body">
<form>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="form-group">
<label for="displayName">Display name:</label>
<input type="displayName" class="form-control" id="displayName">
</div>
<button type="submit" class="btn btn-primary float-right">Salva</button>
</form>
</div>
</div>
</div>

Just add display flex to your card-header class, then align-items: center
.card-header {
padding: .75rem 1.25rem;
margin-bottom: 0;
background-color: rgba(0,0,0,.03);
border-bottom: 1px solid rgba(0,0,0,.125);
display: flex;
justify-content: space-between;
align-items: center;
}

Related

Cannot set input and submit form in the middle of container

I want to align a form in the middle of a container. Then set input bar to be as wide as half of that container. Here is my code.
<div id="sub" class="col-6 d-flex justify-content-center">
<div class="d-flex">
<form id="form" action="https://www.freecodecamp.com/email-submit.">
<div class="form-group">
<input id="email" class="form-control text-center" type="email" placeholder="Enter your email">
</div>
<div class="d-flex justify-content-center pt-3">
<input id="submit" class="btn btn-primary" type="submit">
</div>
</form>
</div>
</div>
Can you try to put your code into row?
<div class="container">
<div class="row d-flex justify-content-center">
<div id="sub" class="col-6">
<div class="d-flex">
<form id="form" action="https://www.freecodecamp.com/email submit.">
<div class="form-group">
<input id="email" class="form-control text-center"
type="email" placeholder="Enter your email">
</div>
<div class="d-flex justify-content-center pt-3">
<input id="submit" class="btn btn-primary" type="submit">
</div>
</form>
</div>
</div>
<div>
</div>
This should help.
#sub{
width:100%;
border:1px solid #ccc;
height:400px;
align-items:center;
}
.form-wrapper{
width:50%;
}
input{
width:100%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div id="sub" class="d-flex justify-content-center align-items-center">
<div class="form-wrapper">
<form id="form" action="https://www.freecodecamp.com/email-submit.">
<div class="form-group">
<input id="email" class="form-control text-center" type="email" placeholder="Enter your email">
</div>
<div class="d-flex justify-content-center pt-3">
<input id="submit" class="btn btn-primary" type="submit">
</div>
</form>
</div>
</div>

How to delete the space between these two elements with bootstrap grid

Here is the code of a login form on which I'm working on:
<main>
<div class="container-fluid">
<div class="row d-flex justify-content-center align-items-center">
<div class="col-6">
<h3 class="display-3">Sign In<h3>
<form class="justify-content-md-center">
<div class="col-md-auto">
<input type="text" required placeholder=" Username"
style="font-family:Arial, FontAwesome">
</div>
<div class="col-md-auto">
<input class="margin-25px" type="password" requires
placeholder=" Password"
style="font-family:Arial, FontAwesome">
</div>
<div class="container-fluid row justify-content-md-center">
<div class="col-sm">
<img class="icon" src="images/check-box.svg"
alt="check-box">
</div>
<div class="col-auto">
<p>Forgot your password?</p>
</div>
</div>
<button class="login__button btn btn-primary" type="submit">
LOGIN
</button>
</form>
</div>
</div>
</div>
</main>
I tried to do the layout with bootstrap grid, but can't find how to nest these two object, which are image with the class icon and the paragraph.
how it looks in chrome
You may use the following lines:
#login .container #login-row #login-column #login-box {
margin-top: 120px;
max-width: 600px;
height: 320px;
border: 1px solid #9C9C9C;
background-color: #EAEAEA;
}
#login .container #login-row #login-column #login-box #login-form {
padding: 20px;
}
#login .container #login-row #login-column #login-box #login-form #register-link {
margin-top: -85px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<body>
<div id="login">
<h3 class="text-center text-white pt-5">Login form</h3>
<div class="container">
<div id="login-row" class="row justify-content-center align-items-center">
<div id="login-column" class="col-md-6">
<div id="login-box" class="col-md-12">
<form id="login-form" class="form" action="" method="post">
<h3 class="text-center text-info">Login</h3>
<div class="form-group">
<label for="username" class="text-info">Username:</label><br>
<input type="text" name="username" id="username" class="form-control">
</div>
<div class="form-group">
<label for="password" class="text-info">Password:</label><br>
<input type="text" name="password" id="password" class="form-control">
</div>
<div class="form-group">
<label for="remember-me" class="text-info"><span>Remember me</span> <span><input id="remember-me" name="remember-me" type="checkbox"></span></label><br>
<input type="submit" name="submit" class="btn btn-info btn-md" value="Login">
</div>
<div id="register-link" class="text-right">
Forgot your password ?
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
I already found it in the codepen and I can't remember the author's name to mention here.

Html: Bootstrap form alignment in center

I'm currently working on a simple login system and I have some Front-End difficulties. I'm trying to make a center-based login form with some inputs and a button. So basically right now I was able to make few inputs inside the center, but when I tried adding a button, then I got result like this:
Note: I need the button to be in the center of the form. Also, am I doing the form in the center correctly?
My HTML code:
<div class="container">
<h1 class="page-header text-center apie_m_cga">~ Support Desk ~</h1>
<hr>
<div class="row justify-content-center">
<div class="form-group col-md-3 col-md-offset-7 align-center ">
<br>
<input type="text" id="inputUsername6" placeholder="Username" class="form-control mx-sm-3 text-center">
<br>
<input type="password" id="inputPassword6" placeholder="Password" class="form-control mx-sm-3 text-center">
<br>
<button type="button" class="btn btn-primary btn-lg">Login</button>
</div>
</div>
<br>
</div>
add text-center class to the div that contain form-group class:
<div class="container">
<h1 class="page-header text-center apie_m_cga">~ Support Desk ~</h1>
<hr>
<div class="row justify-content-center ">
<div class="form-group col-md-3 col-md-offset-7 align-center text-center">
<br>
<input type="text" id="inputUsername6" placeholder="Username" class="form-control mx-sm-3 text-center">
<br>
<input type="password" id="inputPassword6" placeholder="Password" class="form-control mx-sm-3 text-center">
<br>
<button type="button" class="btn btn-primary btn-lg">Login</button>
</div>
</div>
<br>
</div>
Just add a text-align: center; to your form-group
.form-group {
text-align: -webkit-center;
text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<h1 class="page-header text-center apie_m_cga">~ Support Desk ~</h1>
<hr>
<div class="row justify-content-center">
<div class="form-group col-md-3 col-md-offset-7">
<br>
<input type="text" id="inputUsername6" placeholder="Username" class="form-control mx-sm-3 text-center">
<br>
<input type="password" id="inputPassword6" placeholder="Password" class="form-control mx-sm-3 text-center">
<br>
<button type="button" class="btn btn-primary btn-lg">Login</button>
</div>
</div>
<br>
</div>
You just need to add .text-center add on parent DIV
<div class="container">
<h1 class="page-header text-center apie_m_cga">~ Support Desk ~</h1>
<hr>
<div class="row justify-content-center">
<div class="form-group col-md-3 col-md-offset-7 align-center text-center">
<br>
<input type="text" id="inputUsername6" placeholder="Username" class="form-control mx-sm-3 text-center">
<br>
<input type="password" id="inputPassword6" placeholder="Password" class="form-control mx-sm-3 text-center">
<br>
<button type="button" class=" btn-primary btn-lg">Login</button>
</div>
</div>
<br>
</div>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
I'll suggest you make the button the same length with the input fields, it'll make the form look better.
Try this:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="container">
<h1 class="page-header text-center apie_m_cga">~ Support Desk ~</h1>
<hr>
<div class="row justify-content-center">
<div class="form-group col-md-3 col-md-offset-7 align-center ">
<br>
<input type="text" id="inputUsername6" placeholder="Username" class="form-control text-center">
<br>
<input type="password" id="inputPassword6" placeholder="Password" class="form-control col-12 text-center">
<br>
<button type="button" class="btn col-12 btn-primary">Login</button>
</div>
</div>
<br>
</div>
I think the class of your button "btn-lg" is influenced in position. Basically there is no any special errors on your script except for it.
Please remove it in class and try again

Bootstrap4 move login form towards to the center

I have the following login page:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Log in </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body>
<header>
<nav class="navbar navbar-dark bg-primary">
<a class="navbar-brand" href="/">
<img src="https://loremimage.com/default/32/32/1" />
Διαχείρηση Μελών ΕΛΛΑΚ Κύπρου
</a>
</nav>
</header>
<div class="container-fluid d-flex align-items-center justify-content-center">
<div class="row bg-light border border-primary">
<div class="col mt-5 col-xs-12 col-md-12 col-lg-12">
<h1 style="text-align:center">Log in</h1>
<form action="/login_check" method="post">
<div class="form-group">
<input type="text" class="form-control" id="username" name="_username" value="" placeholder="Username" required="required" />
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group">
<input type="password" class="form-control" id="password" name="_password" placeholder="Password" required="required" />
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group">
<div class="form-check">
<input type="checkbox" id="remember_me" name="_remember_me" class="form-check-input" />
<label class="form-check-label" for="remember_me" >Remember me</label>
</div>
</div>
<div class="form-row">
<div class="col">
<input type="submit" class="btn btn-primary btn-block" id="_submit" name="_submit" value="Log in" />
</div>
<div class="col">
<a class="btn btn-warning btn-block" href="/resetting/request">I forgot my password</a>
</div>
</div>
</form>
</div>
<div class="col col-xs-12 col-md-12 col-lg-12 mt-1 mb-5">
<a class="btn btn-primary btn-block" href="/register/">I do not have an account</a>
</div>
</div>
</div>
</body>
</html>
And my problem is that the login form is not too center as I want to as this image shows.
What I want to do is to display like that:
So do you know how to move the whole login form towards the center I tried the bootstrap's d-flex align-items-center justify-content-center class combination and somehow it does center but the flexbox is as height as my login form.
So my guess is on how I can make the flexbox take over the whole remaining height. DO you know how to do that?
You should give height to your container-fluid div in view-port
height: calc(100vh - 60px);
60px is your header height (View in full-screen mode of snippet)
.custom {
height: calc(100vh - 60px);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Log in </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body>
<header>
<nav class="navbar navbar-dark bg-primary">
<a class="navbar-brand" href="/">
<img src="https://loremimage.com/default/32/32/1" />
Διαχείρηση Μελών ΕΛΛΑΚ Κύπρου
</a>
</nav>
</header>
<div class="custom container-fluid d-flex align-items-center justify-content-center">
<div class="row bg-light border border-primary">
<div class="col mt-5 col-xs-12 col-md-12 col-lg-12">
<h1 style="text-align:center">Log in</h1>
<form action="/login_check" method="post">
<div class="form-group">
<input type="text" class="form-control" id="username" name="_username" value="" placeholder="Username" required="required" />
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group">
<input type="password" class="form-control" id="password" name="_password" placeholder="Password" required="required" />
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group">
<div class="form-check">
<input type="checkbox" id="remember_me" name="_remember_me" class="form-check-input" />
<label class="form-check-label" for="remember_me" >Remember me</label>
</div>
</div>
<div class="form-row">
<div class="col">
<input type="submit" class="btn btn-primary btn-block" id="_submit" name="_submit" value="Log in" />
</div>
<div class="col">
<a class="btn btn-warning btn-block" href="/resetting/request">I forgot my password</a>
</div>
</div>
</form>
</div>
<div class="col col-xs-12 col-md-12 col-lg-12 mt-1 mb-5">
<a class="btn btn-primary btn-block" href="/register/">I do not have an account</a>
</div>
</div>
</div>
</body>
</html>

How to center a form inside a Bootstrap 4 jumbotron [duplicate]

This question already has an answer here:
bootstrap 4: center inline form inside a jumbotron
(1 answer)
Closed 5 years ago.
<div class="jumbotron text-center" id="jumbotron">
<h1 class="display-3">Lorem Ipsum</h1>
<p class="lead">Lorem ipsum</p>
<hr class="my-y-2">
<p>################</p>
<form class="form-inline">
<label class="sr-only" for="email">Email</label>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text">#</div>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
</div>
<button type="submit" class="btn btn-primary mb-2">Sign Up</button>
</form>
</div>
I'm trying to have this form inside a jumbotron and be at the center of it but I can't seem to make it work.
The Bootstrap 4 class you need in this case is justify-content-center.
Here's the working code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="jumbotron text-center" id="jumbotron">
<h1 class="display-3">Lorem Ipsum</h1>
<p class="lead">Lorem ipsum</p>
<hr class="my-y-2">
<p>################</p>
<form class="form-inline justify-content-center">
<label class="sr-only" for="email">Email</label>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text">#</div>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
</div>
<button type="submit" class="btn btn-primary mb-2">Sign Up</button>
</form>
</div>
You haven't posted any CSS so it's hard to understand where you are going wrong. But centering your form could be achieved wrapping your form in a
Example: JSFiddle.net
#form-align
{
display: block;
text-align: center;
}
form
{
display: inline-block;
margin-left: auto;
margin-right: auto;
text-align: left;
}