简体   繁体   中英

How to fix side bar and header using CSS for JS & jQuery Scroller

I have this layout and I want to make the left sidebar, right sidebar and the header fixed.

在此输入图像描述

This is my css :

    #container {
        padding-left: 200px;      /* LC fullwidth */
        padding-right: 190px;     /* RC fullwidth + CC padding */
    }

    #container .column {
        position: relative;
        float: left;
    }

    #center {
        padding: 10px 20px;       /* CC padding */
        width: 100%;
        overflow-x:hidden;
    }

    #left {
        width: 180px;             /* LC width */
        padding: 0 10px;          /* LC padding */
        right: 240px;             /* LC fullwidth + CC padding */
        margin-left: -100%;
    }

    #right {
        width: 130px;             /* RC width */
        padding: 0 10px;          /* RC padding */
        margin-right: -100%;
    }

    #footer {
        clear: both;
    }

& the code is here

After this step, I want to add nanScrollerJS to the right side bar.

I'm not familiar with CSS

您可以使用position:fixed ,但是,当然,对于IE,您需要一些黑客来使其工作。

Is this what you were trying to do?

Fiddle

I've erased almost all of your code and replaced it with new code.

#fixed

position: fixed;
top: 0;
left: 0;
width: 100%;

#center

margin-top: 32px; /* Header height */
padding: 10px 20px; /* CC padding */
box-sizing: border-box;
border-left: 200px solid black; /* LC width including padding */
border-right: 150px solid black; /* RC width including padding */

#left

width: 180px; /* LC width */
padding: 0 10px; /* LC padding */
float: left;

#right

width: 130px; /* RC width */
padding: 0 10px; /* RC padding */
float: right;

#footer

position: relative;
z-index: 1;

You could always just fix the center with an absolute height, and then overflow-y. Here's an example of what I mean:

#center {
        padding: 10px 20px;       /* CC padding */
        width: 100%;
        height: 240px;            
        overflow-y:scroll;        
        overflow-x:hidden;
    }

and here's a working example (based on yours): http://jsfiddle.net/nr2NZ/27/

Technically the example on nanScrollerJS uses a fixed div on the outside, however in this case, it could because if the outside boxes are position relative, ie shouldn't theoretically have an issue.

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