I have several forms on a webpage (utilizing Bootstrap 4) and all of them have some content overflow. I can't figure out how to fix it and make the width to fit the form content. Here is a screenshot of one of the simpler forms. This is another screenshot of the other forms in case it helps. Below is some of my code.
page.html
<div class="admin_section">
<h3>Removals</h3>
<div class="admin_section_content container">
<form method="post">
<div class="form-group row">
<label for="deleteName" class="col-sm-2 col-form-label">Remove a Menu Item</label>
<div class="col-sm-2">
<input type="text" name="remove_item_name" pattern="^[a-zA-ZÀ-ÿ-' ]+$" maxlength="25"
class="form-control" id="deleteName" placeholder="Food Item Name" required>
</div>
</div>
<div class="form-group row">
<label for="removeItem" class="col-sm-2 col-form-label"></label>
<div class="col-sm-2 text-right">
<button type="submit" class="btn btn-danger" id="removeItem" name="remove_item_button"
value="clicked">Remove Item</button>
</div>
</div>
</form>
<br><br>
<form method="post">
<div class="form-group row">
<label for="deleteReceipt" class="col-sm-2 col-form-label">Refund a Receipt</label>
<div class="col-sm-2">
<input type="text" name="remove_receipt_number" pattern="^\d{10}$" minlength="10" maxlength="10"
class="form-control" id="deleteReceipt" placeholder="Receipt Number" required>
</div>
</div>
<div class="form-group row">
<label for="removeReceipt" class="col-sm-2 col-form-label"></label>
<div class="col-sm-2 text-right">
<button type="submit" class="btn btn-danger" id="removeReceipt" name="remove_receipt_button"
value="clicked">Refund Receipt</button>
</div>
</div>
</form>
</div>
</div>
general.css
.admin_section{
margin-bottom: 1.5rem;
margin-left: 35%;
margin-right: auto;
}
.admin_section_content{
font-family: 'Segoe UI', 'Open Sans', 'Helvetica Neue', sans-serif;
margin-left: 2rem;
}
select{
border-color: var(--bootstrap-grey);
border-radius: 5px;
}
form{
background-color: var(--form-grey);
border-radius: 5px;
padding: 15px;
}
body{
overflow-x: hidden;
}
Thanks for the extra information Yariel. See what happens if you put the form inside a column.
<div class="col-sm-12 col-md-6">
<form method="post">
<div class="form-group row">
<label for="deleteName" class="col-sm-2 col-form-label">Remove a Menu Item</label>
<div class="col-sm-2">
<input type="text" name="remove_item_name" pattern="^[a-zA-ZÀ-ÿ-' ]+$" maxlength="25"
class="form-control" id="deleteName" placeholder="Food Item Name" required>
</div>
</div>
<div class="form-group row">
<label for="removeItem" class="col-sm-2 col-form-label"></label>
<div class="col-sm-2 text-right">
<button type="submit" class="btn btn-danger" id="removeItem" name="remove_item_button"
value="clicked">Remove Item</button>
</div>
</div>
</form>
</div>
```
Related
I have created an contact form, i tried forms but bootstrap but unable to move it to center of the screen. Can you please help me to move this and arrange a box around the forms.Which i could not do. I am trying this in angular 8
<div class="container">
<h2 >Contact Form</h2>
<div class="container">
<form [formGroup]="profileForm"(ngSubmit)="onSubmit()">
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Your Name:</label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="yourname" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Email: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Items:</label>
<div class="col-sm-5">
<select id="Item" class="form-control" formControlName="item">
<option *ngFor="let c of item" [ngValue]="c">{{ c }}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Name: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="name">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
Remarks:</label>
<div class="col-sm-5">
<textarea class="form-control" type="text" formControlName="remarks" rows="3">
</textarea>
</div>
</div>
<div class="dialog">
<button type="submit" color=#C93C6A class="btn-block" [disabled]="!profileForm.valid">Submit</button>
</div>
</form>
</div>
</div>
CSS below:
.container {
display: block;
border: 2px black;
border-radius: 4px;
box-sizing: border-box 1px black;
}
you can do something like this, the code you shared has limited contents. I tried to fix that only.
use justify-content: center;
align-items: center;
this should fix your issue.
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
}
<div class="container">
<h2>Contact Form</h2>
<div class="container">
<form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Your Name:</label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="yourname">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Email: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Items:</label>
<div class="col-sm-5">
<select id="Item" class="form-control" formControlName="item">
<option *ngFor="let c of item" [ngValue]="c">{{ c }}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Name: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="name">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
Remarks:</label>
<div class="col-sm-5">
<textarea class="form-control" type="text" formControlName="remarks" rows="3">
</textarea>
</div>
</div>
<div class="dialog">
<button type="submit" color=#C93C6A class="btn-block" [disabled]="!profileForm.valid">Submit</button>
</div>
</form>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h2>Contact Form</h2>
</div>
<div class="card-body d-flex justify-content-center">
<form class="w-75" [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<div class="form-group row">
<label class="col-2 col-form-label"> Your Name:</label>
<div class="col">
<input type="text" class="form-control" formControlName="yourname">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Email: </label>
<div class="col">
<input type="text" class="form-control" formControlName="email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Items:</label>
<div class="col">
<select id="Item" class="form-control" formControlName="item">
<option *ngFor="let c of item" [ngValue]="c">{{ c }}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Name: </label>
<div class="col">
<input type="text" class="form-control" formControlName="name">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
Remarks:</label>
<div class="col">
<textarea class="form-control" type="text" formControlName="remarks"
rows="3"></textarea>
</div>
</div>
<div class="dialog">
<button type="submit" color=#C93C6A class="btn-block"
[disabled]="!profileForm.valid">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
Your code is correct and only needs a slight change. You said that you were using bootstrap so I have tried to use the classes from bootstrap to showcase how it will look by using it in the css here. But this will work if you only copy the html contents. Let me know if you need any further help.
.container {
width: 300px;
border: 2px solid black;
border-radius: 4px;
padding: 10px;
}
.d-flex {
display: flex;
}
.flex-column {
flex-direction: column;
}
.text-center {
text-align: center;
}
.justify-content-center {
justify-content: center;
}
.align-self-center {
align-self: center;
}
<div class="d-flex flex-column">
<div class="container align-self-center">
<h2 class="text-center">Contact Form</h2>
<form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Your Name:</label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="yourname">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Email: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Items:</label>
<div class="col-sm-5">
<select id="Item" class="form-control" formControlName="item">
<option *ngFor="let c of item" [ngValue]="c">{{ c }}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Name: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="name">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
Remarks:</label>
<div class="col-sm-5">
<textarea class="form-control" type="text" formControlName="remarks" rows="3">
</textarea>
</div>
</div>
<div class="dialog text-center">
<button type="submit" color=#C93C6A class="btn-block" [disabled]="!profileForm.valid">Submit</button>
</div>
</form>
</div>
</div>
One more way to achieve this design using display:table
Please review my code carefully, And let me know if you have any query.
Hope it will help you. :)
.container {
display: table;
border: 2px black;
border-radius: 4px;
box-sizing: border-box 1px black;
height: 100%;
vertical-align: middle;
margin: 0 auto;
}
.container form {
display: table-cell;
vertical-align: middle;
}
<div class="container">
<div class="container">
<form [formGroup]="profileForm"(ngSubmit)="onSubmit()">
<h2 >Contact Form</h2>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Your Name:</label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="yourname" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Email: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Items:</label>
<div class="col-sm-5">
<select id="Item" class="form-control" formControlName="item">
<option *ngFor="let c of item" [ngValue]="c">{{ c }}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> Name: </label>
<div class="col-sm-5">
<input type="text" class="form-control" formControlName="name">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
Remarks:</label>
<div class="col-sm-5">
<textarea class="form-control" type="text" formControlName="remarks" rows="3">
</textarea>
</div>
</div>
<div class="dialog">
<button type="submit" color=#C93C6A class="btn-block" [disabled]="!profileForm.valid">Submit</button>
</div>
</form>
</div>
</div>
I have a form, I have in this two fields inline because they are in a form-inline div, I want to put the label of these above the fields and not next to them. How to remove form-inline from them without affecting the fields?
Here is a CodePen
<main id="contact_part">
<article class="mb-5 row">
<h1>Nous Contacter</h1>
<div class="col-md-12">
<form action="" method="post" id="contact_form">
<div class="form-inline">
<label class="" for="name_contact">Name</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="name_contact" placeholder="Nom" required>
<label class="" for="lastNameContact">Name</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="lastName_contact" placeholder="Prénom" required>
</div>
<div class="form-group">
<label class="" for="email_contact">E-Mail</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="E-Mail" required>
</div>
<div class="form-group">
<label class="" for="message_contact">Message</label>
<textarea class="form-control" id="message_contact" placeholder="Message" required></textarea>
</div>
</form>
</div>
</article>
</main>
#contact_part article {
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
#contact_part .row {
display: block;
}
#contact_part h1 {
font-size: 1.7rem;
text-transform: uppercase;
margin-bottom: 3rem;
text-decoration: underline;
text-align: center;
}
#contact_form {
width: 50%;
margin: 0 auto;
}
#contact_form .form-inline label {
}
#contact_form input, #contact_form textarea {
border: none;
border-bottom: 1px solid #C6C6C6;
background-color: #FFF989;
}
If I understand correctly you no need to use form-inline class instead use like below code. Your form will look good.
<main id="contact_part">
<div class="container">
<article class="mb-5 row">
<div class="col-12">
<h1>Nous Contacter</h1>
</div>
<div class="col-12">
<form action="" method="post" id="contact_form">
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="name_contact">First Name</label>
<input type="text" class="form-control" id="name_contact" placeholder="First Name" required>
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="lastNameContact">Last Name</label>
<input type="text" class="form-control" id="lastName_contact" placeholder="Last Name" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="email_contact">E-Mail</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="example#example.com" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="message_contact">Message</label>
<textarea class="form-control" id="message_contact" placeholder="Message" rows="5" required></textarea>
</div>
</div>
</div>
</form>
</div>
</article>
</div>
</main>
Code Pen.
Use col-12 instead of col-md-12 class for better performance. Don't use row without container or container-fluid. If you use only row it give you horizontal scroll bar. Your code will look like this.
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
Or
<div class="container-fluid">
<div class="row">
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
</div>
</div>
Fluid view or 100% Browser width
<div class="container-fluid">
<div class="row">
<div class="col-12">Content</div>
<div class="col-12">Content</div>
<div class="col-12">Content</div>
<div class="col-12">Content</div>
</div>
</div>
Hope this help!
Here you go, let me know if this works: https://codepen.io/luke-richter/pen/XWJVqWO
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
#contact_part{
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<!------ Include the above in your HEAD tag ---------->
<main id="contact_part">
<div class="container ">
<div class="row">
<h2>Inline form with heading above inputs</h2>
</div>
<form action="#">
<div class="row">
<div class="col-md-3">
<div class="form-group form-group-sm">
<label for="firstname" class="control-label">Firstname1</label>
<input type="text" class="form-control" id="firstname" placeholder="Firstname">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">Last Name2</label>
<input type="text" class="form-control" id="lastname" placeholder="Last Name">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">Last Name3</label>
<input type="text" class="form-control" id="lastname" placeholder="Last Name">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<textarea class="form-control"></textarea>
</div>
</div>
<div class="row">
<div class="col-xs-3"><br>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
Try this,
.form-inline label
{
margin-bottom:3em;
}
Or You can move the label outside the<div class="form-inline">
This is the bootstrap page
<div id="cover-caption">
<div id="container" class="container-fluid">
<div class="row d-flex">
<div class="col-lg-10 offset-sm-1 text-center"><br>
<h1 class ="font-weight-bold">Classes</h1>
<div class="info-form">
<form action="" class="form-inline justify-content-center">
<div class="form-group">
<input type="text" class="form-control" placeholder="Class Name">
</div><br>
<div class="form-group">
<input type="text" class="form-control" placeholder="Title">
</div><br>
<div class="form-group">
<textarea type="text" class="form-control" placeholder="Notes"></textarea>
</div>
<button type="submit" class="btn btn-warning">Submit</button>
</form>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
Here is my CSS:
#cover {
background: #222 url('') center center no-repeat;
background-size: cover;
height: 100%;
text-align: center;
display: flex;
align-items: center;
}
#cover-caption {
width: 100%;
}
I want to put a line break between the textarea and button, and <br> doesn't work. Can someone explain why and help me fix it
Are you looking for <hr> ? or simply <br><br> ?
Or you could put style="padding-top: 10px;" on the button...
Have a great day.
EDIT:
removed form-inline class from form tag, replaced with span (you'll need to fix the centering):
<div id="cover-caption">
<div id="container" class="container-fluid">
<div class="row d-flex">
<div class="col-lg-10 offset-sm-1 text-center">
<br>
<h1 class="font-weight-bold">Classes</h1>
<div class="info-form">
<form action="">
<span class="form-inline justify-content-center">
<div class="form-group">
<input type="text" class="form-control" placeholder="Class Name">
</div>
<br>
<div class="form-group">
<input type="text" class="form-control" placeholder="Title">
</div>
<br>
<div class="form-group">
<textarea type="text" class="form-control" placeholder="Notes"></textarea>
</div>
</span>
<button type="submit" class="btn btn-warning">Submit</button>
</form>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
I finally understand your problem.
You are letting the bootstrap CSS form to override your button. You dun need to change anything instead just put the button outside the form.
<form action="" class="form-inline justify-content-center">
<div class="form-group">
<input type="text" class="form-control" placeholder="Class Name">
</div><br>
<div class="form-group">
<input type="text" class="form-control" placeholder="Title">
</div><br>
<div class="form-group">
<textarea type="text" class="form-control" placeholder="Notes"></textarea>
</div>
</form>
<button type="submit" class="btn btn-warning">Submit</button>
I'm not strong in frontend development :) I'm using bootstrap for created a form. But it isn't look fine. How could I align my input form in one column?
<form>
<div class="form-group form-inline">
<label for="exampleInputPrice" class="personal-form-labels">Purchase Price</label>
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
<div class="form-group form-inline">
<label for="exampleInputLoan" class="personal-form-labels">Loan Amont</label>
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
enter image description here
Use of display:table-*
table {
border-collapse: separate;
}
.form-inline {
display: table-row;
}
.form-inline label, .form-inline input {
display: table-cell;
margin: 0 0 5px 10px;
}
<form>
<div class="form-group form-inline">
<label for="exampleInputPrice" class="personal-form-labels">Purchase Price</label>
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
<div class="form-group form-inline">
<label for="exampleInputLoan" class="personal-form-labels">Loan Amont</label>
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
Try like this , bootstrap Horizontal form not support in bootstrap -4
Not supported ,use bootstrap 3
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<form class="form-horizontal" action="/action_page.php">
<div class="form-group">
<label class="control-label col-sm-2" for="Purchase Price">Purchase Price</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Loan Amont">Loan Amont</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Continue</button>
</div>
</div>
</form>
bootsrap-3 doc https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_form_horizontal&stacked=h
If you are using bootstrap 4 Try This :
<form>
<div class="form-group row">
<label for="exampleInputPrice" class="col-sm-2 col-form-label">Purchase Price</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
</div>
<div class="form-group row">
<label for="exampleInputLoan" class="col-sm-2 col-form-label">Loan Amont</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
</div>
<div class="form-group form-inline">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
https://jsfiddle.net/sv2j08dd/3/
Modulation:
Glass thickness:
css:
.inputs span{ display: inline-block; width: 60%; padding: 0 0 15px 0; }
.inputs span input{ width: 30%; float: left; height:25px;padding: 0 5px;}
.inputs{width: 100%;float: left;padding: 0 25px; box-sizing: border-box;}
.inputs label{width: 20%;float: left;}
I'm having this problem, next "form-group row" misplaced. Working on django/jinja template (flask project).
This code:
<div class="row">
<div style="color: chocolate; padding: 10px; margin-left: 10px; font-size: 25px;">Client Details</div>
<div class="col-md-12" style="padding: 20px 0px 0px;">
<form class="form-horizontal">
<div class="col-md-6" style="border-left: 5px solid #eee; margin: 0 0 20px;">
<div class="form-group row">
<label id="labelbox" class="col-sm-2 col-form-label">Client ID</label>
<div class="input-group col-sm-6">
<input class="form-control" col-sm-6 type="text" value="" id="client-id" readonly>
<span class="input-group-btn">
<button class="btn" type="button" data-clipboard-target="client-id">Copy</button>
</span
</div>
</div>
<div class="form-group row">
<label id="labelbox" class="col-sm-2 col-form-label">Client Secret</label>
<div class="input-group col-sm-10">
<input class="form-control" type="text" value="" id="client-secret" readonly>
<span class="input-group-btn">
<button class="btn" type="button" data-clipboard-target="client-secret">Copy</button>
</span
</div>
</div>
</div>
</form>
</div>
This behavior is here: http://www.bootply.com/Ig0ilwpSdh
Ideally I would like to have newline, which I could do with , but since I'm using bootstrap, I'm thinking everything could be done with just bootstrap.
And also vertically align input fields.
By the way, misplacing appears, when I add:
<span class="input-group-btn">
Can you advice how I should better handle that?