bootsrap 3.1 pull main content first (on TOP) when mobile - html

I have following grid structure
<div class="row">
<div id="A" class="col-md-3">
<div class="alert alert-info">A</div>
</div>
<div id="B" class="col-md-6">
<div class="alert alert-danger">B</div>
</div>
<div id="C" class="col-md-3">
<div class="alert alert-info">C</div>
</div>
</div>
I want to show B first when mobile (But when big device other than mobile then it should show as above) and also WHEN mobile all A,B,Cwill be in equal width. I have tried as following
<div class="col-md-3 col-md-push-6">
<div class="alert alert-info">A</div>
</div>
<div class="col-md-6 col-md-pull-3">
<div class="alert alert-danger">B</div>
</div>
<div class="col-md-3">
<div class="alert alert-info">C</div>
</div>
Also tried in many combination nothing working
WHEN big screen like desktop
When mobile

Try this one :
<div class="col-sm-6 col-sm-push-3">
<div class="alert alert-danger">B</div>
</div>
<div class="col-sm-3 col-sm-pull-6">
<div class="alert alert-info">A</div>
</div>
<div class="col-sm-3">
<div class="alert alert-info">C</div>
</div>
Or DEMO here.

I used javascript to implement this functionality. I am first finding bootstrap environment and according to it i am arranging divs.
var current='';
function findBootstrapEnvironment() {
var envs = ['xs', 'sm', 'md', 'lg'];
var $el = $('<div>');
$el.appendTo($('body'));
for (var i = envs.length - 1; i >= 0; i--) {
var env = envs[i];
$el.addClass('hidden-'+env);
if ($el.is(':hidden')) {
$el.remove();
return env;
}
}
}
if(findBootstrapEnvironment()=="sm"&&findBootstrapEnvironment()!=current){
current=findBootstrapEnvironment();
var a=$('.row').children()[0];
var b=$('.row').children()[2];
$('.row').children()[0].remove();
$('.row').children()[1].remove();
$('.row').append(a);
$('.row').append(b);
console.log(current);
}
$( window ).resize(function() {
if((findBootstrapEnvironment()=="sm"||findBootstrapEnvironment()=="md")&&findBootstrapEnvironment()!=current){
current=findBootstrapEnvironment();
var a=$('.row').children()[0];
var b=$('.row').children()[2];
$('.row').children()[0].remove();
$('.row').children()[1].remove();
$('.row').append(a);
$('.row').append(b);
console.log(current);
}
});
Demo : https://jsfiddle.net/oog0gdph/

<div class="col-xs-12 col-sm-6 col-sm-push-4 " >B</div>
<div class="col-xs-12 col-sm-pull-6 col-sm-3" >A</div>
<div class="col-xs-12 col-sm-3">C</div>

Related

Show current selective div only and hide other divs using jquery

I have two divs [one is upper | second is lower]. Both can fetch data from database and make accordingly number of divs. lower div is default hidden. I want to show lower div when I click upper div. jquery code that i make is here. Need your help.
Note. Show only current active lower div. All other lower divs must hidden. to do this
<!---upper div section--->
<?php
$id=1;
while ($comp_post_info=mysqli_fetch_array($query))
{
?>
<div class="container-fluid">
<div class="row">
<div class="upperdiv container-fluid mb-5">
<div class="row">
<div class="col-md-1 pdl-3">
<i class="fa fa-circle"></i>
</div>
<div class="col-md-11">
<div class="container-fluid">
<div class="row jlist" id="addbg">
<div class="col-md-4">
<img src="/my_brands/brand.png" alt="" class="cust-em">
<h6><?php echo $comp_post_info['title'] ?> <p><small><?php echo $comp_post_info['c_name'] ?></small></p></h6>
</div>
<div class="col-md-4">
<h6>
<?php echo $comp_post_info['state'] ?>,<?php echo $comp_post_info['coun'] ?>
<p><small>Location</small></p>
</h6>
</div>
<div class="col-md-4">
<h6>
<?php echo $comp_post_info['saly'] ?>
<p><small> Saly</small></p>
</h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!----lowerdiv--->
<div class="lowerdiv container-fluid hideme" id="mydiv" >
<div class="row pt-4 padl-5">
<h6>Other Prepositions <small>for gle</small></h6>
</div>
<div class="row">
<div class="col-md-11 offset-md-1">
<div class="container-fluid">
<div class="row sub_lowerdiv pt-2">
<div class="col-md-4">
<i class="fa fa-circle"></i>
<h6><?php echo $comp_post_info['title'] ?> <p><small><?php echo $comp_post_info['c_name'] ?></small></p></h6>
</div>
<div class="col-md-4">
<h6>
<?php echo $comp_post_info['state'] ?>,<?php echo $comp_post_info['count'] ?>
<p><small>Location</small></p>
</h6>
</div>
<div class="col-md-4">
<h6>
<?php echo $comp_post_info['saly'] ?>
<p><small>Saly</small></p>
</h6>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
** <script>
$(document).ready(function(){
$(".upperdiv").on("click",function(){
var currentselect = $(this).('.lowerdiv');
$(".lowerdiv").not(currentselect).hide();
currentselect.show();
});
});
</script> **
enter code here
Use closest to find the parent (I have added parent class .parent-div) and then use nextAll to find the first lowerdiv.
See the Snippet below:
$(document).ready(function(){
$(".upperdiv").on("click",function(){
var currentselect = $(this).closest(".parent-div").nextAll('.lowerdiv').first(); /* Look I've added find */
$(".lowerdiv").not(currentselect).hide();
currentselect.show();
});
});
.lowerdiv{
display: none;
margin-left: 15px;
}
.upperdiv{
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent-div container-fluid">
<div class="row">
<div class="upperdiv">
Upper 1
</div>
</div>
</div>
<div class="lowerdiv">
Lower 1
</div>
<div class="parent-div container-fluid">
<div class="row">
<div class="upperdiv">
Upper 2
</div>
</div>
</div>
<div class="lowerdiv">
Lower 2
</div>
<div class="parent-div container-fluid">
<div class="row">
<div class="upperdiv">
Upper 3
</div>
</div>
</div>
<div class="lowerdiv">
Lower 3
</div>

Why isn't BootStrap column offset working?

I am trying to build a website with flash-cards to help learn the Hebrew alphabet. My Card partial view looks like this:
#model FlashCards.MultipleChoice.ViewModels.CardViewModel
<div class="index-card">
<div class="row">
<div class="col-md-offset-5"></div>
<div class="col-md-2 text-center">
#Model.Numeric
</div>
</div>
<div class="row">
<div class="col-md-offset-2"></div>
<div class="col-md-8 text-center card-symbol">
#Html.Raw(Model.UnicodeEscape)
</div>
</div>
<div class="row">
<div class="col-md-offset-2"></div>
<div class="col-md-8 text-center">
#Model.Name
</div>
</div>
</div>
Now the col-md-offset works on all but the first row, causing the card to render as in the below image:
Now why isn't the 1 in the image offset like the glyph and the name for the letter Aleph?
My CSS file for these cards only contains the following so far:
.index-card {
height: 150px;
}
.index-card .card-symbol {
font-size: large
}
I believe you're using the offset classes wrong; do not apply them to empty divs.
Your text is centered. Second and third rows have widths of 8 columns. It looks like the offset is working but it really isn't. The first row is only 2 columns wide. None of your offset divs are having any effect on the layout.
You need to do something like this, at the very least:
<div class="index-card">
<div class="row">
<div class="col-md-offset-5 col-md-2 text-center">
#Model.Numeric
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8 text-center card-symbol">
#Html.Raw(Model.UnicodeEscape)
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8 text-center">
#Model.Name
</div>
</div>
</div>

cordova: accordion list for html

I need a accordion list for the html code below. I just want it to be able to open (expand) when click on the 'Technical'. When click again, it will close(collapse).
This is my html code
<!-- Techincal -->
<div class="item">
<div class="row">
<div class="col boldText">Technical</div>
</div>
<!--List-->
<div class="item">
<div class="row centerized">
<div class="col col-40"></div>
<div class="col col-30">Min</div><div class="col col-30">Max</div>
</div>
<div class="row">
<div class="col col-40">Tech spec</div>
<div class="col col-30"><input type="number" placeholder="0" ng-model="searchQuery.techMin"></div>
<div class="col col-30"><input type="number" placeholder="5" ng-model="searchQuery.techMax"></div>
</div>
<div class="row">
<div class="col col-40">Radius</div>
<div class="col col-30"><input type="number" placeholder="-1000" ng-model="searchQuery.radiusMin"></div>
<div class="col col-30"><input type="number" placeholder="1000" ng-model="searchQuery.radiusMax"></div>
</div>
</div>
</div>
I have no javascript code just simple html. It is written in ionic/cordova. How make it a simple preset collapsable and expandable when click?
There are multiple methods to solve this, i find this method as per your requirement
Your HTML code
<!-- Techincal -->
<ul>
<li class="item-stable item-icon-right"
ng-click="toggleGroup(0)"
ng-class="{active: isGroupShown(0)}">
<button class="item-text-center item-text-wrap">Techincal </button>
</li>
<div class="item-accordion"
ng-show="isGroupShown(0)">
<div class="item">
<div class="row">
<!--List-->
<div class="item">
<div class="row centerized">
<div class="col col-40"></div>
<div class="col col-30">Min</div><div class="col col-30">Max</div>
</div>
<div class="row">
<div class="col col-40">Tech spec</div>
<div class="col col-30"><input type="number" placeholder="0" ng-model="searchQuery.techMin"></div>
<div class="col col-30"><input type="number" placeholder="5" ng-model="searchQuery.techMax"></div>
</div>
<div class="row">
<div class="col col-40">Radius</div>
<div class="col col-30"><input type="number" placeholder="-1000" ng-model="searchQuery.radiusMin"></div>
<div class="col col-30"><input type="number" placeholder="1000" ng-model="searchQuery.radiusMax"></div>
</div>
</div>
</div>
</div>
</div>
</ul>
Here is your js code
<script>
$scope.toggleGroup = function(group) {
if ($scope.isGroupShown(group)) {
$scope.shownGroup = null;
} else {
$scope.shownGroup = group;
}
};
$scope.isGroupShown = function(group) {
return $scope.shownGroup === group;
};
</script>
Something like this, without extra modules. Just a simple solution to toggle some content. Animation can be done using CSS if needed. This is just to get you started with your initial question.
VIEW
<!-- Techincal -->
<div class="item">
<div class="row">
<div style="padding:10px; background: gray;" class="col boldText" ng-click="vm.toggleContainer()">Technical</div>
</div>
<!--List-->
<div class="item" style="margin-top:25px;" ng-if='vm.showTechnicalDetails'>
<div class="row centerized">
<div class="col col-40"></div>
<div class="col col-30">Min</div>
<div class="col col-30">Max</div>
</div>
<div class="row">
<div class="col col-40">Tech spec</div>
<div class="col col-30">
<input type="number" placeholder="0" ng-model="searchQuery.techMin">
</div>
<div class="col col-30">
<input type="number" placeholder="5" ng-model="searchQuery.techMax">
</div>
</div>
<div class="row">
<div class="col col-40">Radius</div>
<div class="col col-30">
<input type="number" placeholder="-1000" ng-model="searchQuery.radiusMin">
</div>
<div class="col col-30">
<input type="number" placeholder="1000" ng-model="searchQuery.radiusMax">
</div>
</div>
</div>
</div>
</div>
JS Angular part (vm approach)
angular
.module('app', [])
.controller('MainController', MainController)
function MainController() {
var vm = this;
vm.toggleContainer = toggleContainer;
vm.showTechnicalDetails = false;
function toggleContainer() {
vm.showTechnicalDetails = !vm.showTechnicalDetails;
}
}
JSFiddle : https://jsfiddle.net/DaanDeSmedt/Ln2dgmer/
JS Angular part ($scopeapproach)
angular
.module('app', [])
.controller('MainController', MainController)
function MainController($scope) {
$scope.showTechnicalDetails = false;
$scope.toggleContainer = function(){
$scope.showTechnicalDetails = !$scope.showTechnicalDetails;
}
}
JSFIDDLE : https://jsfiddle.net/DaanDeSmedt/Ln2dgmer/3/

Align multiple elements across bootstrap columns in the same row

I would like to horizontally align multiple items across two columns within the same row in bootstrap. An example HTML Code can be found below:
<div class="container">
<div class="row">
<div class="col-sm-6">
<h1>Short Heading</h1>
<p>Some super long content that will push the button far downward so that it will certainly not align with the next column anymore</p>
<button class="btn btn-primary">Button</button>
</div>
<div class="col-sm-6">
<h1>Super long Heading that requires 2 rows</h1>
<p>Some short content</p>
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
or in this fiddle http://jsfiddle.net/6pYhx/689/
Within the example, I would like to have 2 conditions
The header, p and button elements should be on the same horizontal height. In my example the right header is two rows, therefore the right p element is one row lower than the left p
If the screen size shrinks, all elements of column 1 should be right below each other, followed by all elements of column 2 -> I tried to solve it by having multiple rows, but then you'd have header 1, header 2, p 1, p 2, ... Instead I would like to have header 1, p 1, button 1, followed by header 2, p 2, button 2
Any ideas how to solve it with CSS?
I have three solutions.
Use flexbox at media >= 768px.
#media (min-width: 768px) {
.make-it-flex {
display: flex;
flex-wrap: wrap;
}
.flex-item-1 { order: 1; }
.flex-item-2 { order: 2; }
.flex-item-3 { order: 3; }
.flex-item-4 { order: 4; }
.flex-item-5 { order: 5; }
.flex-item-6 { order: 6; }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="container">
<h2>Flexbox</h2>
<div class="row make-it-flex">
<div class="col-xs-12 col-sm-6 flex-item-1"><div class="well">Header 1</div></div>
<div class="col-xs-12 col-sm-6 flex-item-3"><div class="well">Paragraph 1<br>has three lines<br>it's true</div></div>
<div class="col-xs-12 col-sm-6 flex-item-5"><div class="well">Button 1</div></div>
<div class="col-xs-12 col-sm-6 flex-item-2"><div class="well">Header 2<br>has two lines</div></div>
<div class="col-xs-12 col-sm-6 flex-item-4"><div class="well">Paragraph 2</div></div>
<div class="col-xs-12 col-sm-6 flex-item-6"><div class="well">Button 2<br>has two lines</div></div>
</div>
</div>
http://jsfiddle.net/glebkema/uuLqokhm/
Duplicate data and make two layouts for different screen sizes.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="container visible-xs">
<h2>Columns</h2>
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="row">
<div class="col-xs-12"><div class="well">Header 1</div></div>
<div class="col-xs-12"><div class="well">Paragraph 1<br>has three lines<br>it's true</div></div>
<div class="col-xs-12"><div class="well">Button 1</div></div>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="row">
<div class="col-xs-12"><div class="well">Header 2<br>has two lines</div></div>
<div class="col-xs-12"><div class="well">Paragraph 2</div></div>
<div class="col-xs-12"><div class="well">Button 2<br>has two lines</div></div>
</div>
</div>
</div>
</div>
<div class="container hidden-xs">
<h2>Lines</h2>
<div class="row">
<div class="col-xs-12 col-sm-6"><div class="well">Header 1</div></div>
<div class="col-xs-12 col-sm-6"><div class="well">Header 2<br>has two lines</div></div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6"><div class="well">Paragraph 1<br>has three lines<br>it's true</div></div>
<div class="col-xs-12 col-sm-6"><div class="well">Paragraph 2</div></div>
</div>
<div id="line-3" class="row">
<div class="col-xs-12 col-sm-6"><div class="well">Button 1</div></div>
<div class="col-xs-12 col-sm-6"><div class="well">Button 2<br>has two lines</div></div>
</div>
</div>
http://jsfiddle.net/glebkema/cjs1q42m/
Add the script and transmit data from one layout to another.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="container">
<h2>Columns</h2>
<div class="row">
<div class="col-xs-12 col-sm-6">
<div id="column-1" class="row">
<div class="col-xs-12 column-1 line-1"><div class="well">Header 1</div></div>
<div class="col-xs-12 column-1 line-2"><div class="well">Paragraph 1<br>has three lines<br>it's true</div></div>
<div class="col-xs-12 column-1 line-3"><div class="well">Button 1</div></div>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div id="column-2" class="row">
<div class="col-xs-12 column-2 line-1"><div class="well">Header 2<br>has two lines</div></div>
<div class="col-xs-12 column-2 line-2"><div class="well">Paragraph 2</div></div>
<div class="col-xs-12 column-2 line-3"><div class="well">Button 2<br>has two lines</div></div>
</div>
</div>
</div>
</div>
<div class="container">
<h2>Lines</h2>
<div id="line-1" class="row">
</div>
<div id="line-2" class="row">
</div>
<div id="line-3" class="row">
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$( document ).ready(function() {
var idColumn1 = $('#column-1');
var idColumn2 = $('#column-2');
var idLine1 = $('#line-1');
var idLine2 = $('#line-2');
var idLine3 = $('#line-3');
var classColumn1 = $('.column-1');
var classColumn2 = $('.column-2');
var classLine1 = $('.line-1');
var classLine2 = $('.line-2');
var classLine3 = $('.line-3');
checkLayout();
$( window ).resize(function() {
checkLayout();
});
function checkLayout() {
var classSm6 = 'col-sm-6';
if (( window.innerWidth <= 768 ) && classColumn1.hasClass(classSm6)) {
// console.info( "resize to xs" );
classColumn1.appendTo(idColumn1).removeClass(classSm6);
classColumn2.appendTo(idColumn2).removeClass(classSm6);
} else if (( window.innerWidth > 768 ) && !classLine1.hasClass(classSm6)) {
// console.info( "resize to sm" );
classLine1.appendTo(idLine1).addClass(classSm6);
classLine2.appendTo(idLine2).addClass(classSm6);
classLine3.appendTo(idLine3).addClass(classSm6);
}
}
});
</script>
http://jsfiddle.net/glebkema/cjwc6uev/
Do you want them to be centered in the columns? You could use text-center class on each column.
<div class="col-sm-6 text-center">
If you want them vertically centered, there are a few ways to do it. I recently had this issue and we changed display to table-cell and used the vertical-align: middle; in CSS (example here). Or you can use flexbox, but it doesn't work in all browsers.
Is this what you are trying? Make the preview screen bigger to see the result if you are testing it in jsfiddle:
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="row">
<h1 class="col-md-3">Short Heading</h1>
<p class="col-md-7">Some super long content that will push the button far downward so that it will certainly not align with the next column anymore</p>
<button class="btn btn-primary class="col-md-2"">Button</button>
</div>
</div>
<div class="col-sm-6">
<div class="row">
<h1 class="col-md-3">Super long Heading that requires 2 rows</h1>
<p class="col-md-7">Some short content</p>
<button class="btn btn-primary col-md-2">Button</button>
</div>
</div>
</div>
</div>
also, you can play with the inner columns to make them the right size for your needs, but this is, as you needed, on the same row. I made this for medium or wider screens and on small screens it will be defaulted to the normal behaviour of having them one under another, but again, you can play with that by changing the md part or adding more classes like col-xs-... col-sm-... col-lg-...
here's how that looks:
you can also try this if you want your content to be horizontally aligned as well, it is a bit tricky but it works:
https://plnkr.co/edit/s01bZi2OJc8xm2QlKuII?p=preview

bootstrap nested panels in grid of equal heights

I have two rows of nested panels inside of a primary panel. The 1st row has 3 panels of unequal heights. How do I make the 3 panels to be the same height of the highest panel (panel #3 in the jsfiddle link)?
Here's the jsfiddle - http://jsfiddle.net/niner911/MgcDU/8905/
I would like panel #1 and panel #2 the same height of panel #3, or whichever the tallest panel would be.
Thanks for the help.
Here's my markup:
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">outer</div>
<div class="row">
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">1</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">111</div>
</div>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">2</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">222</div>
<div class="list-group-item">222</div>
</div>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="panel panel-info">
<div class="panel-heading">3</div>
<div class="panel-body">
<div class="list-group">
<div class="list-group-item">333</div>
<div class="list-group-item">333</div>
<div class="list-group-item">333</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="panel panel-info">
<div class="panel-heading">
<span>lower</span>
</div>
<div class="panel-body">
xyz
</div>
</div>
</div>
</div>
</div>
Try using map() to process each item and get the size of the tallest panel. Than apply this height to each panel.
JS
var heightTallest = Math.max.apply(null, $(".panel-info").map(function ()
{
return $(this).outerHeight();
}).get());
$('.panel-info').css({ height: heightTallest + 'px' });
Updated jsfiddle:
http://jsfiddle.net/MgcDU/8915/
using jquery apply height to children of .row
$('.row').each(function(){
var RowHeight = $(this).innerHeight();
$(this).children().css({ height: RowHeight + 'px' });
});
and set .panel height to what size you desire, eg. 100%
If you're okay with the browser compatibility limitations, you could try this CSS flexbox-based experimental code: https://github.com/twbs/bootstrap/pull/11851