Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<ul> with overflow-y: auto and <li>s with relative position behaves oddly

Tags:

css

jquery-ui

I've the following mark up

<div class="row-fluid">
    <div class="span4">
        <ul class="test">
            <li>Arun</li>
            <li>Krishna</li>
            <li>Soundar</li>
        </ul>
    </div>
</div>

And css

.test {
    height: 500px;
    margin-top: 10px;
    overflow-y: auto;
    padding: 10px 4px 70px;
}

And script

$('.test li').draggable({
    revert: 'invalid'
})

If you drag the items to the right side, it disappears, I don't know why it is behaving so.

If the overflow-y: auto; style is removed from .test it works fine.

Demo: Fiddle
You may have to increase the width of the preview tab because of the responsive css to replicate the issue in the fiddle

like image 264
Arun P Johny Avatar asked Mar 19 '13 06:03

Arun P Johny


People also ask

What does overflow-y auto do?

The overflow-y property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.

Which CSS property is used to add scroll behaviour when content is overflowing from an element?

The overflow property specifies what should happen if content overflows an element's box. This property specifies whether to clip content or to add scrollbars when an element's content is too big to fit in a specified area.

What is overflow-y visible?

Visible: If the value assigned to the “overflow-y” property is “visible” then the content is not clipped and may overflow out to the top or bottom of the containing element.

What is overflow auto?

overflow: autoThe auto value is similar to scroll , but it adds scrollbars only when necessary: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.


1 Answers

I know this is an old question, but I think I found an answer. The reason the list disappears is because you drag it off the edge of the div and it begins to auto scroll. So, you you just remove it from the flow of the page when it is clicked on, like so:

$('.test li').draggable({
    revert: 'invalid'
}).mousedown(function() {
    var that = $(this);
    //create div to fill the vacated space
    $div = $('<div></div>');
    $div.width(that.width());
    $div.height(that.height());
    $div.insertAfter(that);
    //remove from flow of the page, set a different background color to see it work
    that.css({'position':'absolute'});
});

New fiddle here

like image 134
mdenton8 Avatar answered Oct 10 '22 02:10

mdenton8