0

Having an issue having some domain names lining up nicely in a 3 column setup, I have been trying this for a bit now with no success, I'm a newbie at this. The code is as followed

TPL file

<div>
                <p class="center">{foreach key=num item=listtld from=$tldslist}
    <input type="checkbox" name="tlds[]" value="{$listtld}"{if in_array($listtld,$tlds)} checked{/if}>
      {$listtld}
    {if $num % 5 == 0}
    {/if}{/foreach}</p>
            </div>              

and for the CSS

.center {
text-align: center;

and

 p {

}

What am I missing here? Or how would I achieve this and have it look good on a mobile device other than all bunched up together like a snowball? Thanks

(And I'm sure you all know this already but the is in a lot of things so I guess I would need to create a different css thing. Sorry, please excuse my ignorance. I'm new to this)

random_user_name
  • 25,694
  • 7
  • 76
  • 115

1 Answers1

0

Not sure if this is the result you desire but you could try using the answer in this stackoverflow question, just use a counter and assign the desired class to each column based on its modal.

<div>
     <p class="center">
        {foreach key=num item=listtld from=$tldslist}
          <div class="{if ($num+1) % 3 == 1}column-left{elseif ($num+1) % 3 == 2}column-center{elseif ($num+1) % 3 == 0}column-right{/if}">
              <input type="checkbox" name="tlds[]" value="{$listtld}"{if in_array($listtld,$tlds)} checked{/if}>
              {$listtld}
              {if $num % 5 == 0}
              {/if}
          </div>
       {/foreach}
    </p>
</div>

CSS:

.column-left{ float: left; width: 33%; }
.column-right{ float: right; width: 33%; }
.column-center{ display: inline-block; width: 33%; }

EDIT:

For a 6 column grid try using two containers to separate the 3 column grid, you can do so by using a mod of 6 for these containers.

Like this:

<div>
     <p class="center">
        {foreach key=num item=listtld from=$tldslist}
          {if ($num+1) % 6 == 1}
              <div class="container-left">
          {else if ($num+1) % 6 == 4}
              <div class="container-right">
          {/if}
            <div class="{if ($num+1) % 3 == 1}column-left{elseif ($num+1) % 3 == 2}column-center{elseif ($num+1) % 3 == 0}column-right{/if}">
              <input type="checkbox" name="tlds[]" value="{$listtld}"{if in_array($listtld,$tlds)} checked{/if}>
              {$listtld}
              {if $num % 5 == 0}
              {/if}
           </div>
         {if ($num+1) % 3 == 0}</div>{/if}
       {/foreach}
    </p>
</div>

CSS:

.column-left{ float: left; width: 30%; }
.column-right{ float: right; width: 30%; }
.column-center{ display: inline-block; width: 30%;}
.container-left{ float: left; width: 50%;  }
.container-right{ float: right; width: 50%;  }
Community
  • 1
  • 1
Aboca
  • 575
  • 2
  • 9
  • YOU ARE AMAZING! Thank you so much! Can I ask one more favor? 3 columns is good but being that there is a lot of entries how would I make this a 6 column or 5? Also it is just displaying on phones as a giant line running down. would switching to 6 column fix this? Thanks – user3646836 May 19 '14 at 22:21
  • Could you post your complete html and css and if possible make a snapshot of how it is being displaied? I can't really track the problem with the information I have right now. – Aboca May 20 '14 at 08:03