Align text input in <td> to right in twitter bootstrap? - html

I am trying to align the Text Input to the right and for some reason it is not doing this.
I have used style="text-align: right" in <td>
See example:
https://jsfiddle.net/DTcHh/31200/
Code
<table class="table">
<thead>
<tr>
<th>Field 1</th>
<th style="text-align:right">Field 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text 1</td>
<td style="text-align: right">
<div class="form-group" style="text-align: right">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
</td>
</tr>
</tbody>
</table>

No extra CSS is needed just use Bootstrap pull-right:
https://jsfiddle.net/cp1tvuj3/
<div class="form-group">
<input style="width:60px" type="number" class="form-control pull-right" value="test">
</div>
Updated fiddle
text-right won't work because the form-control is display: block
The original question was for Bootstrap 3. In Bootstrap 4, pull-right is now float-right.

add inline-block to your div element, by default the div is a block element so it takes the complete width of its parent
<div class="form-group" style="text-align: right;display:inline-block;">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
https://jsfiddle.net/RACCH/y9fvo4dj/

Seems like just adding float: right; does the trick, see
url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<table class="table">
<thead>
<tr>
<th>Field 1</th>
<th style="text-align:right">Field 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text 1</td>
<td style="text-align: right">
<div class="form-group" style="text-align: right; float:right">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
</td>
</tr>
</tbody>
</table>

Giving the div around the input field inside your td a style of
display:inline-block;
also fixes your problem without having any floats to potentially break other things.
https://jsfiddle.net/DTcHh/31202/

You need to add bootstrap class ie. "pull-right"
find the code fiddle :
`https://jsfiddle.net/DTcHh/31204/e`

These two solutions worked for me with a Bootstrap 4 table:
Either:
<td>
<div class="float-right">
<input>
</div>
</td>
Or:
<td class="text-right">
<div class="d-inline-flex">
<input>
</div>
</td>

Related

Styling an invoice form using Bootstrap 4

In my VueJS application I am building an invoice form using Bootstrap 4, I am using this code snippet and everything has been great so far but the problem is that, when it comes to styling a UI I kind of suck at the moment :)
The problem here is that the bottom totals part is floating to the left instead of to the right. This code snippet has been taken from a Bootstrap 3 code snippet samples and I am using Bootstrap 4 so probably this is the issue. However, I've tried converting it to Bootstrap 4 using online converters but none of them helped me. I would appreciate your help.
This is the code that I want to float to the right.
<div class="row clearfix" style="margin-top:20px">
<div class="float-right col-lg-4">
<table class="table table-bordered table-hover" id="tab_logic_total">
<tbody>
<tr>
<th class="text-center">Sub Total</th>
<td class="text-center">
<input type="number" name="sub_total" placeholder="0.00" class="form-control" id="sub_total" readonly>
</td>
</tr>
<tr>
<th class="text-center">Tax</th>
<td class="text-center">
<div class="input-group mb-2 mb-sm-0">
<input type="number" class="form-control" id="tax" placeholder="0">
<div class="input-group-addon">%</div>
</div>
</td>
</tr>
<tr>
<th class="text-center">Tax Amount</th>
<td class="text-center">
<input type="number" name="tax_amount" id="tax_amount" placeholder="0.00" class="form-control" readonly>
</td>
</tr>
<tr>
<th class="text-center">Grand Total</th>
<td class="text-center">
<input type="number" name="total_amount" id="total_amount" placeholder="0.00" class="form-control" readonly>
</td>
</tr>
</tbody>
</table>
</div>
</div>
You could use offset for responsively offsetting the columns. Since the container of #tab_logic_total table is taking up 4 columns, we have 8 left, so:
<div class="row clearfix" style="margin-top:20px">
<!-- Notice this line: We are offsetting the table by 8 columns -->
<div class="col-lg-4 offset-lg-8">
<table class="table table-bordered table-hover" id="tab_logic_total">
<tbody>
<tr>
<th class="text-center">Sub Total</th>
<td class="text-center">
At this point, we no longer need the float-right class. It won't have any effect on flexbox anyway.
Further readings:
Bootstrap Grid system

How can i prevent label in div overlapping another div content on a table td

