Issue centering form inside body | HTML - html

I currently have this as part of my script, the header and 2 paragraphs are being centered properly, but container and button are off to the left side. I have tried using <center> </center> but I don't know where to properly apply them for the form and button to be centered.
Screenshot of what needs to be centered:
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<div class="jumbotron text-center">
<h1>Header Text</h1>
<p>Paragraph</p>
<p>Paragraph 2</p>
</div>
<div class="container">
<form action="excel-script.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="file" name="excelDoc" id="excelDoc" class="form-control" />
</div>
</div>
<div class="col-md-4">
<input type="submit" name="uploadBtn" id="uploadBtn" value="Button" class="btn btn-success" />
</div>
</div>
</form>
</div>

Add 'text-center' class to the row and edit the 'col' classes to have 12 as a sum
<div class="container" >
<form action="excel-script.php" method="post" enctype="multipart/form-data">
<div class="row text-center">
<div class="col-md-2"></div>
<div class="col-md-4">
<div class="form-group">
<input type="file" name="excelDoc" id="excelDoc" class="form-control" />
</div>
</div>
<div class="col-md-3">
<input type="submit" name="uploadBtn" id="uploadBtn" value="Button" class="btn btn-success" />
</div>
<div class="col-md-3"></div>
</div>
</form>
</div>

Check out this code:
<div class="text-center">
<h1>Header Text</h1>
<p>Paragraph</p>
<p>Paragraph 2</p>
</div>
<div class="container">
<form action="excel-script.php" method="post" enctype="multipart/form-data">
<div class="row align-items-center justify-content-center">
<div class="col-12 col-md-4">
<div class="custom-file" id="customFile" lang="es">
<input type="file" class="custom-file-input">
<label class="custom-file-label" for="exampleInputFile">
Choose file...
</label>
</div>
</div>
<div class="col-12 col-md-1">
<input type="submit" name="uploadBtn" id="uploadBtn" value="Button" class="btn btn-success" />
</div>
</div>
</form>
</div>
Hope this helps.

Related

center a container in html using bootstrap

Well this is my code:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="span4 offset4 centered">
<div class="container overflow-hidden">
<div class="col-6">
<div class="p-3 border bg-light">
<form>
<div class="container px-4">
<div className="container">
<h3>Login</h3>
</div>
<div className="container">
<div className="row align-items-center">
<label>Email address</label>
<input type="email" className="form-control" placeholder="Enter email" />
</div>
</div>
<div className="container">
<div className="row align-items-center">
<label>Password</label>
<input type="password" className="form-control" placeholder="Enter password" />
</div>
</div>
<div className="container">
<div className="row align-items-center">
<div className="custom-control custom-checkbox">
<input type="checkbox" className="custom-control-input" id="customCheck1" />
</div>
</div>
</div>
<div className="container">
<div className="row align-items-center">
<button type="submit" class="btn btn-outline-warning">Login</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
the problem is that I'd like to center it vertical and horizontal. I thoutght this is possible with the <div class="span4 offset4 centered"> but it wasn't. Anyone know an answer?
I also tried to use my own styling but it didn't work too
Why are you not using bootstraps classes? I made some changes in your code. check below code
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div style="height: 100vh">
<div class="container h-100">
<div class="row justify-content-center h-100 align-items-center">
<div class="col-md-6">
<div class="p-3 border bg-light">
<h3>Login</h3>
<form action="">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" placeholder="Enter email" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" placeholder="Enter password" id="pwd">
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-outline-warning">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Just add mx-auto and my-auto to the element you want to center within it's parent.
Like this:
<div class="parent">
<div class="container mx-auto my-auto">
<!--Content-->
</div>
</div>
Now .container would be centered vertically and horizontally inside .parent

Getting no space between divs

