Trouble keeping the rows and columns line up :(

I am having trouble keeping the rows and columns line up

  1. When is desktop mode maximum columns should be three.
    When I click on “Cell Three” works fine but when I click on ”Cell Two” it does loose the three column order :frowning:
  2. When Tablet maximum columns should be two all the time.
    When I click on “Cell Two” works fine but when I click on “Cell Three” it does loose the two column order :frowning:
    When Mobile maximum is one column.
  3. It does work fine :smile:

I paste the whole code in one file hoping it will be easier to follow, my apologies if is hard to read
Let me know if I am clear with my explanation plz, in advance thank you for your help!

<!DOCTYPE html>
    <!-- include bootstrap -->
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style>
/* centered columns styles */
.row-centered {
    text-align:center;
}
.col-centered {
    display:inline-block;
    float:none;
    /* reset the text-align */
    text-align:left;
    /* inline-block space fix */
    margin-right:-4px;
    vertical-align: top;
}
.col-fixed {
    /* custom width */
    width:320px;
}
.col-min {
    /* custom min width */
    min-width:320px;
}
.col-max {
    /* custom max width */
    max-width:320px;
}
.item {
    width:100%;
    height:100%;
	border:1px solid #cecece;
    padding:16px 8px;
	background:#ededed;
	background:-webkit-gradient(linear, left top, left bottom,color-stop(0%, #f4f4f4), color-stop(100%, #ededed));
	background:-moz-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
	background:-ms-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
}
/* content styles */
.item {
	display:table;
}
.content {
	display:table-cell;
	vertical-align:middle;
	text-align:center;
}
.content:before {
    font-family:sans-serif;
    font-size:12px;
    letter-spacing:1px;
    color:#747474;
}
/* Style the tab content */
.tabcontent {
    display: none;
    padding: 6px 12px;
    border-top: none;
}
</style>

<div class="container">
    <div class="row row-centered">
<!-- Cell One -->
        <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content">Cell One</div></div></div>
<!-- Cell Two -->        
        <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content"><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'ImageMngt')">Cell Two</a></div></div></div>        
         <div id="ImageMngt" class="tabcontent">       
                <b>Content Cell Two</b><br />
                Content Cell Two Content Cell Two Content Cell Two Content Cell Two Content Cell Two Content Cell Two Content Cell Two
        </div>
<!-- Cell Three -->              
        <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content"><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'ImageOff')">Cell Three</a></div></div></div>
            <div id="ImageOff" class="tabcontent"><b>Content Three</b><br />
                Content Three Content Three Content Three Content Three Content Three Content Three Content Three Content Three Content Three
            </div>
<!-- Cell Four-->  
        <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content">Cell Four</div></div></div>
<!-- Cell Five-->
         <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content">Cell Five</div></div></div>
<!-- Cell Six -->        
         <div class="col-xs-6 col-centered col-fixed"><div class="item"><div class="content">Cell Six</div></div></div>
</div>
</div>
<script>
function openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";
}
</script>

Hi,

Its hard to understand what you are trying to do as you are just adding an extra div outside the existing structure so it of course will not line up with anything,

I assume you want content of cell3 to appear in the gray cell3 box? If so then move the div inside.

e.g.

  <!-- Cell Three -->
    <div class="col-xs-6 col-centered col-fixed">
      <div class="item">
        <div class="content"><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'ImageOff')">Cell Three</a>
          <div id="ImageOff" class="tabcontent"><b>Content Three</b><br />
            Content Three Content Three Content Three Content Three Content Three Content Three Content Three Content Three Content Three </div>
        </div>
      </div>
    </div>

Do the same for any other hidden content that you may want to show.

I’m not sure if that’s what you were trying to do though?

Hey PaulOB, I really appreciate your help, Thank you so much.
I had already tried that but what i want to do is to “.tabcontent” expand 100% horizontally across the page or below the three upper cells, instead of just using the 320 width. Do you have any suggestions? I believe you got what I am trying to do, let me know if you have any questions plz and again thank you :slight_smile:

If i get you, the div you want to show 100%, is actually showing 100%. The problem is it’s inside ‘col-xs-6’. Bootstrap width runs to 12 right?

1 Like

Yes my goal is to show the tab content between the rows as the screen grab i attached

And your issue is that, when you click on Cell Two, Cell Three moves down to a second row, instead of staying in the first row? But when you click on Cell Three, it stays where it should be?

1 Like

Exactly WebMachine, how can i keep “Cell Three” on row one ? and responsive once it moves to two columns ?

mp5163093,

The image in post #5 shows two rows with three cells in each row and with content between the two rows apparently relating to cell #3 in the first row.

The image does not indicate that cell #3 moves out of its position leaving only two cells in that upper row. Quite the contrary, it seems to indicate that clicking any cell places its respective content the full width of a row below the row with the tab that was clicked… very much like tabbed content.

The “responsive” part seems a bit tricky unless one thinks of the “cells” as menu buttons - and you realize that menus are often reconfigured so they will fit in narrow viewports - you mentioned responsive but did not show how the menu is to behave at narrow widths.

Would you mind tying your thoughts into a more cohesive set of drawings?

Hi Ronpat, thanks for taking the time to reply, i am including another screen grab when i click “Cell Two” then “Cell Three” moves out of order. How can i keep "Cell Three at its position ? When is tablet mode, it does switch to “Two Columns” and keep “.tabcontent” below the clicked cell. The souce code is also on this page. Thank you again :slight_smile:

I see what is happening but I don’t know how to go about it while keeping things responsive as it is currently.

The “revealed” content follows each of the “cells”.
Because the revealed content is block, the cells naturally re-position themselves after it.

I don’t know how many cells there are or if it would “work” for what you are wanting to do, but maybe having revealed content display before the first cell?

Hi Mittineague, do you think that what i am trying to accomplish is even possible ?

Could you have an empty <div> after each row and then use JavaScript to insert the appropriate content into that div depending on which link is clicked?

WebMachine, wherever it works but how do you do that ?

I’m thinking this can be done with a little smoke and mirrors and possibly a dash of JS, if you are inclined to use it IF the number of cells in each row does not have to change with the width of the viewport. In other words, the content can be hidden beneath each row and selectively displayed when the respective button is clicked, rather than trying to shift content from the button to the area beneath the row.

1 Like

Ronpat, sounds as it should work as you said, but it now goes over my amateur skills :frowning:

More than a dash, but then it does this

and it is still a bit buggy and still isn’t responsive.

1 Like

In my read of the issue, I am interpreting “responsive” to mean “fluid”.

I specified that the number of cells in a row had to remain fixed like his image… the OP didn’t disagree. If that is indeed acceptable, the JS seems like it would be simple: click a button to hide a visible content box in the rwo below the button row (if any are showing) and show the box whose button was clicked. Hide (reset) any visible content box if a visible content box is clicked or click an “X” in the corner. Like a tabbed display.

If he indeed wants the number of buttons in the row of buttons to change, then I have no idea how that might be done.

1 Like

I’ve come up with what is more proof of concept than polished code.
* the “resize” should be throttled or removed entirely. I added it because I got tired of reloading the page while testing

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Show Hide Content</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style type="text/css">
* {
 outline: 1px solid #00f;
}
.shown {
 float: left;
 width: 200px;
}
.shown a, .hidden {
 display: block;
}
.revealed {
 clear: both;
 background-color: #def;
 font-size: 1.2em;
 color: #252;
}
.revealed b {
 font-size: 1.5em;
 color: #000;
}
</style>
</head>
<body>
<h1>Show Hide Content</h1>
<div id="main_content">
  <div class="shown one">
    <a href="" class="one">Cell One</a>
  </div>
  <div class="hidden one">
    <b>Content Cell One</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
  <div class="shown two">
    <a href="" class="two">Cell Two</a>
  </div>
  <div class="hidden two">
    <b>Content Cell Two</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
  <div class="shown three">
    <a href="" class="three">Cell Three</a>
  </div>
  <div class="hidden three">
    <b>Content Cell Three</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
  <div class="shown four">
    <a href="" class="four">Cell Four</a>
  </div>
  <div class="hidden four">
    <b>Content Cell Four</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
  <div class="shown five">
    <a href="" class="five">Cell Five</a>
  </div>
  <div class="hidden five">
    <b>Content Cell Five</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
  <div class="shown six">
    <a href="" class="six">Cell Six</a>
  </div>
  <div class="hidden six">
    <b>Content Cell Six</b><br />
    Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell Content Cell
  </div>
</div>
<script type="application/javascript">
// script that needs the DOM to be loaded here
var main_content_div = document.getElementById('main_content');
var shown_divs = document.querySelectorAll('#main_content .shown');
var shown_divs_len = shown_divs.length;
var hidden_divs = document.querySelectorAll('#main_content .hidden');
var hidden_divs_len = hidden_divs.length;
/* hide hidden content */
for (var i = 0; i < hidden_divs_len; i++) {
  hidden_divs[i].style.display = "none";
}
function remove_current_revealed() {
  var revealed_divs = document.querySelectorAll('#main_content .revealed');
  for (var m = 0; m < revealed_divs.length; m++) {
   revealed_divs[m].parentNode.removeChild(revealed_divs[m]);
  }
}
function created_div(content) {
  var hidden_display_div = document.createElement('div');
  hidden_display_div.classList.add("revealed");
  hidden_display_div.innerHTML = content;
  return hidden_display_div;
}
function append_hidden_display_div(evt, content) {
  var main_content_div_offset_top = main_content_div.getBoundingClientRect().top;
  var revealed_div = document.querySelector('#main_content .revealed');
  var revealed_div_height = (revealed_div) ? revealed_div.clientHeight : 0;
  var revealed_div_offset_top = (revealed_div) ? revealed_div.getBoundingClientRect().top : 0;
  var item_offset_top = evt.target.getBoundingClientRect().top;
  if (item_offset_top > revealed_div_offset_top) { 
    item_offset_top = item_offset_top - revealed_div_height;
  } 
  var item_height = evt.target.clientHeight;
  var row_index = ((item_offset_top - main_content_div_offset_top) == 0) ? 0 : (item_offset_top - main_content_div_offset_top) / item_height;
//  console.log('row_index ' + row_index);
  var viewport_width = document.getElementsByTagName('body')[0].clientWidth;
  var items_width = viewport_width;
  if (shown_divs_len > 0) { 
    items_width = shown_divs[0].clientWidth;
  }
  var last_row_item = Math.floor(viewport_width / items_width);
  last_row_item = last_row_item * (row_index + 1);
  last_row_item = (last_row_item > shown_divs_len) ? shown_divs_len : last_row_item;
  remove_current_revealed();
  var hidden_display_div = created_div(content);
//  console.log('last_row_item ' + last_row_item);
  if ((typeof shown_divs[last_row_item] != "undefined") && (last_row_item < shown_divs_len) ){
    shown_divs[last_row_item].parentNode.insertBefore(hidden_display_div, shown_divs[last_row_item]);
  } else if (typeof shown_divs[last_row_item - 1] != "undefined") {
    shown_divs[last_row_item - 1].parentNode.appendChild(hidden_display_div);
  }
}
function show_hidden(evt) {
  evt.preventDefault();
  if (evt.target.tagName == 'B') { return; }
  if ( (evt.target.hasAttribute('class')) && (evt.target.getAttribute('class') == "revealed") ) { return; }
  var class_attr = evt.target.getAttribute('class');   
  var class_num = (class_attr) ? class_attr.replace(/(shown|hidden)/, "") : "";
  var hidden_div_content = "";
  for (var j = 0; j < hidden_divs_len; j++) {
    if (hidden_divs[j].getAttribute('class').indexOf(class_num) !== -1) {
      hidden_div_content = hidden_divs[j].innerHTML;
    }
  }  
  append_hidden_display_div(evt, hidden_div_content);
}
main_content_div.addEventListener('click', function(evt) { 
                                show_hidden(evt); });  
window.addEventListener('resize', function(evt) { 
                                remove_current_revealed(); });  
</script>
</body>
</html>
4 Likes

I just forked an old codepen into using flexbox and wonder if this is the sort of thing that was required.

3 Likes

I just tested your POC in Firefox. It works brilliantly!

1 Like