如何通过执行“功能”来避免浏览器嗅探而是检测...?

发布于 2024-10-31 03:22:36 字数 724 浏览 5 评论 0原文

所以,假设我有一个内联块元素。所以这不适用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-11-07 03:22:36

一般来说,Modernizr 的浏览器功能检测效果最好。现代化

向元素添加类
这使您可以针对特定目标
您的浏览器功能
样式表。你实际上不需要
编写任何 Javascript 来使用它。

虽然它可能不适用于您的特定场景,但 Modernizr 也可以进行 CSS 功能检测。例如,

你有没有想过
CSS 中的 if 语句
提供很酷的功能,例如
边界半径?好吧,有了 Modernizr
你可以做到这一点!

In general, Modernizr does browser feature detection best. Modernizr

adds classes to the element
which allow you to target specific
browser functionality in your
stylesheet. You don't actually need to
write any Javascript to use it.

While it may not be applicable to your particular scenario, Modernizr does CSS feature detection as well. For example,

Have you ever wanted to do
if-statements in your CSS for the
availability of cool features like
border-radius? Well, with Modernizr
you can accomplish just that!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文