2013-05-09 45 views
1

我是初學者,談到CSS定位。如何停止位置的元素:從重疊的靜態定位元素中修復

我的問題: 我正在嘗試創建一個包含社交網站鏈接的元素。我希望這個元素是「position:fixed;」所以它不會滾動,我也希望它在我的#social div(我試圖去做的這個元素)和#bodycontainer div(它包含我的網站的其餘部分)之間有一個空白 - 我不想要保證金引用關閉瀏覽器窗口(但基於關閉#bodycontainer股利

基本上我想:

  • 重疊#bodycontainer網站(其他地區)禁止在#social格,但保持#社交網站的位置:固定
  • 在#social和#bodycontainer之間保留一段距離我不希望將瀏覽器窗口的邊距留在瀏覽器窗口,我希望它基於我的#bodycontainer div。我該怎麼做? (一世希望#social在#bodycontainer左側5px。

我的代碼(縮短):

<body> 

<div id="social"> 

<div id="socialimages"> 
<a href="http://facebook.com/connor.lydon" target="_blank"> 
<img src="fblogo.gif"> 
</a> 
<a href="http://instagram.com/connorlydon" target="_blank"> 
<img src="instalogo.gif"> 
</a> 
</div> 
</div> 




<div id="bodycontainer"> 
<img src="lydon_websiteanimation.gif" id="header"> 
</div> 

</body> 


#social { 
position: fixed; 
float: left; 
width: 200px; 
height: 100px; 
margin-left: 10px; 
background-image: url(socialtalk.png); 
background-repeat: no-repeat; 
background-position: top-left; 
} 

#socialimages { 
width: 45px; 
height: 100px; 
margin-left: 200px; 
margin-top: 60px; 
} 

#bodycontainer { 
margin-left: auto; 
margin-right: auto; 
width: 726px; 
} 

我猜測,這是一個非常簡單的問題,我表示歉意。我看了很多指南,並且一直無法自己想出來。

如果您想重新說明我的部分問題,以便更好地理解它,請說 - 我很樂意!

我非常感謝任何幫助,我會收到。

謝謝。

+0

我不能看到你的問題,你可以使用http://jsfiddle.net/h9FqE/顯示說明問題? – 2013-05-09 21:13:17

回答

0

試試這個:

<body> 

<div id="social"> 

<div id="socialimages"> 
<a href="http://facebook.com/connor.lydon" target="_blank"> 
<img src="fblogo.gif"> 
</a> 
<a href="http://instagram.com/connorlydon" target="_blank"> 
<img src="instalogo.gif"> 
</a> 
</div> 
</div> 




<div id="bodycontainer"> 
<img src="lydon_websiteanimation.gif" id="header"> 
</div> 

</body> 


#social { 
position: fixed; 
float: left; 
width: 200px; 
height: 100px; 
margin-left: 10px; 
background-image: url(socialtalk.png); 
background-repeat: no-repeat; 
background-position: top-left; 
} 

#socialimages { 
width: 45px; 
height: 100px; 
margin-left: 200px; 
margin-top: 60px; 
} 

#bodycontainer { 
width: 726px; 
position: absolute; 
left: 50%; 
margin-left: -363px; 
z-index: 1; 
}