Dave_K
Dave_K

Reputation: 59

css overflow with elements moved outside div, elements disappear

I have a form in a div where I brought submit buttons out of the div to another part of the screen. This works nicely. However, I want to lock that div down to a specific size and relative position and use overflow:auto so when it grows too big (the form has elements that are unhidden with checkboxes) the entire screen doesn't scroll, just the div. The problem is, as soon as I add the overflow style, the submit boxes I moved off the div are hidden. I assume this is because with overflow all elements are locked into that div and scroll bars allow you to access them, but in this case the elements are moved left:-500px and it doesn't even give me a scroll bar to scroll left to see them. Basic code follows:

<div class="div1">
 <div class="div2">
  <form>
   <input type="submit" class="sub1" />
  </form>
 </div>
</div>`

CSS would be:

div.div1 {
 position:relative;
 width:1000px;
 margin: 0 auto;
}
div.div2 {
 width:500px;
 height:500px;
 position:absolute;
 top:125px;
 left:500px;
}
input[type=submit].sub1 {
 position:absolute;
 left: -500px;
}

So this works, but as soon as I change the div2 css to:

div.div2 {
 width:500px;
 height:500px;
 position:absolute;
 top:125px;
 left:500px;
 overflow:auto;
}

The submit button disappears.

My question: is there any way to get the scrollbar and keep the div2 container to 500px high without losing the elements outside the div?

Upvotes: 0

Views: 2251

Answers (1)

Derek
Derek

Reputation: 3435

If I understand correctly, you can move div2 within the form and leave the submit button outside of div2. That way, the submit button will always be visible and div2 can have overflow.

<div class="div1">
  <form>
    <div class="div2">
      <!-- form fields go here -->
    </div>
    <input type="submit" class="sub1" />
  </form>
</div>

Note: You'll likely need to adjust styles on the button, but I'm not entirely sure about your end goal.

Upvotes: 1

Related Questions