简体   繁体   中英

Layout issue with absolute positioned div

I have a parent/child divs coded as;

<div class="classes scrollable">
<div class="items">
....Some content
</div>
</div>

My CSS is;

.scrollable {
    overflow: hidden;
    position: relative;
    width: 100%;
}
.scrollable .items {
    clear: both;
    position: absolute;
    width: 20000em;
}

Actually my "items" div has it's "left" position changed dynamically via JS (for kind of carousel effect...scrolls to left/right)

Also bcoz it is an absolute div, I cannot get the parent div "scrollable" to expand as per "items" content.

How do I fix this issue ?

You can set height on the .scrollable . The inner scrolling div is just one row, right?

What keeps you from not making .items absolutely positioned?
Can't you just use something like margin-left: -100px , instead of left: -100px; ?

Working example of what I mean: http://jsfiddle.net/fk5Q2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM