Input Group in combination with span: style problems using bootstrap - html

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;
}

Related

How to make space between two text boxes in bootstrap

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.

Bootstrap4: Text and text area width not same

I want my text and textarea have same width. I have no idea what col, lg, md, MB, and sm does. I have tried it a lot. Here is the code. please help
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="container-fluid">
<div class="row featurette">
<div class="col-md-7">
<h2 class="featurette-heading display-4" id="contact">Contact <span class="text-muted display-4">Us</span></h2>
<img class="bd-placeholder-img bd-placeholder-img-lg featurette-image img-fluid mx-auto" src="undraw_contact_us_15o2.png" width="70%" height="70%" xmlns="http://www.w3.org/2000/svg" focusable="false" role="img"></img>
</div>
<div class="form">
<form action="https://formspree.io/mzbjjlyy" method="POST" class="was-validated">
<div class="form-group mb-3">
<label>
Your email:
<input type="text" name="_replyto" class="form-control" placeholder="Enter email" id="email" required>
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Please fill out this field.</div>
</label>
</div>
<div class="form-group">
<label for="msg">
Your message:
<textarea name="message" class="form-control mb-3" placeholder="Enter your message" id="msg" rows="5" required></textarea>
</label>
<br>
<button type="submit" class="btn btn-primary btn-lg">Send</button>
</form>
</div>
</div>
</div>
also, where can I learn about it
Your bug is in here. Close the label tag before adding the textarea.
Check this link https://getbootstrap.com/docs/4.5/layout/overview/ for how bootstrap layout classes work.
<label for="msg">
Your message:
</label>
<textarea name="message" class="form-control mb-3" placeholder="Enter your
message" id="msg" rows="5" required>
</textarea>

How to reduce size of text-input in datepicker?

I have datepicker and i am using bootstrap, i want to find a way to reduce its width. It seem to fill my browser as large. Here is my code below for this logic.
<!---DatePicker
---->
<div class="d-flex justify-content-start">
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-sm form-control" name="from" placeholder="startdate"/>
<span class="input-group-addon">To</span>
<input type="text" class= "input-sm form-control" placeholder="enddate"/>
</div>
</div><br>
use this code for your section i just use bootstrap col-**-* classes.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid justify-content-start">
<div class="row">
<div class="col-xl-4 col-lg-5 col-md-6 col-sm-8 col-12">
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-sm form-control" name="from" placeholder="startdate"/>
<span class="input-group-addon">To</span>
<input type="text" class= "input-sm form-control" placeholder="enddate"/>
</div>
</div>
</div>
</div>
I hope this will work for you.
Thank you...

Bootstrap 4 set a width of input-group inputs

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>

How can I change the direction of labels?

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="panel-body" style="direction: rtl;">
<form class="form-horizontal" role="form" method="POST" action="#">
<input type="hidden" name="_token" value="LX7HWby1aME0NLMslEr2AHkxTRGBK7pRDYKTrh9P">
<div class="form-group">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="">
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="">
</div>
</div>
<div class="form-group">
<label for="content" class="col-md-4 control-label">Content</label>
<div class="col-md-6">
<textarea id="content" rows="4" class="form-control" cols="50" name="content"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-envelope-o" aria-hidden="true"></i> Send
</button>
</div>
</div>
</form>
</div>
If you run code snippet above in full size screen, you will see titles are in the left side, and inputs are in the right side (next to each other)
My website supports multi languages, also as you know, some languages are rtl direction. So I need to change the position of inputs and titles together. I mean I need to adjust inputs in the right side and titles in the left side (on the contrary of current structure) by adding some CSS code.
How can I do that?
Current UI:
Expected UI: (by using only CSS, not changing HTML)
In your case you can use the :lang() css selector with the rtl languages.
For example with arabic, you can use:
:lang(ar) .form-group label{
/* You can put here all the desired properties */
}
You can read more about it in CSS-Tricks's :lang() selector tutorial, but you have to pay attention to its browser compatibility.
You can use bootstrap-rtl to do the job for you.
Bootstrap RTL provides simple yet robust right-to-left capability for
Bootstrap 3, by employing new theming feature of it. Simply put its
CSS after bootstrap's original CSS, to the pages designed by Bootstrap
3. It works just like an extension on top of the original Bootstrap
You can either include it from your server or use a CDN. For a CDN example:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.css" />
Use pull-right class
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-
BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="panel-body" style="direction: rtl;">
<form class="form-horizontal" role="form" method="POST" action="#">
<input type="hidden" name="_token" value="LX7HWby1aME0NLMslEr2AHkxTRGBK7pRDYKTrh9P">
<div class="form-group">
<label for="name" class="col-md-2 control-label pull-right" style="text-align:left" >Name</label>
<div class="col-md-10">
<input id="name" type="text" class="form-control" name="name" value="">
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-2 control-label pull-right " style="text-align:left">E-Mail Address</label>
<div class="col-md-10">
<input id="email" type="email" class="form-control" name="email" value="">
</div>
</div>
<div class="form-group">
<label for="content" class="col-md-2 control-label pull-right " style="text-align:left">Content</label>
<div class="col-md-10">
<textarea id="content" rows="4" class="form-control" cols="50" name="content"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-envelope-o" aria-hidden="true"></i> Send
</button>
</div>
</div>
</form>
</div>