<p>This is somewhat of a guess, but is based on what I could find. It might not answer everything but it might be a start :)</p>

<p>From what I can work out the grid work is worked out around the values you provide yourself, if you look at <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/resources/js/craft.js#L10244" rel="nofollow"><code>app/resources/js/craft.js</code></a> on line 10244 this seems to be where the grid starts.</p>

<p>On line <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/resources/js/craft.js#L10339" rel="nofollow">10339</a> is the <code>refreshCols</code> function which seems to be responsible of figuring out how wide items are are where they should be placed.</p>

<p>It looks like Craft will take the values you supply <code>data-max-cols="3"</code> <code>data-min-colspan="2"</code> etc and try to work out the best possible layout (This is where <code>data-position</code> gets dealt with aswell) ...</p>

<pre><code>line 10466
// Figure out all of the possible colspans for each item,
// as well as all the possible positions for each item at each of its colspans
...

line 10532
// Now find the layout that looks the best.
// First find the layouts with the highest number of used columns
....
</code></pre>

<p>etc etc, so it looks like there aren't really any set defaults, you just gotta play around with the numbers and see what works best for the layout you are trying to achieve.</p>

<p>Lastly, on line <code>10775</code> is:</p>

<pre><code>defaults: {
    itemSelector: '.item',
    cols: null,
    maxCols: null,
    minColWidth: 320,
    mode: 'pct',
    fillMode: 'top',
    colClass: 'col',
    snapToGrid: null,
    onRefreshCols: $.noop
}
</code></pre>

<p>I realise I could be looking in the wrong direction and apologies if this doesn't completely answer your question, but hopefully it will provide an insight.</p>

CC BY-SA 3.0
2016-02-02T15:54:25.430Z
2016-02-02T15:54:25.430Z
Alec Ritson
<p>Plugins are able to extend Craft and embrace the existing UI nicely. While I'm comfortable extending it in many ways, I don't feel like I could clearly explain to somebody else how the grid system works on the back end and have recently seen a few CP UIs rendered on larger screens (2400px+) that suggest that I may not fully understand how it behaves between devices.</p>

<p>After you extend the CP layout:</p>

<pre><code>{% extends "_layouts/cp" %}
</code></pre>

<p>You can build a grid using <code>grid</code>, <code>item</code>, and <code>pane</code> classes and various attributes. Here is an example with likely too many attributes just to put several of them out there into the discussion:</p>

<pre><code>&lt;div class="grid first" data-max-cols="3"&gt;
  &lt;div class="item" data-position="left" data-min-colspan="2" data-max-colspan="3"&gt;
    &lt;div id="fields" class="pane"&gt;
      ...
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="item" data-position="right" data-colspan="1"&gt;
    &lt;div class="pane meta"&gt;
      ...
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Here are a few of the questions I wonder about while working with the grid:</p>

<ul>
<li>How many columns does the grid support?</li>
<li>Are there any considerations to keep in mind as our plugin's UI adjusts to mobile layouts or big screens with high resolutions?</li>
<li>How do <code>data-position="left"</code> and <code>data-position="right"</code> work? When do we need to use them?</li>
<li>How do the <code>data-colspan</code> attributes work? Are there defaults in place for <code>data-colspan</code>, <code>data-min-colspan</code>, <code>data-max-colspan</code>?</li>
<li>Are there any other features of the grid I'm overlooking or leaving out?</li>
</ul>

<plugin-development><control-panel><user-interface>
How does the Craft Grid System work?
# How does the Craft Grid System work?

(Asked by: username_0 on 2016-01-31)

Plugins are able to extend Craft and embrace the existing UI nicely. While I'm comfortable extending it in many ways, I don't feel like I could clearly explain to somebody else how the grid system works on the back end and have recently seen a few CP UIs rendered on larger screens (2400px+) that suggest that I may not fully understand how it behaves between devices.
After you extend the CP layout:
{% extends "_layouts/cp" %}

You can build a grid using grid, item, and pane classes and various attributes. Here is an example with likely too many attributes just to put several of them out there into the discussion:

  
    
      ...
    
  
  
    
      ...
    
  


Here are a few of the questions I wonder about while working with the grid:

How many columns does the grid support?
Are there any considerations to keep in mind as our plugin's UI adjusts to mobile layouts or big screens with high resolutions?
How do data-position="left" and data-position="right" work? When do we need to use them?
How do the data-colspan attributes work? Are there defaults in place for data-colspan, data-min-colspan, data-max-colspan?
Are there any other features of the grid I'm overlooking or leaving out?

**Tags:** plugin-development, control-panel, user-interface

---

## 1 answers

### Answer by username_1 on 2016-02-02. Score: 3

This is somewhat of a guess, but is based on what I could find. It might not answer everything but it might be a start :)
From what I can work out the grid work is worked out around the values you provide yourself, if you look at app/resources/js/craft.js on line 10244 this seems to be where the grid starts.
On line 10339 is the refreshCols function which seems to be responsible of figuring out how wide items are are where they should be placed.
It looks like Craft will take the values you supply data-max-cols="3" data-min-colspan="2" etc and try to work out the best possible layout (This is where data-position gets dealt with aswell) ...
line 10466
// Figure out all of the possible colspans for each item,
// as well as all the possible positions for each item at each of its colspans
...

line 10532
// Now find the layout that looks the best.
// First find the layouts with the highest number of used columns
....

etc etc, so it looks like there aren't really any set defaults, you just gotta play around with the numbers and see what works best for the layout you are trying to achieve.
Lastly, on line 10775 is:
defaults: {
    itemSelector: '.item',
    cols: null,
    maxCols: null,
    minColWidth: 320,
    mode: 'pct',
    fillMode: 'top',
    colClass: 'col',
    snapToGrid: null,
    onRefreshCols: $.noop
}

I realise I could be looking in the wrong direction and apologies if this doesn't completely answer your question, but hopefully it will provide an insight.


---

