MozTW 討論區
https://forum.moztw.org/

css background-attachment 及 background-repeat 互相排斥?
https://forum.moztw.org/viewtopic.php?f=13&t=13349
1 頁 (共 1 頁)

發表人:  victorlamhk [ 2006-03-23, 23:30 ]
文章主題 :  css background-attachment 及 background-repeat 互相排斥?

小弟正在試一些 css, 但發現有些怪現象.

先來兩段 code

代碼:
.heading {

   background-image: url(cap_content.gif);
   background-repeat: no-repeat;
   background-attachment: fixed;
   background-position: center center;
}


代碼:
...


<table width="100%" border="0">
  <tr>
    <td colspan="3" class="heading">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

...


我發現, 如果 background-repeat 和 background-attachment 同時在 css 內出現, 該幅背景圖在 firefox 1.5 / opera 9 preview 2 並不能顯示, 但在 IE 6 或 dreamweaver 8 卻沒有問題. 如果我將 background-repeat / background-attachment 任何一句刪除, 則背景圖可以在任何一個瀏覽器顯示.

想請教各位大大, 為什麼會出現這個現象? background-repeat 和 background-attachment 並不能共存的嗎?

謝~

發表人:  xacid [ 2006-03-24, 01:30 ]
文章主題 : 

可以啊!
你的問題也許是 position 的使用
用了 background-attachment: fixed; 位置的計算應該是相對於頁面,你的表格可能不在顯示範圍
http://www.w3.org/TR/CSS21/colors.html# ... attachment
引言回覆:
Even if the image is fixed, it is still only visible when it is in the content, padding or border area of the element. Thus, unless the image is tiled ('background-repeat: repeat'), it may be invisible.

W3C spec 有各種疑難雜症的解答啊!

發表人:  victorlamhk [ 2006-03-24, 02:06 ]
文章主題 : 

完全明白了. 謝~

我也有看 W3C 的 spec, 只是, 小弟英文實在爛到.... >.< 看不懂....

1 頁 (共 1 頁) 所有顯示的時間為 UTC + 8 小時
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/