Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're trying a wrong solution to solve your issue.</p> <p>Have a look at how this problem is addressed in powerful SASS frameworks. Let's take <a href="http://susy.oddbird.net/" rel="nofollow noreferrer">Susy</a> by <a href="https://stackoverflow.com/users/1930386/eric-meyer">Eric Meyer</a> as a great example.</p> <p>Let's imagine you've got the following HTML:</p> <pre><code>&lt;div class="container"&gt; &lt;div class="parent"&gt; &lt;div class="child"&gt; Bla bla &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>When you call a mixin for the first time, you're doing it simply (the code is in the indented .sass syntax):</p> <pre><code>$total-columns: 8 // Declaring a varible that will be used by the mixin .parent +span-columns(4) // Span four of eight columns </code></pre> <p>But when you call that for a child element, the proportions would be crooked, because the parent is already proportioned:</p> <pre><code>.child +span-columns(2) // This will fail. You want 2 of 8 columns, // but due to nesting the math is crooked. // It will be "2 of (4 of 8)". </code></pre> <p>To address the issue, you provide an optional argument: a context that is used to do the math:</p> <pre><code>.child +span-columns(2, 4) // Now the mixin will take 2 parts of 4 // instead of 2 parts of four </code></pre> <p>The source code for this mixin is <a href="https://github.com/ericam/susy/blob/master/sass/susy/_grid.scss" rel="nofollow noreferrer">available</a> on GitHub.</p> <p>In short, it creates an optional argument like this (the code is in the CSS-like .scss syntax):</p> <pre><code>@mixin span-columns( $columns, $context: $total-columns //... ) { //... width: columns($cols, $context /*...*/); //... } </code></pre> <p>See how <code>$context</code> has a default value? Thanks to the default value this argument can be omitted. In other words, <code>$context</code> is an optional argument.</p> <p>When calling this mixin, if <code>$context</code> is not provided (e. g. <code>span-columns(2)</code>), then it is set equal to <code>$total-columns</code>. The <code>$total-columns</code> variable should be set prior to calling the mixin for the first time (see my example above).</p> <p>Then the two arguments are used to calculate the width.</p> <h2>UPD 2013-03-30</h2> <blockquote> <p>I am not trying to figure out things in regards to columns... I have modifier my question to make it clearer.</p> </blockquote> <p><strong>First of all</strong>, my recommendation concerns not only grid columns. It's a universal technique you can adopt.</p> <p><strong>Secondly</strong>, now i see that you're trying to nest media queries.</p> <p>Well, <em>some</em> media queries of different type can be combined in CSS3: e. g. <code>print</code> and width. But you can't put a <code>min-width: 601px</code> inside <code>max-width: 600px</code>, this just won't work!</p> <p>There's an extensive answer here on StackOverflow describing why you should not nest media queries of the same type: <a href="https://stackoverflow.com/a/11747166/901944">https://stackoverflow.com/a/11747166/901944</a></p> <p><strong>Thirdly</strong>, you're trying to invent the wheel. There's already a fantastic mixin for crunching media queries: <a href="https://github.com/snugug/respond-to" rel="nofollow noreferrer">Respond To</a> by <a href="https://stackoverflow.com/users/703084/snugug">Snugug</a>. It's super easy to use and very effective.</p> <p><strong>Fourthly</strong>, the <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY</a> thing. Instead of asking about your crooked mixin, please describe the problem that you're trying to solve with it! Show us the actual HTML and explain what behavior you would like to achieve.</p> <p>We will show you that it can be solved with a simple, elegant, semantic solution that does not require SASS hacking.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload