Bootstrap layout, a suggestion - css

I have to organize a quite common (I suppose) layout for my web app (AngularJS + Bootstrap).
The (responsive) layout is made up by a table of rows; this way, more or less:
------------------------------------------------ row 1 ---
| pho- | description |
| to | button1 button2 button3 button4 button5 button6 |
----------------------------------------------------------
...
------------------------------------------------ row N ---
| pho- | description |
| to | button1 button2 button3 button4 button5 button6 |
----------------------------------------------------------
This is the markup I've come up with:
<div class="container">
<div class="row" ng-repeat="(id, person) in persons">
<div class="col-xs-4 col-sm-3 col-md-2 col-lg-2">
<img ng-src="{{person.photo_src}}" />
</div>
<div class="col-xs-8 col-sm-9 col-md-9 col-lg-9">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div>
{{person.description}}
</div>
</div>
</div>
<div class="row-fluid">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button1
</button>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button2
</button>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button3
</button>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button4
</button>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button5
</button>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button6
</button>
</div>
</div>
</div>
</div>
</div>
I'm not satisfied with the results, as you can see... :-(
#1200px width:
#360px width:
(the last button can be present or not...).
I would like to split the buttons on two different rows, at widths below 640 (for example), but I can't figure out how to get there... I've never fully grasped Bootstrap's layout logic... :-(
Any graphical/layout improvement suggestion would be kindly accepted, too... :-)

I think you should use the 12 column concept of bootstrap.
You should divide the column in that way, where the row is divided in 12 column.
For smaller screens you can use the col-xs
I hope to solve the responsive problem above mentioned by you can be solved by the given code.
<div class="container">
<div class="row" ng-repeat="(id, person) in persons">
<div class="col-xs-4 col-sm-3 col-md-3 col-lg-3">
<img ng-src="{{person.photo_src}}" />
</div>
<div class="col-xs-8 col-sm-9 col-md-9 col-lg-9">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div>
{{person.description}}
</div>
</div>
</div>
<div class="row-fluid">
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button1
</button>
</div>
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button2
</button>
</div>
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button3
</button>
</div>
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button4
</button>
</div>
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button5
</button>
</div>
<div class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
<button type="button" class="btn">
button6
</button>
</div>
</div>
</div>
</div>
</div>

Here's a grid layout that might work for you..
<div class="container">
<div class="row" ng-repeat="(id, person) in persons">
<div class="col-xs-12 col-sm-3 col-md-2">
<img src="http://placehold.it/100" class="img-responsive">
</div>
<div class="col-xs-12 col-sm-9 col-md-9">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div>
person.description
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
<div class="clearfix visible-sm visible-xs"> </div>
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
<div class="col-xs-4 col-sm-4 col-md-2">
<button type="button" class="btn">
button
</button>
</div>
</div>
</div>
</div>
</div>
Demo: http://codeply.com/go/XWGksepx3h
Also note, there is no row-fluid in Bootstrap 3, and you only need to specify class for the smallest viewport you want to support. Therefore the col-lg-* aren't needed since col-md-* will be used for col-md-* and col-ld-*.

You may try to add this line to your css's:
#media (max-width: 640px) {
.col-sm-2 {
width:33.33333333333331%;
}
}
FIDDLE

Related

using bootstrap 4, how can one create mobile input friendly buttons that are side-by-side?

Can't seem to figure this one out.
I want to allow a mobile user of my app to interact with two, large (ideally square) buttons which live side by side using bootstrap 4 framework.
Beneath each button, is an <input> which acts as a counter for the # of times the button above was pressed.
I can't get the button/input pairs to line up vertically in mobile mode, like this:
----------------
| (Mobile view)|
| <card> |
| [B1] [B2] |
| [I1] [I2] |
| |
| </card> |
It sounds like you want nesting like this...
https://www.codeply.com/go/FkjWVM03VF
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-6">
<div class="row">
<div class="col-12 col-sm-6">
<button class="btn btn-primary btn-block" type="button">Button</button>
</div>
<div class="col-12 col-sm-6">
<input class="form-control" placeholder="input 1">
</div>
</div>
</div>
<div class="col-6">
<div class="row">
<div class="col-12 col-sm-6">
<button class="btn btn-primary btn-block" type="button">Button</button>
</div>
<div class="col-12 col-sm-6">
<input class="form-control" placeholder="input 2">
</div>
</div>
</div>
</div>
</div>
</div>
I would do something like this:
<div class="card">
<div class="card-block">
<div class="row">
<div class="col">
<button class="btn btn-primary btn-lg btn-block" type="button">Button1</button>
</div>
<div class="col">
<button class="btn btn-secondary btn-lg btn-block" type="button">Button2</button>
</div>
<div class="w-100"></div>
<div class="col">
<input class="form-control" placeholder="Input1" type="text">
</div>
<div class="col">
<input class="form-control" placeholder="Input2" type="text">
</div>
</div>
</div>
</div>
Taken from this Bootstrap4 Grid system example: https://v4-alpha.getbootstrap.com/layout/grid/#equal-width-multi-row

