Using CSS to center a container block









up vote
-2
down vote

favorite












I am trying to center this container block with the background image on my website. The problem is whenever I use margins, it appears different on the mobile version of the website compared to the desktop version. Here are pictures of what the container looks like on desktop version, on mobile version, and the line of code that controls the container.










share|improve this question





















  • share code also for better understanding.
    – Shiv Kumar Baghel
    Nov 10 at 18:46










  • This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    – enxaneta
    Nov 10 at 18:57










  • I did share the code. Did you click on the hyper link labeled "line of code"?
    – Shinookie Cookie
    Nov 10 at 18:58














up vote
-2
down vote

favorite












I am trying to center this container block with the background image on my website. The problem is whenever I use margins, it appears different on the mobile version of the website compared to the desktop version. Here are pictures of what the container looks like on desktop version, on mobile version, and the line of code that controls the container.










share|improve this question





















  • share code also for better understanding.
    – Shiv Kumar Baghel
    Nov 10 at 18:46










  • This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    – enxaneta
    Nov 10 at 18:57










  • I did share the code. Did you click on the hyper link labeled "line of code"?
    – Shinookie Cookie
    Nov 10 at 18:58












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I am trying to center this container block with the background image on my website. The problem is whenever I use margins, it appears different on the mobile version of the website compared to the desktop version. Here are pictures of what the container looks like on desktop version, on mobile version, and the line of code that controls the container.










share|improve this question













I am trying to center this container block with the background image on my website. The problem is whenever I use margins, it appears different on the mobile version of the website compared to the desktop version. Here are pictures of what the container looks like on desktop version, on mobile version, and the line of code that controls the container.







javascript html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 18:43









Shinookie Cookie

42




42











  • share code also for better understanding.
    – Shiv Kumar Baghel
    Nov 10 at 18:46










  • This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    – enxaneta
    Nov 10 at 18:57










  • I did share the code. Did you click on the hyper link labeled "line of code"?
    – Shinookie Cookie
    Nov 10 at 18:58
















  • share code also for better understanding.
    – Shiv Kumar Baghel
    Nov 10 at 18:46










  • This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    – enxaneta
    Nov 10 at 18:57










  • I did share the code. Did you click on the hyper link labeled "line of code"?
    – Shinookie Cookie
    Nov 10 at 18:58















share code also for better understanding.
– Shiv Kumar Baghel
Nov 10 at 18:46




share code also for better understanding.
– Shiv Kumar Baghel
Nov 10 at 18:46












This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
– enxaneta
Nov 10 at 18:57




This is a classic: codepen.io/shshaw/pen/gEiDt?editors=0110 height: whatever; width: whatever; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
– enxaneta
Nov 10 at 18:57












I did share the code. Did you click on the hyper link labeled "line of code"?
– Shinookie Cookie
Nov 10 at 18:58




I did share the code. Did you click on the hyper link labeled "line of code"?
– Shinookie Cookie
Nov 10 at 18:58












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










You are setting a fixed width of 840px. This is wider than the mobile screen, thus the container will go offbounds.



Consider using a percentage for the width, media queries or css grids.






share|improve this answer



























    up vote
    0
    down vote













    You're using fixed width. Try using percentage.






    share|improve this answer




















    • So would I also use percentage with the margins for both versions to to be affected equally?
      – Shinookie Cookie
      Nov 10 at 19:06










    • For desktop you would normally use 80% and for mobile 100%
      – Jaime
      Nov 12 at 2:24










    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%2f53242248%2fusing-css-to-center-a-container-block%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    You are setting a fixed width of 840px. This is wider than the mobile screen, thus the container will go offbounds.



    Consider using a percentage for the width, media queries or css grids.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      You are setting a fixed width of 840px. This is wider than the mobile screen, thus the container will go offbounds.



      Consider using a percentage for the width, media queries or css grids.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        You are setting a fixed width of 840px. This is wider than the mobile screen, thus the container will go offbounds.



        Consider using a percentage for the width, media queries or css grids.






        share|improve this answer












        You are setting a fixed width of 840px. This is wider than the mobile screen, thus the container will go offbounds.



        Consider using a percentage for the width, media queries or css grids.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 18:50









        AWhitePelican

        714




        714






















            up vote
            0
            down vote













            You're using fixed width. Try using percentage.






            share|improve this answer




















            • So would I also use percentage with the margins for both versions to to be affected equally?
              – Shinookie Cookie
              Nov 10 at 19:06










            • For desktop you would normally use 80% and for mobile 100%
              – Jaime
              Nov 12 at 2:24














            up vote
            0
            down vote













            You're using fixed width. Try using percentage.






            share|improve this answer




















            • So would I also use percentage with the margins for both versions to to be affected equally?
              – Shinookie Cookie
              Nov 10 at 19:06










            • For desktop you would normally use 80% and for mobile 100%
              – Jaime
              Nov 12 at 2:24












            up vote
            0
            down vote










            up vote
            0
            down vote









            You're using fixed width. Try using percentage.






            share|improve this answer












            You're using fixed width. Try using percentage.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 18:50









            Jaime

            265




            265











            • So would I also use percentage with the margins for both versions to to be affected equally?
              – Shinookie Cookie
              Nov 10 at 19:06










            • For desktop you would normally use 80% and for mobile 100%
              – Jaime
              Nov 12 at 2:24
















            • So would I also use percentage with the margins for both versions to to be affected equally?
              – Shinookie Cookie
              Nov 10 at 19:06










            • For desktop you would normally use 80% and for mobile 100%
              – Jaime
              Nov 12 at 2:24















            So would I also use percentage with the margins for both versions to to be affected equally?
            – Shinookie Cookie
            Nov 10 at 19:06




            So would I also use percentage with the margins for both versions to to be affected equally?
            – Shinookie Cookie
            Nov 10 at 19:06












            For desktop you would normally use 80% and for mobile 100%
            – Jaime
            Nov 12 at 2:24




            For desktop you would normally use 80% and for mobile 100%
            – Jaime
            Nov 12 at 2:24

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242248%2fusing-css-to-center-a-container-block%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党