如何通过执行“功能”来避免浏览器嗅探而是检测...?
所以,假设我有一个内联块元素。所以这不适用于 ie6 或 FF2...
假设我用 css hacks 并使用 -moz-inline-stack 来补偿它...
现在,假设 inline-block 元素也是position:relative,所以它是一个容器,并且有一个子元素,其位置为绝对位置,top:0,right:0。
在较旧的浏览器中,子元素位于屏幕的右上角,而不是 inline-block 容器元素的右上角。 现在,
我可以通过在我的子元素周围包裹一个 div 并使其成为“相对位置”来解决这个问题...但如果可能的话,我想避免不必要的标记。
最初我想做:
if (browser == ie6 || browser == ff2) {
wrap child element with div for older browser..
}
else {
assume everything is fine
}
但我认为这样做会更好:
if (child element is at the top right of the screen) {
wrap child element with div for older browser..
}
else {
assume everything is fine
}
所以我只是很好奇,这里的人们会如何推荐这种事情。
谢谢!
So, let's say that I have an element that is inline-block. So this won't work with ie6 or FF2...
Say I compensate for it with css hacks and using -moz-inline-stack...
Now, let's say the inline-block element is also position: relative, so it is a container and has a child element with position absolute, top:0, right: 0.
In older browsers, the child element is in the top right of the screen, instead of in the top right of the inline-block container element...
Now, I can fix this by wrapping a div around my child element and make it 'position relative'... But I would like to avoid having unnecessary markup if possible.
Initially I wanted to do:
if (browser == ie6 || browser == ff2) {
wrap child element with div for older browser..
}
else {
assume everything is fine
}
but I am thinking something like this would be better to do:
if (child element is at the top right of the screen) {
wrap child element with div for older browser..
}
else {
assume everything is fine
}
So I am just curious, how people here would recommend this sort of thing.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,Modernizr 的浏览器功能检测效果最好。现代化
虽然它可能不适用于您的特定场景,但 Modernizr 也可以进行 CSS 功能检测。例如,
In general, Modernizr does browser feature detection best. Modernizr
While it may not be applicable to your particular scenario, Modernizr does CSS feature detection as well. For example,