<table>
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
I want it to auto jump to next line if the label text overflow. I no want the label to be hidden or using ellipsis.
Note: In my case, i will loop the div content in the same row td. I want to break the word to next line in full size of browser or browser resized to smaller.
How can i solve this problem?
Apologies for having too less reputation to post a comment.
But have you checked out Bootstrap tables?
It not only solves your problem, but is a good step in moving towards simple web development.
Bootstrap takes care of everything and allows us to make neat and clean tables with very little code from our side.
If at all you need to further style your table, you can add styling OVER the bootstrap styled table.
Check out the following simple tutorial where you can also try it out online.
https://www.w3schools.com/bootstrap/bootstrap_tables.asp
To prove how simple it is,
I have pasted my code into a simple HTML page.
Added bootstrap.
And voila! Your issue is solved in the example given below.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<table class="table">
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div>
<label>abcdefghijklmnop</label>
</div>
<div>
<input type="checkbox">
</div>
<div>
<label>abcdefghijklmnop</label>
</div>
<div>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td> <label>abcdefghijklmnop</label> </td>
<td> <input type="checkbox"> </td>
</tr>
<tr>
<td> <label>abcdefghijklmnop</label> </td>
<td> <input type="checkbox"> </td>
</tr>
</tbody>
</table>
</body>
</html>
I am still confused on what you wanted, so I have included 2 approaches.
Try Float:right;
<table>
<thead>
<th>Item</th>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:10%; float:right;">
<label style="display:block">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
You can use word-wrap: break-word for your label tag.
The word-wrap property allows long words to be able to be broken and wrap onto the next line. break-word allows unbreakable words to be broken
<table>
<thead>
<tr>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div style="display:inline-block;width:25%">
<label style="display:block;word-wrap: break-word;">abcdefghijklmnop</label>
<input type="checkbox">
</div>
<div style="display:inline-block;width:10%">
<label style="display:block;word-wrap: break-word;">abcdefghijklmnop</label>
<input type="checkbox">
</div>
</td>
</tr>
</tbody>
</table>
MDN web docs word-wrap

Design alignment prob in HTML

