CSS Calc with Variables and Multiplication











up vote
0
down vote

favorite
1












I'm validating my CSS using the Nu Html Checker:



https://validator.w3.org/nu/



Consider the following CSS:



:root {
--target-size: 48px;
}

.test1 {
flex: 0 0 calc(var(--target-size) + 1px);
}

.test2 {
min-height: calc(var(--target-size) - 0.5rem);
}

.test3 {
flex: 0 0 calc(320px - 3 * var(--target-size));
}


The validator reports no error with .test1 and .test2.



However, for .test3, the validator reports this error:



Error: flex: The types are incompatible.



I know that the CSS rules stipulates that for multiplication, at least one of the arguments must be a <number>. I don't see that violated. I've tried nesting the multiplication in another calc(), but the error persists.



Any idea what's wrong with that rule and how to correct it?










share|improve this question




















  • 1




    Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
    – Roy
    Nov 10 at 23:48










  • You said it first, I didn't see this sorry
    – Patrick
    Nov 10 at 23:51










  • No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
    – claytoncarney
    Nov 10 at 23:55















up vote
0
down vote

favorite
1












I'm validating my CSS using the Nu Html Checker:



https://validator.w3.org/nu/



Consider the following CSS:



:root {
--target-size: 48px;
}

.test1 {
flex: 0 0 calc(var(--target-size) + 1px);
}

.test2 {
min-height: calc(var(--target-size) - 0.5rem);
}

.test3 {
flex: 0 0 calc(320px - 3 * var(--target-size));
}


The validator reports no error with .test1 and .test2.



However, for .test3, the validator reports this error:



Error: flex: The types are incompatible.



I know that the CSS rules stipulates that for multiplication, at least one of the arguments must be a <number>. I don't see that violated. I've tried nesting the multiplication in another calc(), but the error persists.



Any idea what's wrong with that rule and how to correct it?










share|improve this question




















  • 1




    Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
    – Roy
    Nov 10 at 23:48










  • You said it first, I didn't see this sorry
    – Patrick
    Nov 10 at 23:51










  • No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
    – claytoncarney
    Nov 10 at 23:55













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I'm validating my CSS using the Nu Html Checker:



https://validator.w3.org/nu/



Consider the following CSS:



:root {
--target-size: 48px;
}

.test1 {
flex: 0 0 calc(var(--target-size) + 1px);
}

.test2 {
min-height: calc(var(--target-size) - 0.5rem);
}

.test3 {
flex: 0 0 calc(320px - 3 * var(--target-size));
}


The validator reports no error with .test1 and .test2.



However, for .test3, the validator reports this error:



Error: flex: The types are incompatible.



I know that the CSS rules stipulates that for multiplication, at least one of the arguments must be a <number>. I don't see that violated. I've tried nesting the multiplication in another calc(), but the error persists.



Any idea what's wrong with that rule and how to correct it?










share|improve this question















I'm validating my CSS using the Nu Html Checker:



https://validator.w3.org/nu/



Consider the following CSS:



:root {
--target-size: 48px;
}

.test1 {
flex: 0 0 calc(var(--target-size) + 1px);
}

.test2 {
min-height: calc(var(--target-size) - 0.5rem);
}

.test3 {
flex: 0 0 calc(320px - 3 * var(--target-size));
}


The validator reports no error with .test1 and .test2.



However, for .test3, the validator reports this error:



Error: flex: The types are incompatible.



I know that the CSS rules stipulates that for multiplication, at least one of the arguments must be a <number>. I don't see that violated. I've tried nesting the multiplication in another calc(), but the error persists.



Any idea what's wrong with that rule and how to correct it?







css3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 23:49

























asked Nov 10 at 23:39









claytoncarney

15714




15714








  • 1




    Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
    – Roy
    Nov 10 at 23:48










  • You said it first, I didn't see this sorry
    – Patrick
    Nov 10 at 23:51










  • No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
    – claytoncarney
    Nov 10 at 23:55














  • 1




    Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
    – Roy
    Nov 10 at 23:48










  • You said it first, I didn't see this sorry
    – Patrick
    Nov 10 at 23:51










  • No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
    – claytoncarney
    Nov 10 at 23:55








1




1




Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
– Roy
Nov 10 at 23:48




Have you tried flex: 0 0 calc(320px - (var(—target-size) * 3)))? I think it has to do with the loose ‘3’...
– Roy
Nov 10 at 23:48












You said it first, I didn't see this sorry
– Patrick
Nov 10 at 23:51




You said it first, I didn't see this sorry
– Patrick
Nov 10 at 23:51












No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
– claytoncarney
Nov 10 at 23:55




No, actually your suggestion pointed in the right direction. It is the operand order that appears to be critical. '3 * var(--target-size)' fails. 'var(--target-size) * 3' passes. Thanks!
– claytoncarney
Nov 10 at 23:55












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










If you switch the order of multiplication it seems like it works:



flex: 0 0 calc(320px - var(--target-size) * 3);



Your right about the <number> argument but missed that the number has to be on the right side of the multiplication.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244501%2fcss-calc-with-variables-and-multiplication%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    If you switch the order of multiplication it seems like it works:



    flex: 0 0 calc(320px - var(--target-size) * 3);



    Your right about the <number> argument but missed that the number has to be on the right side of the multiplication.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      If you switch the order of multiplication it seems like it works:



      flex: 0 0 calc(320px - var(--target-size) * 3);



      Your right about the <number> argument but missed that the number has to be on the right side of the multiplication.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        If you switch the order of multiplication it seems like it works:



        flex: 0 0 calc(320px - var(--target-size) * 3);



        Your right about the <number> argument but missed that the number has to be on the right side of the multiplication.






        share|improve this answer












        If you switch the order of multiplication it seems like it works:



        flex: 0 0 calc(320px - var(--target-size) * 3);



        Your right about the <number> argument but missed that the number has to be on the right side of the multiplication.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 23:49









        Patrick

        808




        808






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244501%2fcss-calc-with-variables-and-multiplication%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine