overflow: hidden from the middleCan't scroll to top of flex item that is overflowing containerWhy is a flex-child limited to parent size?CSS Centering with TransformCSS - Make divs align horizontallyHow to align a <div> to the middle (horizontally/width) of the pageAdding padding to HTML elements - IE, FF, Chrome etcCSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issueFluid width with equally spaced DIVsDynamic Stretch DIVHow do I add spacing between columns in Bootstrap?Prevent right div from dropping below when the left one is expandedDesign content of pageHow do I get an absolutely positioned div with overflow auto to grow to the width of it's contents with white-space set to nowrap?

Wireless headphones interfere with Wi-Fi signal on laptop

UUID type for NEWID()

Why does SSL Labs now consider CBC suites weak?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

My bread in my bread maker rises and then falls down just after cooking starts

Why do galaxies collide?

Understanding Deutch's Algorithm

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

Developers demotivated due to working on same project for more than 2 years

How will the lack of ground stations affect navigation?

Testing if os.path.exists with ArcPy?

Does this "yield your space to an ally" rule my 3.5 group uses appear anywhere in the official rules?

What is this weird d12 for?

Why are lawsuits between the President and Congress not automatically sent to the Supreme Court

With today's technology, could iron be smelted at La Rinconada?

When did game consoles begin including FPUs?

Can I say: "When was your train leaving?" if the train leaves in the future?

What is the effect of the Feeblemind spell on Ability Score Improvements?

Were any of the books mentioned in this scene from the movie Hackers real?

Why can't I share a one use code with anyone else?

Why did Varys remove his rings?

How would you translate "grit" (personality trait) to Chinese?

Does the wearer know what items are in which patch in the Robe of Useful items?

Could there be something like aerobatic smoke trails in the vacuum of space?



overflow: hidden from the middle


Can't scroll to top of flex item that is overflowing containerWhy is a flex-child limited to parent size?CSS Centering with TransformCSS - Make divs align horizontallyHow to align a <div> to the middle (horizontally/width) of the pageAdding padding to HTML elements - IE, FF, Chrome etcCSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issueFluid width with equally spaced DIVsDynamic Stretch DIVHow do I add spacing between columns in Bootstrap?Prevent right div from dropping below when the left one is expandedDesign content of pageHow do I get an absolutely positioned div with overflow auto to grow to the width of it's contents with white-space set to nowrap?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1


















#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>





I am trying to do something in my css code.
The code has 3 div objects, and the width of each one of them is 1000px.
I want those 3 divs to be in the same line, so i wrote that to the father div:



white-space: nowrap;
overflow: hidden;


In each one of them I entered:



display: inline-block;


The thing is they all cut to the right, but I want them to be cut from both right and left equally.
That means that if there is 10px overflow area, i want 5px to be cut to the right and 5px to the left.
How can I do that?



Many thanks,



Image of what I want to achieve:
enter image description here










share|improve this question
























  • What do you mean with cut?

    – Ifaruki
    Mar 23 at 14:44











  • i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

    – Ron Rofe
    Mar 23 at 14:49












  • Add the complete code here. cannot see any output with the stuff you have added.

    – Harshana
    Mar 23 at 14:50











  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

    – LGSon
    Mar 23 at 14:55












  • #main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

    – Ron Rofe
    Mar 23 at 14:58

















1


















#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>





I am trying to do something in my css code.
The code has 3 div objects, and the width of each one of them is 1000px.
I want those 3 divs to be in the same line, so i wrote that to the father div:



white-space: nowrap;
overflow: hidden;


In each one of them I entered:



display: inline-block;


The thing is they all cut to the right, but I want them to be cut from both right and left equally.
That means that if there is 10px overflow area, i want 5px to be cut to the right and 5px to the left.
How can I do that?



Many thanks,



Image of what I want to achieve:
enter image description here










share|improve this question
























  • What do you mean with cut?

    – Ifaruki
    Mar 23 at 14:44











  • i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

    – Ron Rofe
    Mar 23 at 14:49












  • Add the complete code here. cannot see any output with the stuff you have added.

    – Harshana
    Mar 23 at 14:50











  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

    – LGSon
    Mar 23 at 14:55












  • #main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

    – Ron Rofe
    Mar 23 at 14:58













