Why does my Bootstrap input not align right (=> see 3rd input with placeholder='Does not align right')?
The td table element has a style which defines the alignment...
When I remove the style element from the td element at set the input style text-align=right, it is still left aligned.
<div class="row">
<div class="col-md-6">
<div class="well" style="width:840px">
<table class='table borderless' style="width:800px">
<tr>
<td colspan="2">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input1" placeholder="Input 1">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input2" placeholder="Input 2">
</td>
</tr>
<tr>
<td colspan="2" style="text-align: right">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input3" placeholder="Does not align right">
</td>
</tr>
<tr>
</table>
</div>
</div>
</div>
Why does my Bootstrap input not align right?
Because .form-control will have display: block from bootstrap.min.css. As proof of this, if you make it an inline-block again it'll work:
.form-control { display: inline-block !important; }
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-md-6">
<div class="well" style="width:840px">
<table class='table borderless' style="width:800px">
<tr>
<td colspan="2">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input1" placeholder="Input 1">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input2" placeholder="Input 2">
</td>
</tr>
<tr>
<td colspan="2" style="text-align: right">
<input class="form-control input-sm" style="width:300px;margin-bottom:0px" type="text" name="input3" placeholder="Does not align right">
</td>
</tr>
<tr>
</table>
</div>
</div>
</div>
What you probably really want is your controls to behave like that straight away. To do so make sure to utilize Bootstrap's form-inline, e.g. like this:
<div class="row form-inline">
Note that this affects the first row of inputs too. If you move the form-inline to a another spot you could choose to prevent that from happening.
That's because your input has it's display property set to block via the .form-control class. Block level elements will take up the whole width of their containing element. Even if a width is set, the remaining space is taken up by margin.
To get the input to align the way you would like change the display value to inline-block or add the class .pull-right to the input.
.form-control {
display: inline-block;
}
<input type="text" class="form-control input-sm pull-right">
Twitter Bootstrap specially set width: 100% property to the .form-control to make the life easier and handle such things with Grid system
You can go with the following solution
HTML Markup
<div class="row">
<div class="col-md-9 is-centered">
<div class="well well-form">
<!-- Two inline input fields per row -->
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control input-sm" type="text" name="input1" placeholder="Input 1">
</div>
<div class="col-sm-6 form-group">
<input class="form-control input-sm" type="text" name="input2" placeholder="Input 2">
</div>
</div>
<div class="row has-border">
<div class="col-sm-12">
<!-- Single input fields per row (pushed to the right) -->
<div class="row">
<div class="col-sm-6 pull-right">
<input class="form-control input-sm" type="text" name="input3" placeholder="align to right">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Helpers (optional)
SCSS
[class*="col-"] {
&.is-centered {
float: none;
margin-right: auto;
margin-left: auto;
}
}
.well-form {
> .row {
padding-top: 8px;
border-top: 1px solid #ddd;
}
.form-group {
margin-bottom: 8px;
}
}
CSS
[class*="col-"].is-centered {
float: none;
margin-right: auto;
margin-left: auto;
}
.well-form > .row {
padding-top: 8px;
border-top: 1px solid #ddd;
}
.well-form .form-group {
margin-bottom: 8px;
}
DEMO
Couple of things to notice:
<table> is not a good approach in this case
inline style=" to HTML tags is not good at all (even if its a demo)
Hope this helps
Related
I have 3 rows with 2 columns in each row on my HTML page with some labels and inputs.
I see a lot of space between the rows which I tried removing but didn't work. Is there a way to do it?
Here's the HTML Code :
<div >
<h1>
New Patient Record
</h1>
</div>
<div class="row" style="padding-bottom: 0px;">
<div class="column"></div>
<div class="column">
<label > <strong>Date</strong> </label>
<input type="date" name="date" id="date" class="form-control" [(ngModel)]="institutes.date">
</div>
</div>
<div class="row" style="padding-top:0px" >
<div class="container" style="padding-left: 7.5%" >
<form #institutesForm="ngForm" (ngSubmit)="instituteLogins(institutesForm)">
<div class="form-group">
<div class="row">
<div class="column">
<h2><strong> Symptoms</strong> </h2>
<input type="text" name="symtoms" id="symtoms" class="form-control"[(ngModel)]="institutes.symtoms">
<br>
<h2><strong>Diagnosis</strong></h2>
<label> <strong>Condition</strong> </label>
<input type="text" name="condition" id="condition" class="form-control"[(ngModel)]="institutes.condition">
<label><strong> Advice </strong></label>
<input type="text" name="advice" id="advice" class="form-control"[(ngModel)]="institutes.advice">
<br>
</div>
<div class="column">
<h2> <strong>Prescription</strong> </h2>
<br>
<label><strong> Medication </strong></label>
<input type="text" name="medication" id="medication" class="form-control"[(ngModel)]="institutes.medication">
<label><strong> Medicine Type </strong></label>
<input type="text" name="type" id="type" class="form-control"[(ngModel)]="institutes.type">
<label><strong>Course</strong></label>
<input type="text" id="course" name="course" class="form-control"[(ngModel)]="institutes.course">
<label><strong> How many per day? </strong></label>
<input type="text" name="cday" id="cday" class="form-control"[(ngModel)]="institutes.cday">
<br>
</div>
<div class="row">
<div class="column"></div>
<div class="column">
<button id="record" class="btn btn-primary" type="submit" >Add Record</button>
</div>
</div>
</div>
<br><br>
</div>
</form>
</div>
Here's what all I tried: I tried to adjust row spacing using margins, and padding but none of them worked. Is there any other alternative for this?
.modal-dialog.cascading-modal.modal-avatar .modal-header img {
width: 130px;
margin-left: auto;
margin-right: auto;
}
.modal-dialog.cascading-modal.modal-avatar .modal-header {
margin: -6rem 2rem -1rem 2rem;
}
.More{
color: blue;
margin-right: 100px;
}
.column{
margin : 100px;
}
.row{
margin:0;
padding:0;
align-items: baseline;
}
Changing:
.column{
margin: 100px;
}
To
.column{
margin-left : 100px;
margin-right: 100px;
}
Will remove the space between the rows. Is that the end result you're looking for?
Adjusting the margin-left helped me solve the issue.
Also using to add number of empty spaces vertically solved my UI design issues.
For the space between both rows, you can add the padding-bottom
style="margin-top:-50px"
I have a bootstrap form with the following css code in it. I have tried to close up the blank spaces in the form by adding margin:0 attribute but still the spaces between the element is there.
css form code
<div class="row-fluid">
<form style="width: 90%; height: 100%; margin-top:1px;" method="post"novalidate="novalidate" class="form well">
<div class="row-fluid">
<div>
<label for="complaints">Message *</label>
<textarea style="width:100%;" name="complaints" rows="3" required></textarea>
</div>
</div>
<div class="form-actions">
<input style="width:100%; background-color:#da291c;" class="btn btn-primary" name="commit" type="submit" value="Send">
</div>
</form>
</div>
this is the picture of the above form
My challenge is to close the gaps on the areas pointed with arrows.
I am using this version of bootstrap
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css">
You can remove the margin-bottom that bootstrap adds to the class .control-group
.row-fluid div.control-group, div.form-actions {
margin-bottom: 0px;
}
div.my-form{
padding-bottom: 0px;
margin-top:0px;
padding-top:0px;
}
.control-group input,.control-group textarea{
margin-bottom: 0px;
}
form.form{
padding-bottom: 0;
padding-top:0;
}
UPDATED jsfiddle with your code
You can use this code:
input[type=text], .txtarea{
margin-bottom: 10px;
}
In bootstrap already they keep on the margin property always. we can overwrite that to solve your problem.
you need to add one class like this:
.splclass{
margin:0 !important;
padding:0 !important;
}
Add additionally in the form inline style like this:
<form style="width: 90%; height: 100%; margin-top:1px; padding-top:5px;" method="post"novalidate="novalidate" class="form well ">
i think it will helpful
Well if you don't want any space in between, you definitely don't want any margin. Move the CSS to it's own file:
.send {
width:100%;
background-color:#da291c;
}
.message {
width:100%;
}
.form {
width: 90%;
height: 100%;
margin: 0;
}
and html:
<div class="row-fluid">
<form class="form" method="post" novalidate="novalidate" class="form well">
<div class="row-fluid">
<div class="control-group span12">
<label for="name">Name *</label>
<input ng-model="name" name="name" type="text" class="input-block-level" required>
</div>
</div>
<div class="row-fluid">
<div class="control-group span12">
<label for="email">Email *</label>
<input name="email" placeholder="" type="email" class="input-block-level" ng-model="email"ng-change="id=email" required>
</div>
</div>
<div class="row-fluid">
<div class="control-group span12">
<label for="complaints">Message *</label>
<textarea class="message" name="complaints" rows="3" required></textarea>
</div>
</div>
<div class="form-actions">
<input class="btn btn-primary send" name="commit" type="submit" value="Send">
</div>
</form>
</div>
and you can see the fiddle here: https://jsfiddle.net/6j98311j/
I am trying to create a message input box in a bootstrap form, however the box has to be of sufficient height so the user could read his message, the place holder of "message" would stay in the middle, also when I write the text it keeps going horizontally without considering margins, I am a newbie programmer so please don't be too harsh.
.theform {
margin-left: 200px;
margin-right: 200px;
margin-top: 50px;
border: 5px solid;
padding: 20px 20px 20px 20px;
}
.theform h1 {
font-size: 50px;
text-decoration: underline;
}
#formGroupExampleInput {
height: 50px;
}
.form-control {
font-size: 30px;
}
#messagebox {
height: 200px;
margin-right: 40px;
line-height: 0px;
}
#message {
height: 200px;
margin-right: 40px;
line-height: -20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="theform" id="link3">
<h1 class="text-center">Contact</h1>
<form>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="messagebox" placeholder="Message" size="50">
</div>
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
You have to use a textarea instead of an input. If you want to center the placeholder vertically, you also have to use some JS, just to adjust the textare.
Just look into this codepen for an example implementation of a vertical centered textarea:
https://codepen.io/desandro/pen/gICqd
NO JS REQUIRED
you can fix this issue by puting the text area :
<textarea name="" id="" cols="30" rows="10"></textarea>
by default in text area the placeholder is sent to the top left.
Don't make the mistake of puting input instead because when you will give it a huge height the placeholder will be sent to the middle left !!!
does anyone know how to Inline an input and a div within a table cell?
this is the code:
<td>
<div class="input-group">
<input type="text" data-tier-id="1" class="form-control notes" value="2.829%">
<div class="input-group-addon">%</div>
</div>
</td>
This is very simple. Just add the following CSS code:
.form-control,.input-group-addon {
display: inline;
}
<td>
<div class="input-group">
<input type="text" data-tier-id="1" class="form-control notes" value="2.829%">
<div class="input-group-addon">%</div>
</div>
</td>
https://developer.mozilla.org/en-US/docs/Web/CSS/display
Hope this helps!
It seems that you are adding a title for the input, in which case I would recommend using a <label> tag instead of <div>.
<td>
<div class="input-group">
<label><input type="text" data-tier-id="1" class="form-control notes" value="2.829%">%</label>
</div>
</td>
Otherwise..
CSS:
.form-control notes, .input-group-addon {
display: inline-block;
}
HTML:
<td>
<div class="input-group">
<input type="text" data-tier-id="1" class="form-control notes" value="2.829%">
<div class="input-group-addon">%</div>
</div>
</td>
I have the following code and I'm trying to get both of these inputs aligned centered. Where is the problem in the code?
<div class='form'>
<form class="form-inline" role="form">
<div class="text-center input-group input-group-lg">
<span class="input-group-addon">#</span>
<input class="text-center form-control" align="middle" placeholder="username" name="username" type="text">
</div>
<div class="text-center input-group input-group-lg">
<span class="input-group-addon">P</span>
<input class="text-center form-control" align="middle" placeholder="password" name="password" type="password">
</div>
</form>
</div>
<style>
.text-center {
width: 50%;
}
div {
text-align:center;
}
</style>
Both inputs are still aligned to the left.
Inputs are not text, and cannot be centered using text-align. Target the element directly in your css, like so:
input {
display: block;
margin: 0 auto;
}
This will center the inputs within the parent element.