Overlapping in Bootstrap Div Structure

I am following the 12 column rule, the following code is for right panel section having width of 8 column.remaining is 4 column panel on left side. It shows well on more than 1300 pixels resolution, but when shrink then the all controls in right panel overlapped. Any Advice ?
<div class="financeScreenRightBlock">
<div class="form-group row ">
<label class="col-md-3 control-label">Retail Price</label>
<div class="col-md-3 ">
<wj-input-number id="retailPrice" style="border-color: red" [placeholder]="'Retail Price'" [isRequired]="true" [(value)]="application.finance.assetCost.retailPrice" (lostFocus)="retailPrice_Focus();getAmtFin_CalculatePayment()">
</wj-input-number>
</div>
<div class="col-md-3 control-label">
<label>Trade In</label>
</div>
<div class="col-md-2 text-right">
<wj-input-number id="retailPrice" [placeholder]="'DepositAmount'" [(value)]="application.finance.assetCost.tradeInDepositAmount" [isReadOnly]="true">
</wj-input-number>
</div>
<div class="col-md-1 text-right">
<button (click)="tradeInWin()" class="btn" style=" padding: 4px 8px;border-radius: 100px;">...</button>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 control-label">Delivery Charges</label>
<div class="col-md-3 ">
<wj-input-number id="deliveryCharges" [placeholder]="'Delivery Charges'" [(value)]="application.finance.assetCost.deliveryAmount" (lostFocus)="getAmtFin_CalculatePayment()">
</wj-input-number>
</div>
<label class="col-md-3 control-label">Deposit</label>
<div class="col-md-3">
<wj-input-number id="deposit" [placeholder]="'Deposit'" [(value)]="application.finance.assetCost.cashDepositAmount" (lostFocus)="totalDepositCalculate()">
</wj-input-number>
</div>
</div>
<div class="form-group row">
<div class="col-md-3 control-label">
<label>Accessories</label>
</div>
<div class="col-md-2 text-right">
<wj-input-number id="accessories" [placeholder]="'Accessories'" [(value)]="application.finance.assetCost.totalAccessoryAmount" [isReadOnly]="true">
</wj-input-number>
</div>
<div class="col-md-1 text-right">
<button class="btn" (click)="accessoriesWin()" style=" padding: 4px 8px;border-radius: 100px;">...</button>
</div>
<div class="col-md-3 control-label">
<label>Total Deposit</label>
</div>
<div class="col-md-3">
<wj-input-number id="totalDeposit" [placeholder]="'Total Deposit'" [(value)]="application.finance.assetCost.totalDepositAmount" [isReadOnly]="true">
</wj-input-number>
</div>
</div>
<div class="form-group row">
<div class="col-md-3 control-label custom-checkbox">
<input type="checkbox" id="onroad" name="onroad" [(ngModel)]="application.finance.onRoadCostInclusionIndicator" (ngModelChange)="getAmtFin_CalculatePayment()" />
<label for="onroad">On Roads</label>
</div>
<div class="col-md-2 text-right">
<wj-input-number [placeholder]="'Interest Rate'" [isRequired]="true" [isReadOnly]="true" (lostFocus)="interestRate_Focus()" [value]="((application.finance.onRoadCostInclusionIndicator)?(application.finance.assetCost.registrationAmount*1+application.finance.financeContract.financeTax.stampDutyAmount*1):0)">
</wj-input-number>
</div>
<div class="col-md-1 text-right">
<button class="btn" (click)="onRoadWin()" style=" padding: 4px 8px;border-radius: 100px;">...</button>
</div>
<div class="col-md-3 control-label custom-checkbox">
<input type="checkbox" id="feebox" name="feebox" [(ngModel)]="application.fee.showIndicator" (ngModelChange)="getFeeCheckbox()" />
<label for="feebox">Fee</label>
</div>
<div class="col-md-2 text-right">
<wj-input-number id="fee" [placeholder]="'fee'" [(value)]="application.fee.totalFeeAmount" [isReadOnly]="true">
</wj-input-number>
</div>
<div class="col-md-1 text-right">
<button (click)="feeWin()" class="btn" style=" padding: 4px 8px;border-radius: 100px;">...</button>
</div>
</div>
<div class="form-group row">
<div class="col-md-3 control-label custom-checkbox">
<input type="checkbox" id="insuranceCheckbox" name="insuranceCheckbox" [(ngModel)]="application.finance.financeContract.financeInsurance.showIndicator" (ngModelChange)="getAmtFin_CalculatePayment()" />
<label for="insuranceCheckbox">Insurance</label>
</div>
<div class="col-md-2 text-right">
<wj-input-number [placeholder]="'Insurance'" [isRequired]="true" [isReadOnly]="true" (lostFocus)="interestRate_Focus()" [value]="((application.finance.financeContract.financeInsurance.showIndicator)?application.finance.financeContract.totalFinancePremiumAmount:0)">
</wj-input-number>
</div>
<div class="col-md-1 text-right">
<button (click)="insuranceWin_close();insuranceWin();" class="btn" style=" padding: 4px 8px;border-radius: 100px;">...
</button>
</div>
<div class="col-md-3 control-label custom-checkbox">
<label for="feebox">Amount Financed</label>
</div>
<div class="col-md-3 text-right">
<wj-input-number [placeholder]="'Amount Financed'" [isRequired]="true" [isReadOnly]="true" [(value)]="application.finance.financeContract.financedAmount">
</wj-input-number>
</div>
</div>
</div>
You can add more css classes to your divs in order to achieve the desired look/behaviour. You can use chrome developer tools to see how your page looks on smaller devices. I usually creating a skeleton for my page for mobile devices first and then moving on to setup the layout for tablets etc.
example
col-xs-2 col-md-4 col-lg-6 can be on the same class definition.
hope that helps.
This is happening because you are using col-md-x that is you are using medium sized columns. For complete responsiveness you should use col-md-x for medium sized screens, col-lg-x for large screen sizes and col-sm-x for smaller screens. For eg. if you want your page to be properly displayed in a tab you should use col-md-x and col-lg-x for laptop screens.
Also, I think it is better to nest your divs properly. You are saying you have one 4 column panel and one 8 column panel. So, for example your code should look like this.
<div class="row">
<div class="col-sm-4 col-md-4 col-lg-4">
<!---Do your stuff here-->
</div>
<div class="col-sm-8 col-md-8 col-lg-8">
<!--you can do further nesting here-->
<!--example-->
<div class="col-sm-4 col-md-4 col-lg-4">
<p>some more code goes here</p>
</div>
<div class="col-sm-7 col-sm-offset-1 col-md-7 col-md-offset-1 col-lg-7 col-lg-offset-1">
<p>above div shows how to give blank columns if you want your page to have some blank spaces between columns. use col-sm/md/lg-offset-x for this.</p>
</div>
</div>
</div>
I understand you are using angular-ui bootstrap and the above example is for twitter-bootstrap. Keeping that in mind, I thought a nesting div example will be helpful to you. Cheers!

Bootstrap table layout

I'm trying to achieve the setup illustrated below with Bootstrap 3, but I can't quite find a way to do it, especially to keep it responsive. I looked at panels and tables, etc. but then tend to not have really worked out great so far.
I figured it out in the end. Just took a bit of messing around with rows within the panels.
<div class="panel-group" id="accordion" role="tablist">
<div class="panel panel-default container-fluid">
<div class="row panel-heading ">
<div class="col-sm-1 pull-left"></div>
<div class="col-sm-4 col-xs-12">Asset ID</div>
<div class="col-sm-2 col-xs-12">Status</div>
<div class="col-sm-2 col-xs-12">Asset Nodes</div>
<div class="col-sm-3 col-xs-12">Manage</div>
</div>
</div>
<div class="panel panel-default container-fluid">
<div class="panel-heading row" role="tab" id="headingOne">
<div class="col-xs-1">
<div data-toggle="collapse" class="handpointer glyphicon glyphicon-chevron-right"></div>
</div>
<div class="col-sm-4 col-xs-12">
xxx
</div>
<div class="col-sm-2 col-xs-12">Normal</div>
<div class="col-sm-2 col-xs-12">?</div>
<div class="col-sm-3 col-xs-12"><a class="btn btn-xs btn-default" href="#" role="button">button</a></div>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
dsfsdfd
</div>
</div>
</div>
</div>
http://www.bootply.com/NLxmcWu4SJ

Column Offset and centering not working in Small Screens (Bootstrap)

I have a list which needs to be centered in all screen sizes. I have the following code for it -
<div class="container container-fluid.body-content">
<div class="row">
<h2 style="text-align:center;">Select your Campus</h2>
</div>
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-sm-12 col-sm-offset-0 col-md-10 col-md-offset-1 btn-group-vertical" style="background-color:#EAEBED;padding:2%;" id="dispcolleges" role="group" aria-label="...">
<button type="button" class="btn btn-default" onclick="storeValue('4847453903781888','National Institute of Technology Karnataka')">National Institute of Technology Karnataka</button>
<button type="button" class="btn btn-default" onclick="storeValue('5743114304094208','Test')">Test</button></div>
</div>
</div>
It is centered with offset in large and medium screens, but not on small screens. How do I fix this?
Full code can be found here
Try this:
<div class="container container-fluid.body-content">
<div class="row">
<h2 style="text-align:center;">Select your Campus</h2>
</div>
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-sm-offset-3 col-sm-6 col-xs-10 col-md-6 col-md-offset-6 btn-group-vertical col-xs-offset-1" style="background-color:#EAEBED;padding:2%;" id="dispcolleges" role="group" aria-label="..."><button type="button" class="btn btn-default" onclick="storeValue('4847453903781888','National Institute of Technology Karnataka')">National Institute of Technology Karnataka</button><button type="button" class="btn btn-default" onclick="storeValue('5743114304094208','Test')">Test</button></div>
</div>
</div>
The reason is display: inline-block; of class btn-group-vertical
Solution: Add display: inherit; for your <div>. Try this:
<div class="container container-fluid.body-content">
<div class="row">
<h2 style="text-align:center;">Select your Campus</h2>
</div>
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-sm-12 col-sm-offset-0 col-md-10 col-md-offset-1 btn-group-vertical" style="background-color:#EAEBED;padding:2%;display: inherit;" id="dispcolleges" role="group" aria-label="..."><button type="button" class="btn btn-default" onclick="storeValue('4847453903781888','National Institute of Technology Karnataka')">National Institute of Technology Karnataka</button><button type="button" class="btn btn-default" onclick="storeValue('5743114304094208','Test')">Test</button></div>
</div>
</div>

Responsive Textbox in bootstrap for extra small size(col-xs) not working

Hello friends the textbox is working fine when the size is large, medium and small, but when I the textbox in extra small sized device then it is getting cut. Following is the code for my text field. Please help me out with this, every help is highly appreciated. Thanks in advance
<div class="form-group">
<div class="col-sm-6 col-lg-6 col-md-6 col-xs-12">
<label for="inputEmail" class="col-sm-6 col-lg-3 col-xs-12 col-md-3 control-label" style="">Anything</label>
<div class="col-sm-12 col-lg-9 col-xs-12 col-md-9">
<div class="input-group">
<div class="input-group-addon">$</div>
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
</div>
</div>
</div>
<div class="col-sm-12 col-lg-6 col-md-6 col-xs-12">
<div class="col-lg-4 col-md-4 col-sm-6">
<label for="inputEmail" class="control-label" style="">per</label>
<div class="btn-group btn-group-xs" role="group" aria-label="...">
<button type="button" class="btn btn-default tax_percentage active" > month </button>
<button type="button" class="btn btn-default tax_flat"> year </button>
<input type='hidden' id='month_year_button' name='month_year_button' />
</div>
</div>
<div class="col-lg-8 col-md-8 col-sm-6">
<p>How much will spend on office rent?</p>
</div>
</div>
</div>
you should decrease the size of the column for xs so that they all fit in a single row.
<div class="col-sm-6 col-lg-6 col-md-6 col-xs-8">
<label for="inputEmail" class="col-sm-6 col-lg-3 col-xs-4 col-md-3 control-label" style="">Anything</label>
<div class="col-sm-12 col-lg-9 col-xs-8 col-md-9 input-sm">
<label class="sr-only" for="exampleInputAmount"></label>
<div class="input-group">
<div class="input-group-addon">$</div>
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
</div>
</div>
</div>
hope this works for you.

Resources