I am new to webforms and am trying to create a login page with 2 buttons and 2 textboxes. I have placed them between divs however I am getting no spces between them.
Here is what I am getting:
As you can see there is no vertical space between the buttons and textboxes and labels
Here is the code I am using:
<div class="container">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col">
<center>
<img width="150px" src="imgs/generaluser.png" />
</center>
</div>
</div>
<div class="row">
<div class="col">
<center>
<h3>Member Login</h3>
</center>
</div>
</div>
<div class="row">
<div class="col">
<center>
<hr>
</center>
</div>
</div>
<div class="row">
<div class="col">
<label>Member ID</label>
<div class="form-group">
<asp:TextBox CssClass= "form-control" ID="Textbox1" runat="server"
placeholder="Member ID"></asp:TextBox>
</div>
<label>Password</label>
<div class="form-group">
<asp:TextBox CssClass= "form-control" ID="Textbox2" runat="server"
placeholder="Password" TextMode="Password"></asp:TextBox>
</div>
<div class="form-group">
<asp:Button class="btn btn-primary btn-lg col-12" ID="Button1"
runat="server" Text="Login" />
</div>
<div class="form-group">
<input class="btn btn-info btn-lg col-12" id="Button2"
type="button" value="Sign Up" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I am using bootstrap. Should not it give vertical space automatically?
How do I fix this?
You can add margin with bootstrap by adding it to the class
<label class="mt-3">Password</label>
You should be using inputs instead of textboxes
and you should look into wrapping it all in a form
<head>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
</head>
<div class="container">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col">
<center>
<img width="150px" src="imgs/generaluser.png" />
</center>
</div>
</div>
<div class="row">
<div class="col">
<center>
<h3>Member Login</h3>
</center>
</div>
</div>
<div class="row">
<div class="col">
<center>
<hr>
</center>
</div>
</div>
<div class="row">
<div class="col">
<label>Member ID</label>
<div class="form-group">
<input class= "form-control" ID="Textbox1" runat="server"
placeholder="Member ID"></T>
</div>
<label class="mt-3">Password</label>
<div class="form-group">
<input class= "form-control" ID="Textbox2" runat="server"
placeholder="Password" TextMode="Password"></Textarea>
</div>
<div class="form-group mt-2">
<input class="btn btn-primary btn-lg col-12" ID="Button1"
runat="server" Text="Login" value="Login" />
</div>
<div class="form-group mt-2">
<input class="btn btn-info btn-lg col-12" id="Button2"
type="button" value="Sign Up" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
You can either use a margin-top for the button class of use a <br> after the first button container

Incorrect version of form appearance on resize

Issue Details
When I resize the browser, it displays like this...
I am sorry, Can't show the image due to low reputation points.
Further, when I decrease the browser size, it displays like this...
I am sorry, Can't show the image due to low reputation points.
My JS Fiddle is here
Am I missing anything in below code?
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css">
</head>
<body>
<div id="app">
<main class="py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-4">
<div class="card">
<div class="card-header">Login</div>
<div class="card-body">
<form role="form" class="row">
<div class="col-sm-12 col-md-12">
<div class="form-group">
<label for="Email Address" class="control-label">UserName Or EmailAddress</label>
<input type="text" name="Email Address" class="form-control">
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group">
<label for="Password" class="control-label">Password</label>
<input type="password" name="Password" class="form-control">
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group">
<button type="button" class="btn btn-primary" >
Login
</button>
<a class="btn btn-link" title="Forgot Password">Forgot Password</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</body>
</html>

CSS vertically align components within BootsFaces row

I have a BootFaces JSF-generated login form but I can't seem to get the span's to line up vertically in the middle with the input fields.
This is how the login form currently looks:
Here is the HTML that is generated for this particular form:
<html>
<head>
<link rel="stylesheet" href="bsf.css"/>
<link rel="stylesheet" href="core.css"/>
</head>
<body>
<form id="loginForm" name="loginForm" method="post" action="" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="loginForm" value="loginForm" />
<div id="loginForm:j_idt18" class="row">
<div id="loginForm:j_idt19" class="col-md-4"><span class="pull-right">Username:</span></div>
<div id="loginForm:j_idt21" class="col-md-4">
<div id="loginForm:username" class="form-group"><input id="input_loginForm:username" name="input_loginForm:username" type="text" class="form-control bf-no-message" placeholder="Username" /></div>
</div>
<div id="loginForm:j_idt22" class="message col-md-4 ">
<div id="loginForm:j_idt23"></div>
</div>
</div>
<div data-toggle="tooltip" data-placement="auto" data-container="body" title="This password has fancy error messages." id="loginForm:j_idt24" class="row">
<div id="loginForm:j_idt25" class="col-md-4"><span class="pull-right">Password:</span></div>
<div id="loginForm:j_idt27" class="col-md-4">
<div id="loginForm:password" class="form-group"><input id="input_loginForm:password" name="input_loginForm:password" type="password" class="form-control bf-no-message" placeholder="Password" /></div>
</div>
<div id="loginForm:j_idt28" class="message col-md-4 ">
<div id="loginForm:j_idt29"></div>
</div>
</div>
<div id="loginForm:j_idt30" class="row">
<div id="loginForm:j_idt31" class="col-md-2 col-md-offset-4"><button type="submit" id="loginForm:j_idt32" name="loginForm:j_idt32" style="width:100%" class="btn btn-default" style="width:100%">Login</button></div>
<div id="loginForm:j_idt33" class="col-md-2"><button type="submit" id="loginForm:j_idt34" name="loginForm:j_idt34" style="width:100%" class="btn btn-default" style="width:100%">Forgotten password?</button></div>
</div>
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:1" value="-5586558823054575095:3125033607536646469" autocomplete="off" />
</form>
</body>
</html>
And here are the two CSS files belonging to BootFaces:
bsf.css
core.css
Assuming that the height will remain consistent, you can vertically center text by specifying both a height and line-height:
.vertical-center {
height: 100px;
line-height: 100px;
}
Just apply that class to the username and password text fields. The values should reflect the height of the input fields.

Making the design more uniform?

I'm new to Website design with Bootstrap and I just made this simple start here which looks alright but needs some adjustment to be more uniform and pretty.
As you can see here the Jumbotron I've used seems fairly centered but the Well and Search Bar underneath it does not. I would like some help so that I can make it fit better together :)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="header-container">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="jumbotron" style="width: 100%">
<h1>Cool Text</h1>
<p>Catchphrase</p>
</div>
</div>
</div>
</div>
</div>
<div class="search-bar-container">
<div class="well">
<div class="container">
<div class="row">
<div class="col-lg-12">
<form class="navbar-form" role="search">
<div class="input-group" style="width: 100%">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
You're using class="navbar-form" which is meant for use inside a navbar, that's why it won't occupy 100% of the div it's in.
Depending on if you doing anything else inside these container, you currently don't need to use any columns or rows. I've also add some padding to your jumbotron for under 768px becauseyou'' see the text float up to the edge of the div otherwise.
See example Snippet.
#media (max-width: 767px) {
.jumbotron.jumbotronic {
padding-left: 20px;
padding-right: 20px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="well well-sm">
<h3>Without Col/Row</h3>
</div>
<div class="header-container">
<div class="container">
<div class="jumbotron jumbotronic">
<h1>Cool Text</h1>
<p>Catchphrase</p>
</div>
</div>
</div>
<div class="search-bar-container">
<div class="container">
<div class="well">
<form role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
<hr>
<div class="well well-sm">
<h3>With Col/Row</h3>
</div>
<div class="header-container">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="jumbotron jumbotronic">
<h1>Cool Text</h1>
<p>Catchphrase</p>
</div>
</div>
</div>
</div>
</div>
<div class="search-bar-container">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="well">
<form role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
Something like this, container has some predefined width and margin:
<div class="header-container">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="jumbotron" style="width: 100%">
<h1>Cool Text</h1>
<p>Catchphrase</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="search-bar-container">
<div class="well">
<div class="row">
<div class="col-lg-12">
<form class="navbar-form" role="search">
<div class="input-group" style="width: 100%">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
Try this.
#media screen and (max-width: 768px) {
.container .jumbotron, .container-fluid .jumbotron {
padding-right: 19px;
padding-left: 19px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container header-container">
<div class="jumbotron">
<h1>Cool Text</h1>
<p>Catchphrase</p>
</div>
<form class="search-bar-container well" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</form>
</div>
</body>
</html>