I need small white space between two text boxes.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row col-lg-12 col-sm-12">
<div class="input-group col-md-8">
<span class="control-label">Product Name*</span>
<input type="text" class="form-control" placeholder="Product Name" id="productname" required>
</div>
<div class="input-group col-md-4" style=>
<span class="control-label">Short Name*</span>
<input type="text" class="form-control" placeholder="ShortName" id="shortname" required>
</div>
</div>
Are you want space between the textbox? i mean in small device it having in two row .so there is add mt-3(margin-top) for below margin to each input-group
Is this issue?
Add mt-3(margin-top) to each input-group and also add a width to span for correct alignment like this span{width:130px;}
span{
width:130px;
}
<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-fluid">
<div class="row">
<div class="input-group col-12 mt-3">
<span class="control-label d-flex h-100 align-items-center">Product Name* </span>
<input type="text" class="form-control" placeholder="Product Name" id="productname" required>
</div>
<div class="input-group col-12 mt-3" style=>
<span class="control-label d-flex h-100 align-items-center">Short Name* </span>
<input type="text" class="form-control"placeholder="ShortName" id="shortname" required>
</div>
</div>
</div>
You may use margin or padding class on your span element :
example
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row col-lg-12 col-sm-12">
<div class="input-group col-md-8">
<span class="control-label px-1">Product Name*</span>
<input type="text" class="form-control" placeholder="Product Name" id="productname" required>
</div>
<div class="input-group col-md-4" style=>
<span class="control-label px-1">Short Name*</span>
<input type="text" class="form-control" placeholder="ShortName" id="shortname" required>
</div>
</div>
https://getbootstrap.com/docs/4.5/utilities/spacing/
Spacing
Bootstrap includes a wide range of shorthand responsive margin and padding utility classes to modify an element’s appearance.
How it works
Assign responsive-friendly margin or padding values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. Classes are built from a default Sass map ranging from .25rem to 3rem.
Related
I am facing a style problem.
So this is my code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<form>
<div class="input-group mb-3">
<span class="input-group-addon">Site Name</span>
<input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">
</div>
<br>
<div class="input-group mb-3">
<span class="input-group-addon">URl</span>
<input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">
</div>
<br>
<div class="input-group mb-3">
<span class="input-group-addon">Number</span>
<input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">
</div>
<br>
<div class="input-group mb-3">
<span class="input-group-addon">Desc. or Comment</span>
<input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">
</div>
<br>
</form>
I have different long names in my span tag. The problem is that my input fields are not in a column. I want them to be among themselves. Can u tell me what how to get the style i want.
You need to separate everything per Bootstrap styles. You don't have your items layed out in rows/columns. The following example would be with Bootstrap 4.
Use the Full Page option when viewing the snippet.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<form>
<div class="row">
<span class="input-group-addon col-sm-12 col-md-3">Site Name</span>
<input type="text" id="msg" class="form-control col-sm-12 col-md-9" name="msg" placeholder="Additional Info">
</div>
<div class="row mt-5">
<span class="input-group-addon col-sm-12 col-md-3">URL</span>
<input type="text" id="msg" class="form-control col-sm-12 col-md-9" name="msg" placeholder="Additional Info">
</div>
<div class="row mt-5">
<span class="input-group-addon col-sm-12 col-md-3">Number</span>
<input type="text" id="msg" class="form-control col-sm-12 col-md-9" name="msg" placeholder="Additional Info">
</div>
<div class="row mt-5">
<span class="input-group-addon col-sm-12 col-md-3">Desc. or Comment</span>
<input type="text" id="msg" class="form-control col-sm-12 col-md-9" name="msg" placeholder="Additional Info">
</div>
</form>
</div>
I admit I am guessing a bit as to your intent here that you mean to make the input group start labels have a similar width so that is what I attempt here.
Your input group prefix text is already left so we can simply leverage the Bootstrap grid column classes for this. Here I used col-3 to force a 3/12 of a width for the input-group-text using in Bootstrap 5. You can try other values such as col-2 or col-4 etc.
Things I did:
Used Bootstrap 5
Changed your ID attributes to be unique so that the HTML is valid
Changed your name attributes to match the id I had changed it to
Removed the <br> markup as it seemed to not be needed - if you need more space you can increase mb-3 to mb-5 or give the next item mt-3 or some such.
Changed the placeholder attribute text to better illustrate which field we were using
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<form>
<div class="input-group mb-3">
<span class="input-group-text col-3">Site Name</span>
<input id="site-name" type="text" class="form-control" name="site-name" placeholder="Name here">
</div>
<div class="input-group mb-3">
<label class="input-group-text col-3">URI</label>
<input id="url" type="text" class="form-control" name="url" placeholder="URL here">
</div>
<div class="input-group mb-3">
<span class="input-group-text col-3">Number</span>
<input id="site-number" type="text" class="form-control" name="site-number" placeholder="Number Info">
</div>
<div class="input-group mb-3">
<span class="input-group-text col-3">Desc. or Comment</span>
<input id="site-desc" type="text" class="form-control" name="site-desc" placeholder="Comment Info">
</div>
</form>
So i solved my problem with some custom css.
Create style.css and dont forget to link it in your html code!
that css worked for me:
.input-group-addon {
min-width:80px;
text-align:left !important;
}
Can you help me with this problem? I have an input-group within bootstrap 4. In my input-group I have 2 inputs, first with prepend and second with append.
It's wrapped in a col-12 div in a form-group and I need to set the width of the first input and second to some specific (but different) value. I tried to set the width in my custom css, but without success. Is it possible? I know, that I can set it via wrapping it in a div with another col, but than I have both input below and not side by side.
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="form-group">
<label for="telephone">Telephone</label>
<div class="row">
<div class="col-12">
<div class="input-group telephone-input">
<div class="input-group-prepend preselection-prepend">
<div class="input-group-text">+</div>
</div>
<input class="form-control" id="preselection" type="text" maxlength="3" name="preselection" placeholder="Preselection" autocomplete="off" required>
<input class="form-control" id="telephone" placeholder="Telephone number" type="tel" maxlength="11" name="telephone" autocomplete="off" required>
<span class="placeholder" id="tele-holder"></span>
<div class="input-group-append" id="preselectionToggle">
<div class="input-group-text">
<i class="far fa-plus-square"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>
You can do it with class w-50 and w-100
like this
<div class="input-group">
<div class="input-group-prepend w-50">
<span class="input-group-text w-100">label</span>
</div>
<input type="text" class="form-control " />
</div>
I've found a solution on the internet and you can visit it at codeply!.
It is pretty neat and simple. To do so, you just need to add the following CSS to your stylesheet.
.input-group>.input-group-prepend {
flex: 0 0 30%;
}
.input-group .input-group-text {
width: 100%;
}
To set the width of the input-group-text, just change the value of the flex of the input-group, for instance, as seen above 30% of the total width.
Thank the author of the link above for this simple code snippet.
I found a solution. I tried set max-width instead of only width and it works.
For the above example it would be:
#preselection {
max-width: 15%;
}
<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="form-group">
<label for="telephone">Telephone</label>
<div class="row">
<div class="col-12">
<div class="input-group telephone-input">
<div class="input-group-prepend preselection-prepend">
<div class="input-group-text">+</div>
</div>
<input class="form-control" id="preselection" type="text" maxlength="3" name="preselection" placeholder="Preselection" autocomplete="off" required>
<input class="form-control" id="telephone" placeholder="Telephone number" type="tel" maxlength="11" name="telephone" autocomplete="off" required>
<span class="placeholder" id="tele-holder"></span>
<div class="input-group-append" id="preselectionToggle">
<div class="input-group-text">
<i class="far fa-plus-square"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>
I want to center the .input-group inside a <div>. When I use the class center-block, the <span> takes the full width and pushes down the input field below it. I want to center them together.
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<div class="input-group input-group-lg inv-amount-block">
<span class="input-group-addon" id="inv-rs">Rs</span>
<input type="text" class="form-control" placeholder="Your Amount" aria-describedby="basic-addon1">
</div>
</div>
I want to center them together like how they are by default.
Here is the fiddle
Just change the display property in the CSS for the .center-block
Edited: Difference between display: block and display: table is that - . display: block - will extend to 100% of the available space, while display: table - will only be as wide as its contents.
So in the latter case your span and input field would only be as wide as its content and won't take up the entire 40% width that is specified.
.center-block {
display: table; /* Instead of display:block */
margin-left: auto;
margin-right: auto;
}
<div class = "col-lg-12 col-sm-12 col-md-12 col-xs-12 ">
<div class="input-group input-group-lg inv-amount-block center-block ">
<span class="input-group-addon " id="inv-rs">Rs</span>
<input type="text" class="form-control" placeholder="Your Amount" aria-describedby="basic-addon1">
</div>
</div><br>
<div class = "col-lg-12 col-sm-12 col-md-12 col-xs-12 ">
<div class="input-group input-group-lg inv-amount-block ">
<span class="input-group-addon " id="inv-rs">Rs</span>
<input type="text" class="form-control" placeholder="Your Amount" aria-describedby="basic-addon1">
</div>
</div>
In Bootstrap 4, center-block has been replaced by mx-auto, and input-group has changed to display:flex. Here's how to center in Bootstrap 4...
<div class="col-12">
<div class="input-group input-group-lg w-25 mx-auto">
<div class="input-group-prepend">
<span class="input-group-text">Rs</span>
</div>
<input type="text" class="form-control" placeholder="Your Amount">
</div>
</div>
Remember that input-group will fill the width of the parent, so in this case I added w-25 (width:25%) to demonstrate the centering.
Demo on Codeply
Copy below code and paste in your file and run check this input box is align center and responsive also.
This example is based in bootstrap v3.4
<!DOCTYPE html>
<html>
<head>
<title>Center Input box demo</title>
<link href="https://getbootstrap.com/docs/3.4/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<form class="row" action="" method="post" id="search_project_form">
<div class="col-md-4 col-sm-2 col-sm-offset-4 col-xs-offset-2">
<input type="text" name="search_group" id="search_group" class="form-control" placeholder="Group Number" required>
</div>
<button type="submit" class="btn btn-primary">Download Data</button>
</form>
</div>
</body>
</html>
Use display: grid for input-group-text element.
<div class="input-group">
<div class="form-floating" style="width: 85%;">
<input type="text" class="form-control" id="abc" placeholder="Description">
<label for="abc">Description</label>
</div>
<div class="input-group-text" style="display: grid; width: 15%;">Hello</div>
</div>
I want a form in Bootstrap that renders two text fields on the same line, with text following each input:
Label 1A Input 1A Text 1A Label 1B Input 1B Text 1B
Label 2A Input 2A Text 2A Label 2B Input 2B Text 2B
Basically, the two inputs on the same line are related, so I want them next to each other. I've sort of accomplished that using this markup:
<form class="inline-form">
<div class="col-sm-8">
<div class="form-group">
<label for="input1" class="control-label">ABCDEFG</label>
<input type="text" name="input1" id="input1"> units
<label for="input1_max" class="control-label"></label>
<input type="text" name="input1_max" id="input1_max"> units
</div>
<div class="form-group">
<label for="input2" class="control-label">ABCD</label>
<input type="text" name="input2" id="input2"> units
<label for="input2_max" class="control-label"></label>
<input type="text" name="input2_max" id="input2_max"> units
</div>
</div>
</form>
Also see this fiddle. If you widen the HTML output you should see the effect I'm describing.
The problem with this is the form fields are not aligned, and the layout gets really screwy for small screen sizes.
First and foremost, I'd like the fields to all align nicely when viewed in a standard desktop browser. I've tried various classes with no success.
But if there's a better way to do this, I'd love to hear that too.
Thank you for any and all help!
If I understand what you want it will work.
Try this approach:
The idea is playing with the grid, dividing each row (using grid´s bootstrap) and inside of each row, dividing again as you need.
It should be enough, but if you have any problem, you can add pull-right and pull-left class where you need it. These classes set to left or right inside a column of grid´s bootstrap.
Besides, you can add this style or class for being secure you are not overlapping layers/div.
white-space : nowrap;
<form class="form-inline" role="form">
<div class="form-group col-lg-6 col-md-6 col-xs-6">
<div class="form-group col-lg-8 col-md-8 col-xs-8">
<label for="input1" class="control-label first-label pull-left">ABCDEFG</label>
<input type="text" name="input1" id="input1" class="pull-right"> units
</div>
<div class="form-group col-lg-4 col-md-4 col-xs-4">
<label for="input1_max" class="control-label"></label>
<input type="text" name="input1_max" id="input1_max" class="pull-right"> units
</div>
</div>
<div class="form-group col-lg-6 col-md-6 col-xs-6 pull-right">
<!-- REPEAT THE SAME IDEA -->
</div>
</form>
With this code, you have one row with 2 parts with the same size. Inside the first part you have two part as well, one of them double than the other one. Inside of these part, you have a label at the left(pull-left) and it input at thee right(pull-right).
If you have any doubt, please let me know.
Cheers mate
<style>
label { width: 12%; }
</style>
<form class="inline-form">
<div class="col-sm-8">
<div class="form-group">
<label for="input1" class="control-label">ABCDEFG</label>
<input type="text" name="input1" id="input1"> units
<input type="text" name="input1_max" id="input1_max"> units
</div>
<div class="form-group">
<label for="input2" class="control-label">ABCD</label>
<input type="text" name="input2" id="input2"> units
<input type="text" name="input2_max" id="input2_max"> units
</div>
</div>
</form>
To align them input boxes you need to set equal width on the labels. As the labels are inline element, while your labels got different texts their sizes will be different so the following boxes will be just right after it.
For the above example you can have this following
label{
width: 80px;
}
But the above css will widen the width of the text "units" to solve this you may update your markup a bit by assigning class to the not equal labels & then declaring width on them like the follwoing
<form class="inline-form">
<div class="col-sm-8">
<div class="form-group">
<label for="input1" class="control-label first-label">ABCDEFG</label>
<input type="text" name="input1" id="input1"> units
<label for="input1_max" class="control-label"></label>
<input type="text" name="input1_max" id="input1_max"> units
</div>
<div class="form-group">
<label for="input2" class="control-label first-label">ABCD</label>
<input type="text" name="input2" id="input2"> units
<label for="input2_max" class="control-label"></label>
<input type="text" name="input2_max" id="input2_max"> units
</div>
</div>
</form>
And assigning width to the class
.first-label{
width: 80px;
}
There is one more solution without the markup change
.form-group label:first-of-type{
width: 80px;
}
Need to add a fixed width for your control-label
.control-label {
width: 15%;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<form class="inline-form">
<div class="col-sm-8">
<div class="form-group">
<label for="input1" class="control-label">Label 1A</label>
<input type="text" name="input1" id="input1">units
<label for="input1_max" class="control-label">Label 1B</label>
<input type="text" name="input1_max" id="input1_max">units
</div>
<div class="form-group">
<label for="input2" class="control-label">Label 2A</label>
<input type="text" name="input2" id="input2">units
<label for="input2_max" class="control-label">Label 2B</label>
<input type="text" name="input2_max" id="input2_max">units
</div>
</div>
</form>
try this code it may solve your problem.you need to define cols inside row .so in this i define 2 row and each of them have 4 column for mobile as well as desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form class="inline-form">
<div class="form-group">
<div class="row">
<div class="col-md-3 col-xs-3 ">
<label for="input1" class="control-label">ABCDE35</label>
</div>
<div class="col-md-3 col-xs-3 ">
<input type="text" name="input1" id="input1"> units
</div>
<div class="col-md-3 col-xs-3 ">
<label for="input1_max" class="control-label"></label>
</div>
<div class="col-md-3 col-xs-3 ">
<input type="text" name="input1_max" id="input1_max"> units
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 col-xs-3 ">
<label for="input2" class="control-label">ABCD</label>
</div>
<div class="col-md-3 col-xs-3 ">
<input type="text" name="input3" id="input3"> units
</div>
<div class="col-md-3 col-xs-3 ">
<label for="input3_max" class="control-label"></label>
</div>
<div class="col-md-3 col-xs-3 ">
<input type="text" name="input3_max" id="input3_max"> units
</div>
</div>
</div>
</form>
</body>
</html>
From official docs:
Use Bootstrap's predefined grid classes to align labels and groups of
form controls in a horizontal layout by adding .form-horizontal to the
form (which doesn't have to be a ). Doing so changes
.form-groups to behave as grid rows, so no need for .row.
So I tried:
<form class="form-horizontal">
<div class="form-group">
<input type="text" class="col-md-2 form-control" placeholder="Cantidad">
<input type="text" class="col-md-6 form-control" placeholder="Unidad">
</div>
</form>
But it seems the form-control class will make them return to an own single row each.
This is what I got:
How can I achieve both input to be placed in same row?
Add form-inline to the form class. Note that, if you make the form too small, it will still 'spill over'. In this case, and if you don't want all form-groups to be inline, use separate divs for the spacing.
Form inline example:
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-md-10 col-md-offset-1">
<form class="form-horizontal form-inline">
<div class="form-group">
<input type="text" class="col-md-2 col-xs-6 form-control" placeholder="Cantidad">
<input type="text" class="col-md-6 col-xs-6 form-control" placeholder="Unidad">
</div>
</form>
</div>
</div>
Separate Div example:
fiddle
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-md-10 col-md-offset-1">
<form class="form-horizontal">
<div class="form-group">
<div class="input-group">
<div class="col-md-2 col-xs-6">
<input type="text" class=" form-control" placeholder="Cantidad" />
</div>
<div class="col-md-6 col-xs-6">
<input type="text" class=" form-control" placeholder="Unidad" />
</div>
</div>
</div>
</form>
</div></div>
HTML
<form class="form-horizontal">
<div class="form-group">
<input type="text" class="col-md-2 pull-left" placeholder="Cantidad">
<input type="text" class="col-md-6 pull-left" placeholder="Unidad">
</div>
</form>
jsfiddle