1












1








1











#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>





I am trying to do something in my css code.
The code has 3 div objects, and the width of each one of them is 1000px.
I want those 3 divs to be in the same line, so i wrote that to the father div:



white-space: nowrap;
overflow: hidden;


In each one of them I entered:



display: inline-block;


The thing is they all cut to the right, but I want them to be cut from both right and left equally.
That means that if there is 10px overflow area, i want 5px to be cut to the right and 5px to the left.
How can I do that?



Many thanks,



Image of what I want to achieve:
enter image description here










share|improve this question



















#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>





I am trying to do something in my css code.
The code has 3 div objects, and the width of each one of them is 1000px.
I want those 3 divs to be in the same line, so i wrote that to the father div:



white-space: nowrap;
overflow: hidden;


In each one of them I entered:



display: inline-block;


The thing is they all cut to the right, but I want them to be cut from both right and left equally.
That means that if there is 10px overflow area, i want 5px to be cut to the right and 5px to the left.
How can I do that?



Many thanks,



Image of what I want to achieve:
enter image description here






#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>





#main 
white-space: nowrap;
overflow: hidden;


#main div
display: inline-block;
heighh: 200px;
width: 1000px;
border: solid black;

 <div id="main">
<div id="first">
1
</div>
<div id="second">
2
</div id="third">
<div>
3
</div>
</div>






html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 7:39









Anurag Srivastava

2,47621220




2,47621220










asked Mar 23 at 14:37









Ron RofeRon Rofe

113




113












  • What do you mean with cut?

    – Ifaruki
    Mar 23 at 14:44











  • i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

    – Ron Rofe
    Mar 23 at 14:49












  • Add the complete code here. cannot see any output with the stuff you have added.

    – Harshana
    Mar 23 at 14:50











  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

    – LGSon
    Mar 23 at 14:55












  • #main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

    – Ron Rofe
    Mar 23 at 14:58

















  • What do you mean with cut?

    – Ifaruki
    Mar 23 at 14:44











  • i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

    – Ron Rofe
    Mar 23 at 14:49












  • Add the complete code here. cannot see any output with the stuff you have added.

    – Harshana
    Mar 23 at 14:50











  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

    – LGSon
    Mar 23 at 14:55












  • #main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

    – Ron Rofe
    Mar 23 at 14:58
















What do you mean with cut?

– Ifaruki
Mar 23 at 14:44





What do you mean with cut?

– Ifaruki
Mar 23 at 14:44













i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

– Ron Rofe
Mar 23 at 14:49






i.imgur.com/KV5wjwV.png the first one is the way it is looking right now the second is the desired result

– Ron Rofe
Mar 23 at 14:49














Add the complete code here. cannot see any output with the stuff you have added.

– Harshana
Mar 23 at 14:50





Add the complete code here. cannot see any output with the stuff you have added.

– Harshana
Mar 23 at 14:50













Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

– LGSon
Mar 23 at 14:55






Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. See: How to create a Minimal, Complete, and Verifiable example.

– LGSon
Mar 23 at 14:55














#main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

– Ron Rofe
Mar 23 at 14:58





#main white-space: nowrap; overflow: hidden; #main div display: inline-block; heighh: 200px; width: 1000px; border: solid black; <div id="main"> <div id="first"> 1 </div> <div id="second"> 2 </div id="third"> <div> 3 </div> </div>

– Ron Rofe
Mar 23 at 14:58












3 Answers
3






active

oldest

votes


















2














I believe you can use flexbox to achieve the effect you're looking for, though it's not particularly clean, and a bit advanced for a beginner.



Instead of putting all the children inside your #main, we put them in another container right inside #main that we'll call #wrapper. We use flexbox to put all its children (#first, #second, #third) on the same line, and we make this container arbitrarily wide (in this example, 9999px) so that all of the items will fit on the same line no matter what.



Then, we use position: absolute; left: 50%; transform: translateX(-50%); to center that container within #main. Applying overflow: hidden to #main as you already had gets you the cut-off effect you're looking for.



For more information about these techniques, check out A Complete Guide to Flexbox and This question about centering with transform and absolute positioning.






#main 
overflow: hidden;
position: relative;


#wrapper
position: relative;
width: 9999px;
left: 50%;
transform: translateX(-50%);
display: flex;
justify-content: center;


#wrapper div
height: 200px;
width: 400px;
border: solid black;

<div id="main">
<div id="wrapper">
<div id="first">
1
</div>
<div id="second">
2
</div>
<div id="third">
3
</div>
</div>
</div>








share|improve this answer
































    0














    An easy solution without extra element is to simply make the container a flexbox one and center the elements:






    #main 
    display: flex;
    justify-content: center; /*center to have overflow from both side*/
    overflow:hidden; /*hide the overflow*/


    #main div
    height: 200px;
    width: 500px;
    border: solid black;
    flex-shrink:0; /* Don't shrink element so they overflow */

    <div id="main">
    <div id="first">
    1
    </div>
    <div id="second">
    2
    </div>
    <div id="third">
    3
    </div>
    </div>





    Here is some related question to better understand what is happening:



    Why is a flex-child limited to parent size?



    Can't scroll to top of flex item that is overflowing container






    share|improve this answer






























      0














      on your case you have 3 div tags with a fixed width ,so it can be easily achieved by setting margin-left of it's parent .set margin-left:calc(50%-1500px); to your parent element it will work fine,
      >



      • 50% is half the width of the screen.

      • here 1500px is 1.5 times of width of your child elements(1000px).

      here I added an example to demonstrate with child width:300px;






      #main 
      white-space: nowrap;
      overflow: hidden;
      margin-left:calc(50% - 450px);


      #main div
      display: inline-block;
      height: 200px;
      width: 300px;
      border: solid black;
      box-sizing:border-box;

      <div id="main">
      <div id="first">
      1
      </div>
      <div id="second">
      2
      </div >
      <div id="third">
      3
      </div>
      </div>








      share|improve this answer

























      • This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

        – Geo1088
        Mar 23 at 16:20











      • @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

        – Dream Hunter - hashADH
        Mar 23 at 16:29











      • @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

        – Dream Hunter - hashADH
        Mar 23 at 16:30











      • Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

        – Geo1088
        Mar 23 at 17:14












      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%2f55314820%2foverflow-hidden-from-the-middle%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









      2














      I believe you can use flexbox to achieve the effect you're looking for, though it's not particularly clean, and a bit advanced for a beginner.



      Instead of putting all the children inside your #main, we put them in another container right inside #main that we'll call #wrapper. We use flexbox to put all its children (#first, #second, #third) on the same line, and we make this container arbitrarily wide (in this example, 9999px) so that all of the items will fit on the same line no matter what.



      Then, we use position: absolute; left: 50%; transform: translateX(-50%); to center that container within #main. Applying overflow: hidden to #main as you already had gets you the cut-off effect you're looking for.



      For more information about these techniques, check out A Complete Guide to Flexbox and This question about centering with transform and absolute positioning.






      #main 
      overflow: hidden;
      position: relative;


      #wrapper
      position: relative;
      width: 9999px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      justify-content: center;


      #wrapper div
      height: 200px;
      width: 400px;
      border: solid black;

      <div id="main">
      <div id="wrapper">
      <div id="first">
      1
      </div>
      <div id="second">
      2
      </div>
      <div id="third">
      3
      </div>
      </div>
      </div>








      share|improve this answer





























        2














        I believe you can use flexbox to achieve the effect you're looking for, though it's not particularly clean, and a bit advanced for a beginner.



        Instead of putting all the children inside your #main, we put them in another container right inside #main that we'll call #wrapper. We use flexbox to put all its children (#first, #second, #third) on the same line, and we make this container arbitrarily wide (in this example, 9999px) so that all of the items will fit on the same line no matter what.



        Then, we use position: absolute; left: 50%; transform: translateX(-50%); to center that container within #main. Applying overflow: hidden to #main as you already had gets you the cut-off effect you're looking for.



        For more information about these techniques, check out A Complete Guide to Flexbox and This question about centering with transform and absolute positioning.






        #main 
        overflow: hidden;
        position: relative;


        #wrapper
        position: relative;
        width: 9999px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        justify-content: center;


        #wrapper div
        height: 200px;
        width: 400px;
        border: solid black;

        <div id="main">
        <div id="wrapper">
        <div id="first">
        1
        </div>
        <div id="second">
        2
        </div>
        <div id="third">
        3
        </div>
        </div>
        </div>








        share|improve this answer



























          2












          2








          2







          I believe you can use flexbox to achieve the effect you're looking for, though it's not particularly clean, and a bit advanced for a beginner.



          Instead of putting all the children inside your #main, we put them in another container right inside #main that we'll call #wrapper. We use flexbox to put all its children (#first, #second, #third) on the same line, and we make this container arbitrarily wide (in this example, 9999px) so that all of the items will fit on the same line no matter what.



          Then, we use position: absolute; left: 50%; transform: translateX(-50%); to center that container within #main. Applying overflow: hidden to #main as you already had gets you the cut-off effect you're looking for.



          For more information about these techniques, check out A Complete Guide to Flexbox and This question about centering with transform and absolute positioning.






          #main 
          overflow: hidden;
          position: relative;


          #wrapper
          position: relative;
          width: 9999px;
          left: 50%;
          transform: translateX(-50%);
          display: flex;
          justify-content: center;


          #wrapper div
          height: 200px;
          width: 400px;
          border: solid black;

          <div id="main">
          <div id="wrapper">
          <div id="first">
          1
          </div>
          <div id="second">
          2
          </div>
          <div id="third">
          3
          </div>
          </div>
          </div>








          share|improve this answer















          I believe you can use flexbox to achieve the effect you're looking for, though it's not particularly clean, and a bit advanced for a beginner.



          Instead of putting all the children inside your #main, we put them in another container right inside #main that we'll call #wrapper. We use flexbox to put all its children (#first, #second, #third) on the same line, and we make this container arbitrarily wide (in this example, 9999px) so that all of the items will fit on the same line no matter what.



          Then, we use position: absolute; left: 50%; transform: translateX(-50%); to center that container within #main. Applying overflow: hidden to #main as you already had gets you the cut-off effect you're looking for.



          For more information about these techniques, check out A Complete Guide to Flexbox and This question about centering with transform and absolute positioning.






          #main 
          overflow: hidden;
          position: relative;


          #wrapper
          position: relative;
          width: 9999px;
          left: 50%;
          transform: translateX(-50%);
          display: flex;
          justify-content: center;


          #wrapper div
          height: 200px;
          width: 400px;
          border: solid black;

          <div id="main">
          <div id="wrapper">
          <div id="first">
          1
          </div>
          <div id="second">
          2
          </div>
          <div id="third">
          3
          </div>
          </div>
          </div>








          #main 
          overflow: hidden;
          position: relative;


          #wrapper
          position: relative;
          width: 9999px;
          left: 50%;
          transform: translateX(-50%);
          display: flex;
          justify-content: center;


          #wrapper div
          height: 200px;
          width: 400px;
          border: solid black;

          <div id="main">
          <div id="wrapper">
          <div id="first">
          1
          </div>
          <div id="second">
          2
          </div>
          <div id="third">
          3
          </div>
          </div>
          </div>





          #main 
          overflow: hidden;
          position: relative;


          #wrapper
          position: relative;
          width: 9999px;
          left: 50%;
          transform: translateX(-50%);
          display: flex;
          justify-content: center;


          #wrapper div
          height: 200px;
          width: 400px;
          border: solid black;

          <div id="main">
          <div id="wrapper">
          <div id="first">
          1
          </div>
          <div id="second">
          2
          </div>
          <div id="third">
          3
          </div>
          </div>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 5 at 0:11

























          answered Mar 23 at 15:18









          Geo1088Geo1088

          3151514




          3151514























              0














              An easy solution without extra element is to simply make the container a flexbox one and center the elements:






              #main 
              display: flex;
              justify-content: center; /*center to have overflow from both side*/
              overflow:hidden; /*hide the overflow*/


              #main div
              height: 200px;
              width: 500px;
              border: solid black;
              flex-shrink:0; /* Don't shrink element so they overflow */

              <div id="main">
              <div id="first">
              1
              </div>
              <div id="second">
              2
              </div>
              <div id="third">
              3
              </div>
              </div>





              Here is some related question to better understand what is happening:



              Why is a flex-child limited to parent size?



              Can't scroll to top of flex item that is overflowing container






              share|improve this answer



























                0














                An easy solution without extra element is to simply make the container a flexbox one and center the elements:






                #main 
                display: flex;
                justify-content: center; /*center to have overflow from both side*/
                overflow:hidden; /*hide the overflow*/


                #main div
                height: 200px;
                width: 500px;
                border: solid black;
                flex-shrink:0; /* Don't shrink element so they overflow */

                <div id="main">
                <div id="first">
                1
                </div>
                <div id="second">
                2
                </div>
                <div id="third">
                3
                </div>
                </div>





                Here is some related question to better understand what is happening:



                Why is a flex-child limited to parent size?



                Can't scroll to top of flex item that is overflowing container






                share|improve this answer

























                  0












                  0








                  0







                  An easy solution without extra element is to simply make the container a flexbox one and center the elements:






                  #main 
                  display: flex;
                  justify-content: center; /*center to have overflow from both side*/
                  overflow:hidden; /*hide the overflow*/


                  #main div
                  height: 200px;
                  width: 500px;
                  border: solid black;
                  flex-shrink:0; /* Don't shrink element so they overflow */

                  <div id="main">
                  <div id="first">
                  1
                  </div>
                  <div id="second">
                  2
                  </div>
                  <div id="third">
                  3
                  </div>
                  </div>





                  Here is some related question to better understand what is happening:



                  Why is a flex-child limited to parent size?



                  Can't scroll to top of flex item that is overflowing container






                  share|improve this answer













                  An easy solution without extra element is to simply make the container a flexbox one and center the elements:






                  #main 
                  display: flex;
                  justify-content: center; /*center to have overflow from both side*/
                  overflow:hidden; /*hide the overflow*/


                  #main div
                  height: 200px;
                  width: 500px;
                  border: solid black;
                  flex-shrink:0; /* Don't shrink element so they overflow */

                  <div id="main">
                  <div id="first">
                  1
                  </div>
                  <div id="second">
                  2
                  </div>
                  <div id="third">
                  3
                  </div>
                  </div>





                  Here is some related question to better understand what is happening:



                  Why is a flex-child limited to parent size?



                  Can't scroll to top of flex item that is overflowing container






                  #main 
                  display: flex;
                  justify-content: center; /*center to have overflow from both side*/
                  overflow:hidden; /*hide the overflow*/


                  #main div
                  height: 200px;
                  width: 500px;
                  border: solid black;
                  flex-shrink:0; /* Don't shrink element so they overflow */

                  <div id="main">
                  <div id="first">
                  1
                  </div>
                  <div id="second">
                  2
                  </div>
                  <div id="third">
                  3
                  </div>
                  </div>





                  #main 
                  display: flex;
                  justify-content: center; /*center to have overflow from both side*/
                  overflow:hidden; /*hide the overflow*/


                  #main div
                  height: 200px;
                  width: 500px;
                  border: solid black;
                  flex-shrink:0; /* Don't shrink element so they overflow */

                  <div id="main">
                  <div id="first">
                  1
                  </div>
                  <div id="second">
                  2
                  </div>
                  <div id="third">
                  3
                  </div>
                  </div>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 22:57









                  Temani AfifTemani Afif

                  87.4k104998




                  87.4k104998





















                      0














                      on your case you have 3 div tags with a fixed width ,so it can be easily achieved by setting margin-left of it's parent .set margin-left:calc(50%-1500px); to your parent element it will work fine,
                      >



                      • 50% is half the width of the screen.

                      • here 1500px is 1.5 times of width of your child elements(1000px).

                      here I added an example to demonstrate with child width:300px;






                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>








                      share|improve this answer

























                      • This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                        – Geo1088
                        Mar 23 at 16:20











                      • @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                        – Dream Hunter - hashADH
                        Mar 23 at 16:29











                      • @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                        – Dream Hunter - hashADH
                        Mar 23 at 16:30











                      • Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                        – Geo1088
                        Mar 23 at 17:14
















                      0














                      on your case you have 3 div tags with a fixed width ,so it can be easily achieved by setting margin-left of it's parent .set margin-left:calc(50%-1500px); to your parent element it will work fine,
                      >



                      • 50% is half the width of the screen.

                      • here 1500px is 1.5 times of width of your child elements(1000px).

                      here I added an example to demonstrate with child width:300px;






                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>








                      share|improve this answer

























                      • This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                        – Geo1088
                        Mar 23 at 16:20











                      • @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                        – Dream Hunter - hashADH
                        Mar 23 at 16:29











                      • @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                        – Dream Hunter - hashADH
                        Mar 23 at 16:30











                      • Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                        – Geo1088
                        Mar 23 at 17:14














                      0












                      0








                      0







                      on your case you have 3 div tags with a fixed width ,so it can be easily achieved by setting margin-left of it's parent .set margin-left:calc(50%-1500px); to your parent element it will work fine,
                      >



                      • 50% is half the width of the screen.

                      • here 1500px is 1.5 times of width of your child elements(1000px).

                      here I added an example to demonstrate with child width:300px;






                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>








                      share|improve this answer















                      on your case you have 3 div tags with a fixed width ,so it can be easily achieved by setting margin-left of it's parent .set margin-left:calc(50%-1500px); to your parent element it will work fine,
                      >



                      • 50% is half the width of the screen.

                      • here 1500px is 1.5 times of width of your child elements(1000px).

                      here I added an example to demonstrate with child width:300px;






                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>








                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>





                      #main 
                      white-space: nowrap;
                      overflow: hidden;
                      margin-left:calc(50% - 450px);


                      #main div
                      display: inline-block;
                      height: 200px;
                      width: 300px;
                      border: solid black;
                      box-sizing:border-box;

                      <div id="main">
                      <div id="first">
                      1
                      </div>
                      <div id="second">
                      2
                      </div >
                      <div id="third">
                      3
                      </div>
                      </div>






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 24 at 5:03

























                      answered Mar 23 at 15:40









                      Dream Hunter - hashADHDream Hunter - hashADH

                      2,20911636




                      2,20911636












                      • This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                        – Geo1088
                        Mar 23 at 16:20











                      • @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                        – Dream Hunter - hashADH
                        Mar 23 at 16:29











                      • @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                        – Dream Hunter - hashADH
                        Mar 23 at 16:30











                      • Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                        – Geo1088
                        Mar 23 at 17:14


















                      • This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                        – Geo1088
                        Mar 23 at 16:20











                      • @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                        – Dream Hunter - hashADH
                        Mar 23 at 16:29











                      • @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                        – Dream Hunter - hashADH
                        Mar 23 at 16:30











                      • Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                        – Geo1088
                        Mar 23 at 17:14

















                      This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                      – Geo1088
                      Mar 23 at 16:20





                      This isn't a perfect solution, because it doesn't account for border width or the width of the space between elements that you get from display: inline-block, though it's probably close enough for the asker's uses.

                      – Geo1088
                      Mar 23 at 16:20













                      @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                      – Dream Hunter - hashADH
                      Mar 23 at 16:29





                      @Geo1088 border width is not a matter here because I'm added box-sizing : border-box; and the space between the blocks can be easily managed by adjusting the margin left value,I give him the basic logic.

                      – Dream Hunter - hashADH
                      Mar 23 at 16:29













                      @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                      – Dream Hunter - hashADH
                      Mar 23 at 16:30





                      @Geo1088 assume if the margin between div tags are 10px then equation just change to margin-left:calc(50%-(1500px+20px));

                      – Dream Hunter - hashADH
                      Mar 23 at 16:30













                      Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                      – Geo1088
                      Mar 23 at 17:14






                      Didn't notice the box-sizing, good call. However, there is a space between them that's always there even if you set margin: 0 because of the way HTML whitespace is handled with display: inline-block. There is an actual text node between each element, containing nothing but a space, unless you have no whitespace between the child tags in HTML. This is why I almost always use flexbox for this type of thing - it ignores whitespace in the markup.

                      – Geo1088
                      Mar 23 at 17:14


















                      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%2f55314820%2foverflow-hidden-from-the-middle%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript