Increasing the background-size in CSS makes the background image disappear












0















this is what I have:






.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>





This is the result:



slot with bg image



Now the issue comes when the background-size property changes to more than 62px. For example when it becomes 63px and more - the background image disappears:



slot with no bg image



Interesting that if we increase the height of the div then we can have a bigger background-size and still see the background image.



Here is a jsFiddle I made: https://jsfiddle.net/avc4y3h0/



Please help!



Edit: It seems that I can reproduce this issue only on Google Chrome, Avast Browser and Opera. It works fine on Mozilla Firefox and Microsoft Edge. Can not check on Safari. Also I have the feeling that this was working before on Chrome and it is probably something recent? But I can't tell for sure.










share|improve this question




















  • 1





    background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

    – Pete
    Nov 22 '18 at 12:54













  • Sorry the above should say shouldn't have a comma

    – Pete
    Nov 22 '18 at 13:00











  • use 100% instead of auto

    – Temani Afif
    Nov 22 '18 at 13:02











  • @Pete Thanks for the remark. I tried it but it didn't fix the issue.

    – Simeon Nikolov
    Nov 22 '18 at 15:15











  • @TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

    – Simeon Nikolov
    Nov 22 '18 at 15:22
















0















this is what I have:






.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>





This is the result:



slot with bg image



Now the issue comes when the background-size property changes to more than 62px. For example when it becomes 63px and more - the background image disappears:



slot with no bg image



Interesting that if we increase the height of the div then we can have a bigger background-size and still see the background image.



Here is a jsFiddle I made: https://jsfiddle.net/avc4y3h0/



Please help!



Edit: It seems that I can reproduce this issue only on Google Chrome, Avast Browser and Opera. It works fine on Mozilla Firefox and Microsoft Edge. Can not check on Safari. Also I have the feeling that this was working before on Chrome and it is probably something recent? But I can't tell for sure.










share|improve this question




















  • 1





    background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

    – Pete
    Nov 22 '18 at 12:54













  • Sorry the above should say shouldn't have a comma

    – Pete
    Nov 22 '18 at 13:00











  • use 100% instead of auto

    – Temani Afif
    Nov 22 '18 at 13:02











  • @Pete Thanks for the remark. I tried it but it didn't fix the issue.

    – Simeon Nikolov
    Nov 22 '18 at 15:15











  • @TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

    – Simeon Nikolov
    Nov 22 '18 at 15:22














0












0








0


1






this is what I have:






.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>





This is the result:



slot with bg image



Now the issue comes when the background-size property changes to more than 62px. For example when it becomes 63px and more - the background image disappears:



slot with no bg image



Interesting that if we increase the height of the div then we can have a bigger background-size and still see the background image.



Here is a jsFiddle I made: https://jsfiddle.net/avc4y3h0/



Please help!



Edit: It seems that I can reproduce this issue only on Google Chrome, Avast Browser and Opera. It works fine on Mozilla Firefox and Microsoft Edge. Can not check on Safari. Also I have the feeling that this was working before on Chrome and it is probably something recent? But I can't tell for sure.










share|improve this question
















this is what I have:






.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>





This is the result:



slot with bg image



Now the issue comes when the background-size property changes to more than 62px. For example when it becomes 63px and more - the background image disappears:



slot with no bg image



Interesting that if we increase the height of the div then we can have a bigger background-size and still see the background image.



Here is a jsFiddle I made: https://jsfiddle.net/avc4y3h0/



Please help!



Edit: It seems that I can reproduce this issue only on Google Chrome, Avast Browser and Opera. It works fine on Mozilla Firefox and Microsoft Edge. Can not check on Safari. Also I have the feeling that this was working before on Chrome and it is probably something recent? But I can't tell for sure.






.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>





