Half fixed, half scrollable layout that can be scrolled… CSS

前端 未结 3 2319
清歌不尽
清歌不尽 2020-12-31 07:50

I have an exotic design that needs the following. The left side must scroll, while the right side + top head must stay put (fixed). See attached image.

I can accompl

相关标签:
3条回答
  • 2020-12-31 08:33

    Its not very hard to create a layout like this.

    I created one for you, see that Working Fiddle

    HTML:

    <div class="Container">
        <div class="Header">
            <p>The Header div height is not fixed (But he can be if you want it to)</p>
            <p>This Layout has been tested on: IE10, IE9, IE8, FireFox, Chrome, Safari, Opera. using Pure CSS 2.1 only</p>
        </div>
        <div class="Content">
            <div class="Wrapper">
                <div class="RightContent">
                    <p>You can fix the width of this content.</p>
                    <p>if you wont, his width will stretch just as it needs to.</p>
                </div>
                <div class="LeftContent">
                    <p>this will scroll</p>
                </div>
            </div>
        </div>
    </div>
    

    CSS:

    *
    {
        margin: 0;
        padding: 0;
    }
    
    html, body, .Container
    {
        height: 100%;
    }
    
        .Container:before
        {
            content: '';
            height: 100%;
            float: left;
        }
    
    .Header
    {
        margin-bottom: 10px;
        background-color: #6ea364;
    }
    .Content
    {
        position: relative;
        z-index: 1;
    }
        .Content:after
        {
            content: '';
            clear: both;
            display: block;
        }
    
    .Wrapper
    {
        position: absolute;
        width: 100%;
        height: 100%;
    }
        .Wrapper > div
        {
            height: 100%;
        }
    
    .LeftContent
    {
        background-color: purple;
        overflow: auto;
    }
    
    .RightContent
    {
        background-color: orange;
        float: right;
        margin-left: 10px;
    }
    

    Bonus: with a little change in the CSS, you can create a beautiful scrolling. See that Fiddle

    Edit: If you want to set a width value to the left side, that is actually bigger then the body size (and to have an horizontal scroll), do it that way.

    <div class="LeftContent">
        <div style="width:1200px;"> <-- better to aplly the width from the CSS
            ..<The content>..
        </div>
    </div>
    
    0 讨论(0)
  • 2020-12-31 08:36

    Have you tried

    overflow-y: scroll;
    

    in body?

    0 讨论(0)
  • 2020-12-31 08:53

    you need to add overflow:auto; to the area you want to scroll.

    0 讨论(0)
提交回复
热议问题