html音乐用了绝对定位就按不了了

html音乐用了绝对定位就按不了了,第1张

html音乐用了绝对定位就按不了了form设置了绝对定位,form里面有个按钮,按钮注册了onclick事件,发现点击按钮没反应;

问题解决:在则枣梁chrome中打开该网页,鼠标移到这个按钮上右键检查,发现form后面定义的html元素在该按钮的上面层,由此可知 ,我们点击按钮,实际上并没有点击到按钮......

只需在岩咐form绝对定位的样式里添加一行代码,让按钮浮上来:

position: absolute

z-index: 99//添加该行代孙运码即可

div的样式中使用相当于浏览器窗口定位——position:fixed。

一、position:fixed属性的含义

fixed:生成绝对定位的元素,相对于浏览器窗口进行定位。元素的位置枣闭塌通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

我们平时所说的固定定位指的就是fixed,设置了固定定位的元素不会随滚动条上下滚动。

二、一般的 position:fixed实现方法

#top{position:fixedbottom:0right:20px}

实现了id为top的元素固定在浏览器的底部和距离右边20个像素的位置

#top{position:fixedtop:20pxright:20px}

实现了id为top的元素固定在距离浏览器的顶部20个像素和距离右边20个像素的位置

三、IE6下position:fixed实现方法

在IE6中是不能直接使用 position:fixed。你需要一些 CSS Hack 来解决它

相同的还是让 <div id="top">...</div>元素固定在浏览器的态谨底部和距离右边的20个像素,这次的代码是:#top{

position:fixed

bottom:0

right:20px

_position:absolute

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))

}

right 跟 left 属性可以用绝对定位的办法解决,而 top 跟 bottom 就需要用上面的表达式来实现。其中在_position:absolute中的 _ 符号只有 IE6 才能识别,目的是为了区分其凳圆他浏览器

1、使元素固定在浏览器窗口的顶部:

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop))

}

2、使元素固定距浏览器窗口的顶部a像素的位置:

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop))

_margin-top:a

}或者

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop+a))

}

3、使元素固定在浏览器窗口的底部:

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))

}

4、使元素固定在距浏览器窗口的底部b像素的位置:

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))

_margin-bottom:b

}或者

#top{

_position:absolute

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||b)-(parseInt(this.currentStyle.marginBottom,10)||b)))

}

四、IE6下的闪动问题

问题还没有完全解决。在用了上面的办法后,你会发现:被固定定位的元素在滚动滚动条的时候会闪动。解决闪动问题的办法是在 CSS 文件中加入:

*html{background-image:url(about:blank)background-attachment:fixed}

其中 * html选择器hack是给 IE6 识别的。

到此,IE6 的 position:fixed问题已经被解决了

CSS中的定位使用position属性的, 此属性有以下几个可选值侍凯举

static

默认值。没孙肆有定位老碧,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明)。

absolute生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。

元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

fixed生成绝对定位的元素,相对于浏览器窗口进行定位。

元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

relative生成相对定位的元素,相对于其正常位置进行定位。

因此,"left:20" 会向元素的 LEFT 位置添加 20 像素。

inherit规定应该从父元素继承 position 属性的值。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11985277.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存