2011-02-06 56 views
0

如何在所有屏幕分辨率上左側的容器div製作固定的div格式?對齊固定問題

#container{ 
    background-color:#000; 
    filter:alpha(opacity=85); 
    -moz-opacity: 0.85; 
    opacity: 0.85; 
    width:1000px; 
    min-height:1275px; 
    height:100%; 
    margin:auto; 
} 

#fixed{ 
    position: fixed; 
    top:150px; 
} 
+0

刪除 「保證金:汽車;」? – kirilloid 2011-02-06 14:31:47

回答

0

這是有點不可能與固定的CSS屬性,但你可以做的是定位容器div相對位置的固定div絕對然後模擬Jquery的固定效果。 例如

容器{

background-color:#000; 
filter:alpha(opacity=85); 
-moz-opacity: 0.85; 
opacity: 0.85; 
width:1000px; 
min-height:1275px; 
height:100%; 
margin:auto; 
position:relative; 
} 

固定{

width:100px; 
position:absolute; 
top:150px; 
left:-100px; 

}

jQuery的

$(文件)。就緒(函數(){ 變量$ scrollingDiv = $(「#fixed」); $(window).scroll(function(){ $ scrollingDiv .stop() .animate({「marginTop」:($(window).scrollTop()+ 0)+「px」},「slow」 ); }); });
+0

我們在#fixed div中添加了另一個固定位置的div,它工作正常。 – 2011-02-08 15:48:57

0

不知道我是否正確理解你。也許這將工作:

#container{ 
    background-color:#000; 
    filter:alpha(opacity=85); 
    -moz-opacity: 0.85; 
    opacity: 0.85; 
    width:1000px; 
    min-height:1275px; 
    height:100%; 
    margin:auto; 

    position:relative; 
} 

#fixed{ 
    position: absolute; 
    top:150px; 
} 

請看:http://jsfiddle.net/gQP8X/2/注意:我已經做了一些修改,以更好地符合的jsfiddle。

0

試試這個,

#wrapper{ 
    width: 600px; 
    height: 2000px; 
    margin: auto; 
    position: relative; 

} 

#content{ 
    margin: auto; 
    width: inherit; 
    height: 100%; 
    float: left; 
} 

#sidebar{ 
    width: 100px; 
    height: 100%; 
    position: absolute; 
     left: -100px; 
} 

#fixed{ 
    top: 100px; 
    width: 100px; 
    height: 150px; 
    position: fixed; 
    background-color: cyan; 
} 

而且

<div id="wrapper"> 
     <div id="content"></div> 
     <div id="sidebar"> 
      <div id="fixed">something</div> 
     </div> 
    </div>