How to prevent a div from leaving the page, when another div changes size?

Asked

Viewed 1,310 times

1

My page has basically two divs, to the right and to the left, the two are with style="position: fixed;", that is, if I roll the page, those two divs are side by side, fixed, always visible.

But when the div from the left receives text, it changes its size gets wider. It "pushes" the div from the right even further to the right and consequently out of the browser window. Therefore, a portion of its contents can no longer be viewed.

How to make the div the right has its right edge less than the browser window limit, such as making this div get thinner and more "thin", preventing her to "leak" to screen shoot?

  • Friend, try using style="width:50%;" on both Ivs

1 answer

2


Hello, Roberval!

Use the box-Sizing beam the sizes with the percentage desired.
See the tips in CSS Tricks

I put in the Jsfiddle p/ you can test as well!
Jsfiddle | https://jsfiddle.net/romulobastos/awnonopr/


Follows the code:

* { margin: 0; padding: 0; font-family: arial, helvetica, sans-serif; }
    h1 { font-size: 21px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.2); }
    #container {
      position: fixed;
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    #divEsquerda, #divDireita {
      position: fixed;
    	height: 100%;
      top: 0;
      bottom: 0;
      padding: 2%;
      color: #fff;
      overflow: auto;
      -webkit-box-sizing: border-box;
    	-moz-box-sizing: border-box;
    	box-sizing: border-box;  
    }
    #divEsquerda{ width: 30%; background: #246; left: 0; }
    #divDireita { width: 70%; background: #369; right: 0; }
<div id="container">
      <!-- esquerda -->
      <div id="divEsquerda">
        <h1>Conteúdo da Esquerda</h1>
        <p>...</p>
      </div>
      
      <!-- direita -->
      <div id="divDireita">
        <h1>Conteúdo da Direita</h1>
        <p>...</p>    
      </div>
    </div>

Hug!

  • 1

    Romulo, use the OS feature to put code blocks in the answer, since the availability of the external link cannot be guaranteed.

  • 1

    Okay, @Marciano.Andrade. Thanks for the comment!

  • thanks @Marciano Andrade, resolvidoooo!! brigadeo! I wish everyone was so clear in responstas and so complete!!!

  • Even more .. when we, do not know well how to ask... AND WHY is asking a question.... Soon it is clear that if I do not know . I’m going to ask a little question... neh?? brigade once again

  • 1

    @Robervalsena 山 本 There is no weird question :) if you have questions you can ask friend, but who answered your question was not me, but romulobastos :D just edited the answer to have the snippet there. If you are new to the community, I suggest you read the [tour]

  • 1

    @Marciano.Andrade thanks for the edition! I knew there was a feature, but only now I could see how it is done. Roberval Sena, sometimes it is not so easy to explain in a textual way the problem we have (mainly dealing with layout). But the idea of the OS is to ask questions and share knowledge. Your doubt may be a light at the end of the tunnel p/ someone who has that same "problem" in the future. Abs!

  • 1

    The @romulobastos brigadeo pelaajuda! I’m still getting used to this Strap boot!! Oce solved my problem! was worth a lot!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.