Friday, February 28, 2014

Size does matter with Bootstrap

So I figured out this cool way to dynamically change the size of a column in Bootstrap with angular.  It's pretty slick.  Check it out:
 
<span ng-class="{true: 'col-lg-2', false: 'col-lg-3'}[TypeID == 1]">...</span>
 
That's it!
 
Okay, so what it does:  It's using AngularJS, as you probably noticed by the 'ng-class' tag.  So the TypeID is a model.  This code is actually inside an ng-repeat.  So if the TypeID is equal to 1, then make the column only 2 big in Bootstrap.  If you're unfamiliar with this, click here for Bootstrap Knowledge.  So, if it's not 1, it's 3 big.  This TypeID is set dynamically in my code not show by a dropdown list selection. 
 
If you have trouble with this, post a comment and I'll give a more thorough example, perhaps on jsfiddle.
 

No comments:

Post a Comment