.slot {
border: 1px solid;
border-color: rgba(90, 90, 90, 1);
height: 31px;
background: url(https://i.imgur.com/r6ihXJe.png), rgba(150, 150, 150, 1);
background-position-x: center !important;
background-repeat: repeat-y, no-repeat !important;
}

<div class="slot" style="width:345px; background-size: 62px, auto;"></div>






html css background background-image background-size






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 13:06







Simeon Nikolov

















asked Nov 22 '18 at 12:49









Simeon NikolovSimeon Nikolov

323




323








  • 1





    background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

    – Pete
    Nov 22 '18 at 12:54













  • Sorry the above should say shouldn't have a comma

    – Pete
    Nov 22 '18 at 13:00











  • use 100% instead of auto

    – Temani Afif
    Nov 22 '18 at 13:02











  • @Pete Thanks for the remark. I tried it but it didn't fix the issue.

    – Simeon Nikolov
    Nov 22 '18 at 15:15











  • @TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

    – Simeon Nikolov
    Nov 22 '18 at 15:22














  • 1





    background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

    – Pete
    Nov 22 '18 at 12:54













  • Sorry the above should say shouldn't have a comma

    – Pete
    Nov 22 '18 at 13:00











  • use 100% instead of auto

    – Temani Afif
    Nov 22 '18 at 13:02











  • @Pete Thanks for the remark. I tried it but it didn't fix the issue.

    – Simeon Nikolov
    Nov 22 '18 at 15:15











  • @TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

    – Simeon Nikolov
    Nov 22 '18 at 15:22








1




1





background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

– Pete
Nov 22 '18 at 12:54







background size should have a comma separating the 2 values - try removing it and see if that fixes the issue

– Pete
Nov 22 '18 at 12:54















Sorry the above should say shouldn't have a comma

– Pete
Nov 22 '18 at 13:00





Sorry the above should say shouldn't have a comma

– Pete
Nov 22 '18 at 13:00













use 100% instead of auto

– Temani Afif
Nov 22 '18 at 13:02





use 100% instead of auto

– Temani Afif
Nov 22 '18 at 13:02













@Pete Thanks for the remark. I tried it but it didn't fix the issue.

– Simeon Nikolov
Nov 22 '18 at 15:15





@Pete Thanks for the remark. I tried it but it didn't fix the issue.

– Simeon Nikolov
Nov 22 '18 at 15:15













@TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

– Simeon Nikolov
Nov 22 '18 at 15:22





@TemaniAfif Actually using 100% solves the problem. Thanks! I tried first another solution the idea for which I got from vishwaovi and that's Why I marked his answer as solution. Maybe I'll write a post that includes the 2 solutions - the one with using 100% for y is simpler.

– Simeon Nikolov
Nov 22 '18 at 15:22












3 Answers
3






active

oldest

votes


















0














What actually is happening - you are stretching one pixel image to 63px, and stretching at such scale is causing it to disappear as browser is not able to do that operation.



This is browser specific implementation, if you check on Firefox, it is will work fine and on chrome it is not working.



You can accomplish the same - by using same image as background(repeat x and y both) of .slot's child(set height, width and margin for this child)






share|improve this answer
























  • Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

    – Simeon Nikolov
    Nov 22 '18 at 14:57



















0














So here is my take.



You are giving background height 62px(you have given auto but it will be same as the width because it is a square image) and height of the div as 31px. Means, your background height is twice the height of the element) and you have given repeat-y for the background.



This might be a side effect in CSS3. which is,



If the background image is twice the height(or width) of the element and it is repeating in the y-direction(or x), then the background will not be shown.



I don't think there is any specific logic that was applied during design(CSS feature) to make it work like this.



The solution for your current scenario will be,




  1. Know that auto given in background is actually equal to the width and accordingly make sure that background-height is less than twice the height of the element


or




  1. Use no-repeat if that serves your use-case






share|improve this answer



















  • 1





    Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

    – Simeon Nikolov
    Nov 22 '18 at 14:56



















0














Solution #1: (Thanks to the comment of Temani Afif)



Should use 100% instead of auto in the background-size property for value of y:



background-size: 63px 100%;



Solution #2:



I came up to this idea thanks to vishwaovi answer.



We can use a background image that is a line of 1 x 31 pixels (or other fixed height) instead of just single pixel.



Then we can set the background-size with fixed height for the y:



background-size: 63px 31px;



And the background-repeat property needs to be set to no-repeat:



background-repeat: no-repeat;



This one works too for me but obviously the first solution with just setting the value for y to 100% is more simple.






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',
    autoActivateHeartbeat: false,
    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%2f53431428%2fincreasing-the-background-size-in-css-makes-the-background-image-disappear%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    What actually is happening - you are stretching one pixel image to 63px, and stretching at such scale is causing it to disappear as browser is not able to do that operation.



    This is browser specific implementation, if you check on Firefox, it is will work fine and on chrome it is not working.



    You can accomplish the same - by using same image as background(repeat x and y both) of .slot's child(set height, width and margin for this child)






    share|improve this answer
























    • Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

      – Simeon Nikolov
      Nov 22 '18 at 14:57
















    0














    What actually is happening - you are stretching one pixel image to 63px, and stretching at such scale is causing it to disappear as browser is not able to do that operation.



    This is browser specific implementation, if you check on Firefox, it is will work fine and on chrome it is not working.



    You can accomplish the same - by using same image as background(repeat x and y both) of .slot's child(set height, width and margin for this child)






    share|improve this answer
























    • Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

      – Simeon Nikolov
      Nov 22 '18 at 14:57














    0












    0








    0







    What actually is happening - you are stretching one pixel image to 63px, and stretching at such scale is causing it to disappear as browser is not able to do that operation.



    This is browser specific implementation, if you check on Firefox, it is will work fine and on chrome it is not working.



    You can accomplish the same - by using same image as background(repeat x and y both) of .slot's child(set height, width and margin for this child)






    share|improve this answer













    What actually is happening - you are stretching one pixel image to 63px, and stretching at such scale is causing it to disappear as browser is not able to do that operation.



    This is browser specific implementation, if you check on Firefox, it is will work fine and on chrome it is not working.



    You can accomplish the same - by using same image as background(repeat x and y both) of .slot's child(set height, width and margin for this child)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 '18 at 13:00









    Rohit GargRohit Garg

    1217




    1217













    • Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

      – Simeon Nikolov
      Nov 22 '18 at 14:57



















    • Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

      – Simeon Nikolov
      Nov 22 '18 at 14:57

















    Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

    – Simeon Nikolov
    Nov 22 '18 at 14:57





    Thank you for your answer. I found a solution for my problem by using a fixed height for y and having a no-repeat.

    – Simeon Nikolov
    Nov 22 '18 at 14:57













    0














    So here is my take.



    You are giving background height 62px(you have given auto but it will be same as the width because it is a square image) and height of the div as 31px. Means, your background height is twice the height of the element) and you have given repeat-y for the background.



    This might be a side effect in CSS3. which is,



    If the background image is twice the height(or width) of the element and it is repeating in the y-direction(or x), then the background will not be shown.



    I don't think there is any specific logic that was applied during design(CSS feature) to make it work like this.



    The solution for your current scenario will be,




    1. Know that auto given in background is actually equal to the width and accordingly make sure that background-height is less than twice the height of the element


    or




    1. Use no-repeat if that serves your use-case






    share|improve this answer



















    • 1





      Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

      – Simeon Nikolov
      Nov 22 '18 at 14:56
















    0














    So here is my take.



    You are giving background height 62px(you have given auto but it will be same as the width because it is a square image) and height of the div as 31px. Means, your background height is twice the height of the element) and you have given repeat-y for the background.



    This might be a side effect in CSS3. which is,



    If the background image is twice the height(or width) of the element and it is repeating in the y-direction(or x), then the background will not be shown.



    I don't think there is any specific logic that was applied during design(CSS feature) to make it work like this.



    The solution for your current scenario will be,




    1. Know that auto given in background is actually equal to the width and accordingly make sure that background-height is less than twice the height of the element


    or




    1. Use no-repeat if that serves your use-case






    share|improve this answer



















    • 1





      Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

      – Simeon Nikolov
      Nov 22 '18 at 14:56














    0












    0








    0







    So here is my take.



    You are giving background height 62px(you have given auto but it will be same as the width because it is a square image) and height of the div as 31px. Means, your background height is twice the height of the element) and you have given repeat-y for the background.



    This might be a side effect in CSS3. which is,



    If the background image is twice the height(or width) of the element and it is repeating in the y-direction(or x), then the background will not be shown.



    I don't think there is any specific logic that was applied during design(CSS feature) to make it work like this.



    The solution for your current scenario will be,




    1. Know that auto given in background is actually equal to the width and accordingly make sure that background-height is less than twice the height of the element


    or




    1. Use no-repeat if that serves your use-case






    share|improve this answer













    So here is my take.



    You are giving background height 62px(you have given auto but it will be same as the width because it is a square image) and height of the div as 31px. Means, your background height is twice the height of the element) and you have given repeat-y for the background.



    This might be a side effect in CSS3. which is,



    If the background image is twice the height(or width) of the element and it is repeating in the y-direction(or x), then the background will not be shown.



    I don't think there is any specific logic that was applied during design(CSS feature) to make it work like this.



    The solution for your current scenario will be,




    1. Know that auto given in background is actually equal to the width and accordingly make sure that background-height is less than twice the height of the element


    or




    1. Use no-repeat if that serves your use-case







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 '18 at 13:23









    vishwaovivishwaovi

    366




    366








    • 1





      Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

      – Simeon Nikolov
      Nov 22 '18 at 14:56














    • 1





      Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

      – Simeon Nikolov
      Nov 22 '18 at 14:56








    1




    1





    Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

    – Simeon Nikolov
    Nov 22 '18 at 14:56





    Thank you, your answer helped me reach the solution. The solution for me was to use an image that is line of 1 x 31 pixels instead of an image that is 1 x 1 pixel. I set the background-repeat: no-repeat; and background-size: 63px 31px; This solved the issue for me since the "slot" div will never change its height.

    – Simeon Nikolov
    Nov 22 '18 at 14:56











    0














    Solution #1: (Thanks to the comment of Temani Afif)



    Should use 100% instead of auto in the background-size property for value of y:



    background-size: 63px 100%;



    Solution #2:



    I came up to this idea thanks to vishwaovi answer.



    We can use a background image that is a line of 1 x 31 pixels (or other fixed height) instead of just single pixel.



    Then we can set the background-size with fixed height for the y:



    background-size: 63px 31px;



    And the background-repeat property needs to be set to no-repeat:



    background-repeat: no-repeat;



    This one works too for me but obviously the first solution with just setting the value for y to 100% is more simple.






    share|improve this answer




























      0














      Solution #1: (Thanks to the comment of Temani Afif)



      Should use 100% instead of auto in the background-size property for value of y:



      background-size: 63px 100%;



      Solution #2:



      I came up to this idea thanks to vishwaovi answer.



      We can use a background image that is a line of 1 x 31 pixels (or other fixed height) instead of just single pixel.



      Then we can set the background-size with fixed height for the y:



      background-size: 63px 31px;



      And the background-repeat property needs to be set to no-repeat:



      background-repeat: no-repeat;



      This one works too for me but obviously the first solution with just setting the value for y to 100% is more simple.






      share|improve this answer


























        0












        0








        0







        Solution #1: (Thanks to the comment of Temani Afif)



        Should use 100% instead of auto in the background-size property for value of y:



        background-size: 63px 100%;



        Solution #2:



        I came up to this idea thanks to vishwaovi answer.



        We can use a background image that is a line of 1 x 31 pixels (or other fixed height) instead of just single pixel.



        Then we can set the background-size with fixed height for the y:



        background-size: 63px 31px;



        And the background-repeat property needs to be set to no-repeat:



        background-repeat: no-repeat;



        This one works too for me but obviously the first solution with just setting the value for y to 100% is more simple.






        share|improve this answer













        Solution #1: (Thanks to the comment of Temani Afif)



        Should use 100% instead of auto in the background-size property for value of y:



        background-size: 63px 100%;



        Solution #2:



        I came up to this idea thanks to vishwaovi answer.



        We can use a background image that is a line of 1 x 31 pixels (or other fixed height) instead of just single pixel.



        Then we can set the background-size with fixed height for the y:



        background-size: 63px 31px;



        And the background-repeat property needs to be set to no-repeat:



        background-repeat: no-repeat;



        This one works too for me but obviously the first solution with just setting the value for y to 100% is more simple.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 17:05









        Simeon NikolovSimeon Nikolov

        323




        323






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431428%2fincreasing-the-background-size-in-css-makes-the-background-image-disappear%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

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]