Twitter Bootstrap - Left column display after right container on mobile devices [duplicate] - css

This question already has an answer here:
Issue with push/pulling my layout
(1 answer)
Closed 6 years ago.
This is my code:
<div class="row">
<div class="col-sm-12 col-lg-3">
A
</div>
<div class="col-sm-12 col-lg-9">
B
</div>
</div>
This is my template on desktop device:
+-------+-------+-------+-------+
| | |
| A | B |
| | |
+-------+-------+-------+-------+
This is my template on mobile device:
+-------+-------+-------+-------+
| |
| A |
| |
+-------+-------+-------+-------+
| |
| B |
| |
+-------+-------+-------+-------+
But I want my template to look like this on mobile device:
+-------+-------+-------+-------+
| |
| B |
| |
+-------+-------+-------+-------+
| |
| A |
| |
+-------+-------+-------+-------+
Is there any way to achieve this without having to change my initial structure?

You can use the col push & pull class to achieve this quite easily. There is a good explanation here which should help.
To spell it out, you need to move B above A, then pull A across 9 cols for large screen (col-lg-pull-9) and push B across 3 cols for larger screens( col-lg-push-3). Therefore, the code will be:
<div class="row">
<div class="col-sm-12 col-lg-9 col-lg-push-3">
B
</div>
<div class="col-sm-12 col-lg-3 col-lg-pull-9">
A
</div>
</div>
OK, reading your comments below, you stated you can't changes the order of the divs. Can you use jQuery? If so, try this:
$(document).ready(function(){
if ($(window).width() < 768){
alert("mobile");
$("#divB").insertBefore("#divA");
}
else {
alert("not mobile");
}
});
http://jsfiddle.net/humotrj0/173/

You can change the order in the HTML (first div B), being this the order for mobile, and change the order in desktop with col-lg-push-* and col-lg-pull-*.
See http://getbootstrap.com/css/#grid-column-ordering

You need to use the col-lg-push and col-lg-pull options
You cannot change the order of columns in smaller screens but you can do that in large screens.
So change the order of your columns.
<div class="row">
<div class="col-lg-9 col-lg-push-3">
B
</div>
<div class=" col-lg-3 col-lg-pull-9">
A
</div>
</div>
By default this displays the main content first.
So in mobile main content is displayed first.
By using col-lg-push and col-lg-pull we can reorder the columns in large screens and display sidebar on the left and main content on the right. View it working in Bootsnipp

Related

Start columns at end of container with Bulma.io

I would like to know if there is a good way to start the columns of Bulma.io at the end of its container. The usual setup is:
<div class="container">
<div class="columns">
<div class="column">
First
</div>
<div class="column">
Second
</div>
<div class="column">
Third
</div>
</div>
</div>
which spreads the columns evenly throughout the container.
-----------------------------------------------------
| | | | | |
| | | | | |
-----------------------------------------------------
I know it is possible to make them shorter and left-aligned with is-(size) classes. I would like to to the same but make the right-aligned so the following happens:
-----------------------------------------------------
| | | | | | | |
| | | | | | | |
-----------------------------------------------------
I have looked up the documentation but I couldn't find any built in way.
I'm afraid there's no built in way for .columns. For some reason .is-right class is only available for .tags, .buttons and some more. What you could do is to create and use your own utility/helper class:
.columns.is-right {
justify-content: flex-end;
}

How to iterate through collection across two columns in Meteor

I'd like to have a two-column layout to display the returned collection information. Right now I have a two-column layout like:
<template name="Participants">
<div class="container">
<h4 style="text-align: center">{{ReportsMonth}} {{ReportsCamp}} {{ReportsYear}} {{ReportsTitle}}</h4>
{{#each programReports}}
<div class="row">
<div class="col s6">
<h5>Name: {{FullName}}</h5>
<p>Age: {{calculateAge Bdate}}<br> Sex: {{Sex}}<br> Level: {{Level}}<br> Location: {{City}}, {{State}}</p>
</div>
<div class="col s6">
<h5>Name: {{FullName}}</h5>
<p>Age: {{calculateAge Bdate}}<br> Sex: {{Sex}}<br> Level: {{Level}}<br> Location: {{City}}, {{State}}</p>
</div>
</div>
{{/each}}
</div>
</template>
The problem of course is that when it iterates through, it repeats the document across to the next column; it only gets to the next document when it finishes row. Is there a way to have it iterate to fill each div in each row with the next document?
Example:
Current HTML Output:
a a
b b
Desired:
a c
b d
Or:
a b
c d
Best way I can think of for the first example (vertical data rows, a c on same row):
Split your programReports into two helpers: one for the first half, one for the second half.
Make a row and a col s6 outside your #each loops.
Put your items in your each loops in a row and xs12.
I'd love it if someone had a better way to do this, as I've had to do it myself.
Horizontal data rows example (a b on same row):
I think for this one you simply need to get rid of the second col s6 in your each loop. I could be misunderstanding something though.

AngularJS pagination in separate columns

I have pagination working in my app. I display 10 elements per page. Now I would like to format these 10 elements into 2 columns (2x 5 elements per 1 page).
I don't know how to start.
<pagination data-boundary-links="true" data-num-pages="noOfPages" data-current-page="currentPage" max-size="maxSize" class="pagination-small" data-previous-text="«" data-next-text="»"></pagination>
Code reference:
http://jsfiddle.net/eqCWL/224/
In your fiddle you are using the older bootstrap2 css, so I'll use it here for the solution:
First, you need to read the bootstrap documentation on scaffolding/grid system
format your HTML to show two lists in two rows:
<div class="row">
<div class="span6">
<li>{{data.name}}</li>
</div>
<div class="span6">
<li>{{data.name}}</li>
</div>
</div>
then, you will need to set the first ng-repeat to show only half of items:
ng-repeat="data in filtered = (list | filter:search) |
startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit/2"
notice limitTo:entryLimit/2
and the second one to show the rest:
ng-repeat="data in filtered = (list | filter:search) |
startFrom:(currentPage-1)*entryLimit + entryLimit/2 | limitTo:entryLimit/2"
you need to change the startFrom filter, to start entryLimit / 2 items later:
startFrom:(currentPage-1)*entryLimit + entryLimit/2
You can test a working example here

CSS display:inline/none with tables works with Firefox but not Chrome or Safari

I am working on a quick and dirty application which involves several single-column tables displayed horizontally within an outer table.
|-------------------------------------------|
| outer table |
|-------------------------------------------|
| --------- --------- --------- |
| | table 1| |table 2| |table 3| |
| --------- --------- --------- |
| | row 1 | | row 1 | | row 1 | |
| --------- --------- --------- |
| ... |
| --------- --------- --------- |
| | row n | | row n | | row n | |
| --------- --------- --------- |
| |
|-------------------------------------------|
--------- ---------
|SHOW #2| |SHOW #3|
--------- ---------
I realize this could be done using css without tables, but I am not adept enough and this doesn't need to be elegant. At the start, only the first table is displayed. Clicking buttons toggles the display from "none" to "inline" (I also tried "block") of #2 and #3. In this example, I set the style of #2 in a DIV around the table and in #3 within a TD around the table. Both methods work in Firefox 22.0 but not in Chrome 27.0 or Safari 5.0 (all on Mac). Is there any solution using tables? Or, if you'd like to design the style sheet, that works too :-)
<html>
<body>
<table id = "main" border=0 cellspacing=20>
<tr>
<td>
<table id = "tbl1" border=0>
<tr><td> table #1, row #1 </td></tr>
<tr><td> table #1, row #2 </td></tr>
</table>
</td>
<td>
<!-- Hide the table with a hidden DIV -->
<div id = "tbl2" style="display:none">
<table border=0>
<tr><td> table #2, row #1 </td></tr>
<tr><td> table #2, row #2 </td></tr>
</table>
</div>
</td>
<!-- Hide the table with a hidden TD -->
<td id = "tbl3" style="display:none">
<table border=0>
<tr><td> table #3, row #1 </td></tr>
<tr><td> table #3, row #2 </td></tr>
</table>
</td>
</tr>
</table>
<br>
<input type=button value ='show table #2' onclick='document.getElementById("tbl2").style="display:inline"'>
<input type=button value ='show table #3' onclick='document.getElementById("tbl3").style="display:inline"'>
<br>
<br>
<input type=button value ='hide table #2' onclick='document.getElementById("tbl2").style="display:none"'>
<input type=button value ='hide table #3' onclick='document.getElementById("tbl3").style="display:none"'>
</body>
</html>
Here's a a working example. While making it, I didn't know you did not want to use jQuery, but I strongly recommend you to change your mind, since all you have to do is adding this to your html, preferably just before the closing </body> tag:
<script src="http://code.jquery.com/jquery-1.7.2.min.js">
$(document).ready(function () {
$('input').on("click", function () {
var inputValue = $(this).val();
var index = inputValue.indexOf("#")
var divId = "#tbl" + inputValue.substr(index+1);
$(divId).toggle();
});
});
</script>
I also changed the html a bit: I'm using 1 input per table: "show or hide" in 1 button.
But you can ofcourse use 2 buttons for it: just change the jQuery and call hide() or show() accordingly. If you really don't wanna use jQuery, you could convert my example to pure JavaScript, but it seems like that's gonna take a bit more coding for you :)
You can use TABS here and still have your table-Element.
Try this: http://jqueryui.com/tabs/
It should help you with your problem

CSS grid inside a grid

I am using a 960 Grid System, I am trying to achieve something like the following --
|-----| |-------------------|
| | | |--| |-----| |
| | | | | | | |
| | | |--| |-----| |
| | | |
| | | |------| |--| |
| | | | | | | |
| | | |------| |--| |
|-----| |-------------------|
Is there a way of doing so? The only reason I need the second set of divs in my right column is because the left column is quite long and I dont want the space between the 2nd set of columns.
I would really appreciate any guidance if there is a better way of achieving this.
This capability is built into the Grid 960 system. You just give the left and right nested grid items the classes "alpha" and "omega", respectively.
Here's an example:
<div class="container_12">
<div class="grid_3">
</div>
<div class="grid_9">
<div class="grid_4 alpha">
</div>
<div class="grid_5 omega">
</div>
<div class="grid_5 alpha">
</div>
<div class="grid_4 omega">
</div>
</div>
</div><!-- end .container_12 -->
In case you're willing to consider other frameworks, here's how you achieve the desired result with Cascade Framework :
<div class="site-center"> <!-- Center all content in a responsive container -->
<div class="col width-1of4"> <!-- Your left column goes here -->
</div>
<div class="col width-fill"> <!-- Your main content goes here -->
<div class="col"> <!-- First row -->
<div class="col width-1of3"> <!-- First element of first row -->
</div>
<div class="col width-fill"> <!-- Second element of first row -->
</div>
</div>
<div class="col"> <!-- Second row -->
<div class="col width-2of3"> <!-- First element of second row -->
</div>
<div class="col width-fill"> <!-- Second element of second row -->
</div>
</div>
</div>
</div>
A grid element in Cascade framework is either
One of the following HTML elements : section, main, article, header, footer, aside or nav (these elements are polyfilled with the HTMLshiv for old IE in case you need it).
A div element with a 'col' class (can be used in old IE without a polyfill).
To add a width to a grid element, you add a class of the format 'width-XofY', where Y can be 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16 or 24 and X can be any value lower than X.
More concretely, here are some examples of valid classes you can use in Cascade Framework : 'width-1of2' (width : 50%), 'width-3of4' (width : 25%), 'width-2of5' (width : 40%), 'width-2of5' (width : 40%), 'width-2of7' (width:28.5714286%) and 'width-13of16' (width:81.25%)
Additional to these classes, you can also use the classes 'width-fit' and 'width-fill' that respectively fit to content and fill whatever remains of your 100% width. Or, you could just define your own classes and IDs and just add a custom width for those classes to do things the 'semantic' way.
If your builds include the responsiveness module (which is the case for the recommended builds), the width of all grid elements automatic resets to 100% on mobile. You can use classes like 'mobile-width-3of16', 'phone-width-3of7' or 'tablet-width-2of4' to customize the layout for different width ranges and the classes 'desktop-hidden', 'mobile-hidden', 'phone-hidden' or 'tablet-hidden' to hide content for a specific screen with range.

Resources