如何添加固定侧边栏

时间:2013-03-22 11:53:58

标签: css

我想添加一个固定的侧边栏,如下图所示。

enter image description here

这怎么可能?

Appreciate any suggestion.

Solution

4 个答案:

答案 0 :(得分:2)

习惯了这个

  

固定位置

.sidebar{
position:fixed;
left:0;
width:250px; // width change to according your left bar side
top:0;
bottom:0;
}

<强> Demo

答案 1 :(得分:1)

.SomeClass { position: fixed }

答案 2 :(得分:1)

这个小提琴可以解决您的问题,右栏灵活且左栏固定

http://jsfiddle.net/R5TZH/

<div class="container">
         <div class="columns">
         <div class="right-col">
             Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum
        </div>    
     </div>  
    <div class="left-col">
                <a class="selected" href="#">05 <br><strong>Today</strong></a>
                <a href="#">06 <br><strong>TOM</strong></a>
                <a href="#">07 <br><strong>MON</strong></a>
                <a href="#">08 <br><strong>TUE</strong></a>
                <a href="#">09 <br><strong>WED</strong></a>
                <a href="#">08 <br><strong>THU</strong></a>
                <a href="#">09 <br><strong>FRI</strong></a>
    </div>  
</div>      

CSS:

.container {
    width: 100%;
}

.left-col {
    background: none repeat scroll 0 0 #434345;
    float: left;
    margin-left: -100%;
    padding: 10px;
    width: 80px;
}

.left-col a {
    background: none repeat scroll 0 0 #FFFFFF;
    border-radius: 10px 10px 10px 10px;
    color: #000000;
    float: left;
    font-size: 18px;
    height: 50px;
    margin-bottom: 10px;
    padding: 10px;
    text-align: center;
    width: 60px;
}


.columns {
    float: left;
    width: 100%;
}


.right-col {
    margin-left: 100px;
    background:red;
    height:400px;
}

答案 3 :(得分:0)

用于固定侧栏,样式

position:fixed;

这样做但不是Chrome,所以你可以使用这个

position:absolute;
top:0;
left:0;
bottom:0;
width:180px;// you may change as per your requirement

这适用于所有浏览器:)

编辑:更新内容div

http://jsfiddle.net/MarmeeK/nkprH/5/

我希望这样做,更多回答你的一些工作细节,谢谢