【问题标题】:CSS Fixed sidebar in the rightCSS 固定侧边栏在右侧
【发布时间】:2016-04-18 20:46:32
【问题描述】:

我正在尝试使用引导程序制作两列响应式布局。

我想在左栏中放置宽度为 100%/2 的内容,在右侧放置宽度为 100%/3 的固定侧边栏。

这是我用于侧边栏的 css,但在小提琴中,我附加侧边栏在左侧,我希望它在右侧。

 #sidebar-wrapper {
        z-index: 1000;
        position: fixed;
        left: 250px;
        width: 0;
        height: 100%;
        margin-left: -250px;
        overflow-y: auto;
        background: #000;
        -webkit-transition: all 0.5s ease;
        -moz-transition: all 0.5s ease;
        -o-transition: all 0.5s ease;
        transition: all 0.5s ease;
    }

小提琴:

https://jsfiddle.net/une5nhf4/

我怎样才能修改它以满足我的需要?

【问题讨论】:

    标签: css twitter-bootstrap


    【解决方案1】:

    我修改了你的 CSS:

    #wrapper {
        padding-left: 0;
        -webkit-transition: all 0.5s ease;
        -moz-transition: all 0.5s ease;
        -o-transition: all 0.5s ease;
        transition: all 0.5s ease;
    }
    
    #wrapper.toggled {
        padding-right: 250px;
    }
    
    #sidebar-wrapper {
        z-index: 1000;
        position: fixed;
        right: 250px;
        width: 0;
        height: 100%;
        margin-right: -250px;
        overflow-y: auto;
        background: #000;
        -webkit-transition: all 0.5s ease;
        -moz-transition: all 0.5s ease;
        -o-transition: all 0.5s ease;
        transition: all 0.5s ease;
    }
    
    #wrapper.toggled #sidebar-wrapper {
        width: 250px;
    }
    
    #page-content-wrapper {
        width: 100%;
        position: absolute;
        padding: 15px;
    }
    
    #wrapper.toggled #page-content-wrapper {
        position: absolute;
        margin-right: -250px;
    }
    
    /* Sidebar Styles */
    
    .sidebar-nav {
        position: absolute;
        top: 0;
        width: 250px;
        margin: 0;
        padding: 0;
        list-style: none;
    }
    
    .sidebar-nav li {
        text-indent: 20px;
        line-height: 40px;
    }
    
    .sidebar-nav li a {
        display: block;
        text-decoration: none;
        color: #999999;
    }
    
    .sidebar-nav li a:hover {
        text-decoration: none;
        color: #fff;
        background: rgba(255,255,255,0.2);
    }
    
    .sidebar-nav li a:active,
    .sidebar-nav li a:focus {
        text-decoration: none;
    }
    
    .sidebar-nav > .sidebar-brand {
        height: 65px;
        font-size: 18px;
        line-height: 60px;
    }
    
    .sidebar-nav > .sidebar-brand a {
        color: #999999;
    }
    
    .sidebar-nav > .sidebar-brand a:hover {
        color: #fff;
        background: none;
    }
    
    @media(min-width:768px) {
        #wrapper {
            padding-right: 250px;
        }
    
        #wrapper.toggled {
            padding-right: 0;
        }
    
        #sidebar-wrapper {
            width: 250px;
        }
    
        #wrapper.toggled #sidebar-wrapper {
            width: 0;
        }
    
        #page-content-wrapper {
            padding: 20px;
            position: relative;
        }
    
        #wrapper.toggled #page-content-wrapper {
            position: relative;
            margin-right: 0;
        }
    }
    

    DEMO

    【讨论】:

    • 当侧边栏打开时,它会移动内容(margin/padding)
    • 非常感谢,那我怎样才能让右边的内容占 100%/3 宽度,而左边的内容占 100%/2 呢?
    • 内容将占 50%,右侧边栏占 33%;那么剩下的 17% 会是什么?黑洞? ;-)
    • @Legionar 哈哈哈对不起,我想说右边:100%/3 和左边:100% - 100%/3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 2012-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多