How to fix a div on the Y-axis using javascript?

Asked

Viewed 150 times

0

I am trying to leave a div fixed on VERTICAL, and when moving the scrollbar, the rest of the contents of that same div would normally look like, I used the position Fixed, but the rest of the content does not appear. I tried with CSS, but I could not and now that I am knowing better javascript.

    <!doctype html>
    <html>
    <head>
    <meta charset="iso-8859-1">
    <title>Untitled Document</title>

    <style>
       *{margin:0; padding:0;}
       #fixar {position:fixed; background-color:#666; height:1000px; width:500px;}
       #conteudo {width:50000px; height:1000px; background-color:#CCC; margin-left:505px;}
    </style>

    </head>
    <body>

    <div id="fixar">
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
       <p>conteúdo fixo</p>
      <p>ESSE CONTEÚDO FICA "CORTADO"</p>
    </div>

   <div id="conteudo">
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
      <p>conteúdo normal</p>
    </div>



   </body>
   </html>
  • Caren, can you put the code you have and that has the problem you described "the rest of the content does not appear"?

  • In html, the div "fix" I would like it to stay fixed without the rest of the content disappearing.

  • Click on [Edit] and join the code to understand the problem better

  • The div "fix" I want it to stay fixed, and the whole content to appear, but with position:Fixed; the rest of the content is "cut"

  • A simple overflow-y: auto; height: 100%; in your fixed div CSS wouldn’t solve the problem?

  • The problem is that I don’t want the div "fix" to create scroll bar, the only bar I want is the normal one of the browser, I need the content of this div to appear normally, only I need it always fixed, so I think only with css can not do.

  • If you do not want the scrollbar you can add . classname::-Webkit-scrollbar{display:None;}. The content is cut at the end of your div, if you want all the content to appear you have to increase the height of that div.

Show 2 more comments
No answers

Browser other questions tagged

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