使图像元素固定位置,并在滚动时不移动 [英] make image element fixed position and doesn't move on scroll
本文介绍了使图像元素固定位置,并在滚动时不移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让图片贴在网页左侧,例如「Give Feedback」按钮:
I am trying to make an image stick to left of the page like "Give Feedback" button in:
http://www.hotscripts.com/category/scripts/php/
我有以下HTML代码(我有其他代码,但只是为了示例):
I have the following HTML code ( i have other codes but just to show an example):
<img id="btn" class="btn" src="cl.png" height="161" width="34" alt="clear" />
和以下CSS:
#btn {
display: block;
position: fixed;
left: 0;
top: 54%;
z-index: 100001;
width: 34px;
height: 168px;
margin: -45px 0 0;
padding: 0;
cursor: pointer;
}
由于某种原因,当我滚动页面时,它不会产生相同的效果。
For some reason it's not producing the same effect when I scroll the page. Do I have to use another DIV and wrap the button?
推荐答案
是否在标记中指定了DOCTYPE decalaration?
这应该工作:
Have you specified a DOCTYPE decalaration in your markup? This should work:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
将此添加到文档的顶部。
Add this to the top of your document.
这篇关于使图像元素固定位置,并在滚动时不移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文