I have this picture below that I want to convert into web from a windows. I manage to do the design but I have a problem in the grid (I am using data tables in bootstrap) I can't do the design in what in the picture like.
<table>
<tr>
<td>
<div>
<input type="radio" />
Radio Button
</div>
</td>
<td>
<input type="radio" />
Radio Button
</td>
</tr>
<tr>
<td>
<div>
<input type="text" />
</div>
</td>
<td>
< div>
< input type="button" />
</div>
</td>
</tr>
</table >
<table >
<tr>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw" >< / i >Table
< /div >
< /div>
< /div>
< !-- /.panel-heading -->
< div class="panel-body">
< div class="dataTable_wrapper">
< table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxxx">
</table>
</div>
</div>
</div>
</div>
< /div>
</td>
<td>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
< i class="fa fa-list fa-fw"></i>Table
< /div>
< /div>
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover table-responsive nowrap"
role="grid" style="width: 100%;" id="dataTables-xxasdxx">
</table>
< /div>
< /div>
< /div>
< /div>
< /div>
</ td>
< /tr>
< /table>
My 2 Images bellow:
Try the below design hope it helps.You can customize the column property as your desire I just added the basic skeleton.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container">
<div class="row">
<div class=" col-sm-12 form-group">
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
<div class=" col-sm-2">
<input type="radio" />
Radio Button
</div >
</div >
<div class=" col-sm-12 form-group ">
<div class=" col-sm-2">
<input type="text" class="form-control" id="usr">
</div>
<div class=" col-sm-2">
<button type="button" class="btn btn-default">Submit</button>
</div>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1">#</th>
<th class="col-md-2">Header</th>
<th class="col-md-3">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,001</td>
<td class="col-md-3">1,001</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
Or See the below fiddle for a better look
table design demo fiddle (updated)
You can also, do something like this instead of using tables for layout and mimic as close as to your conversion UI.
table tags are meant primarily for data formatting. Bootstrap has the concept of grid layout which is meant for laying out your UI without using tables.
When you open the snippet in full screen, you would see the exact replica. However, when the screen is too small to fit in your entire content, it just wraps into the next row, giving you the flexibility to build responsive layout, which is not possible with table tags.
.custom-margin {
margin-top: 10px;
margin-bottom: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="custom-container">
<div class="radio">
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosOne" value="optionOne">Radio Button One
</label>
<label class="radio-inline">
<input type="radio" name="" id="optionsRadiosTwo" value="optionTwo">Radio Button Two
</label>
</div>
<div class="custom-margin">
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Enter Email :</label>
<input type="text" class="form-control" placeholder="Enter Email">
</div>
<button type="submit" class="btn btn-primary">Send invitation</button>
</form>
</div>
<div class="row">
<div class="col-lg-3">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
<div class="col-lg-6">
<table class="table table-hover">
<tr>
<td>Header One
</td>
<td>Header Two
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
<tr>
<td>Row Content
</td>
<td>Row Content
</td>
</tr>
</table>
</div>
</div>
</div>

Vertical scroll is not working properly in tbody breaking the previous tbody width

I have a table where I need to add a vertical scroll bar in tbody. I have watched some code but not fit for me or I am not understanding. I am also not so good in css. I have add a div and place my tbody there. It works for scroll but tbody width has become smaller.
Here is my table:
<table id="familyHist" class="table table-striped table-bordered">
<thead>
<tr>
<th colspan="{{(relationCount + 1)}}" class="info">
<g:if test="${session.userIsPatient}">
Please click the appropriate box to indicate family history for a given category or medical issue.
</g:if>
<g:else>
Please click the appropriate box to indicate positive family history.
</g:else>
</th>
</tr>
<tr>
<th></th>
{{#each relations}}
{{#if .relation !== 'Uncles' && .relation !== 'Aunts'}}
<th class="text-center">{{relation}}*</th>
{{else}}
<th class="text-center">{{relation}}</th>
{{/if}}
{{/each}}
</tr>
</thead>
<div style="width: inherit; overflow-y:scroll; height:100px; overflow-x: hidden;">
<tbody>
{{#each rows: index}}
<tr id="familyHistoryRow-{{symptomId}}">
<td>
<input type="hidden" name="familyHistId" value={{familyHistId}}/>
{{description}}
</td>
{{#if isUserDefined}}
<td colspan="8">
<div class="-fluid">
<form class="form-inline">
<div class="col-sm-9 col-md-8 col-lg-7 form-group">
<g:render template="/patient/familyHist/textarea" />
</div>
<div class="col-sm-3 col-md-4 col-lg-5 form-group">
<g:render template="/patient/familyHist/buttons" />
</div>
</form>
</div>
</td>
{{else}}
{{#each relationMap}}
<td class="text-center">
<g:render template="/patient/familyHist/checkbox" />
</td>
{{/each}}
{{/if}}
</tr>
{{/each}}
</tbody>
</div>
</table>
And here is the table before add the div before tbody:
And here is the table after add the div before tbody:
Change from:
<div style="width: inherit; overflow-y:scroll; height:100px; overflow-x: hidden;">
<tbody>
to
<tbody style="width: inherit; overflow-y:scroll; height:100px; overflow-x: hidden;">

Input width in bootstrap table always using max width

Ok I was trying to do a table with input fields. To set the sizes of each field I understood that I had to set the col-size in the header.
<thead>
<tr>
<th class="col-sm-2">Large</th>
<th class="col-sm-2">Large</th>
<th class="col-sm-1">Small</th>
<th class="col-sm-2">Large</th>
<th class="col-sm-1">Small</th>
<th class="col-sm-2">Large</th>
<th class="col-sm-2">Large</th>
</tr>
</thead>
However the inputs expand to their max width with no regard to col-size.
http://jsfiddle.net/m79HR/
Possibly this is an improper use of Bootstrap but I saw it as a best bet for inline inputs with headers above.
Also, lets say I want this particular grid to have 18 columns instead of the default 12 is that possible here just in this particular case?
Just add the "form-control" class to the inputs and bootstrap takes care of the rest.
Doing it this way makes it easier to add columns or change the width, since you only have to change in the header as opposed to every row/input.
<table class="table table-condensed">
<thead>
<tr>
<th class="col-sm-12 col-md-4">Large</th>
<th class="col-sm-12 col-md-2">Small</th>
<th class="col-sm-12 col-md-2">Small</th>
<th class="col-sm-12 col-md-2">Small</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="form-control" />
</td>
<td>
<input type="text" class="form-control" />
</td>
<td>
<input type="text" class="form-control" />
</td>
<td>
<input type="text" class="form-control" />
</td>
</tr>
</tbody>
</table>
You need to use the class col-md-* for normal screens col-sm-* for tablet screen and col-xs-* for mobile screen, there is also col-lg-* for larger screens, you can combine all these classes to make it responsive, like:
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<thead>
<tr>
<th>Very Small</th>
<th>Very Small</th>
<th>Very Small</th>
<th>Large</th>
<th>Small</th>
<th>Medium</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-sm-1">
<input class="col-sm-12" placeholder="col-sm-1" />
</td>
<td class="col-sm-1">
<input class="col-sm-12" placeholder="col-sm-1" />
</td>
<td class="col-sm-1">
<input class="col-sm-12" placeholder="col-sm-1" />
</td>
<td class="col-sm-4">
<input class="col-sm-12" placeholder="col-sm-4" />
</td>
<td class="col-sm-2">
<input class="col-sm-12" placeholder="col-sm-2" />
</td>
<td class="col-sm-3">
<input class="col-sm-12" placeholder="col-sm-3" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
For Bootstrap 4, you need to additionally add the d-flex class to the rows, like
<table>
<thead>
<tr class="d-flex">
<th class="col-3">3 columns wide header</th>
<th class="col-sm-5">5 columns wide header</th>
<th class="col-sm-4">4 columns wide header</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-3">3 columns wide content</th>
<td class="col-sm-5">5 columns wide content</th>
<td class="col-sm-4">4 columns wide content</th>
</tr>
</tbody>
</table>