我想要一個GIF保持在頁面的中心,而不管用戶在哪裏滾動。我希望那裏有一個錯覺,那就是圖像'漂浮在頁面上方'而不是它上面。在HTML頁面上浮動一個gif圖像
我相信CSS會是這樣做的方式嗎?假設有一個名爲foo.gif
的圖像,CSS會做什麼?
我想要一個GIF保持在頁面的中心,而不管用戶在哪裏滾動。我希望那裏有一個錯覺,那就是圖像'漂浮在頁面上方'而不是它上面。在HTML頁面上浮動一個gif圖像
我相信CSS會是這樣做的方式嗎?假設有一個名爲foo.gif
的圖像,CSS會做什麼?
沒有你想要什麼更具體的指導,爲什麼呢,我能提供的最好的是:
img {
position: fixed; /* forces the element to stay fixed in relation to the viewport */
top: 50%; /* sets the top of the image 50% of the page height */
left: 50%; /* sets the left side of the image 50% across the page */
margin-left: -100px; /* moves the image half of its own width to the left-side of the page */
margin-top: -93px; /* moves the image half its height 'up' the page */
box-shadow: 0.5em 0.5em 0.7em #333; /* to give the illusion of 'floating'
border-radius: 1em;
}
謝謝你David。 :) – 2014-01-28 10:55:11
你的意思是*浮動*就像一個[陰影](HTTP:// EN .wikipedia.org /維基/ Drop_shadow)?你到目前爲止嘗試了什麼? ['position:fixed'](http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/),['margin:auto'](http:// bluerobot。 com/web/css/center1.html),...? – 2012-02-09 10:35:15