栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

为什么[CSS功能]在[浏览器]中不起作用,但在其他浏览器中又起作用呢?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

为什么[CSS功能]在[浏览器]中不起作用,但在其他浏览器中又起作用呢?

虽然它并非总是如此,最常见的原因,就像一个属性的一个

transition
animation
工作在某些浏览器,而不是其他人是因为
供应商前缀

什么是供应商前缀?

在引入Firefox第4版时,CSS过渡模块规范是“工作草案”。在规范最终定稿之前(实际上,这是达到候选推荐标准的时间),浏览器供应
在属性,值和@ -rules中添加了 供应商前缀 ,以防止在规范更改时出现兼容性问题。

供应商前缀正是它们的名称所描述的-
属性或值的特定于供应商的(供应商是指开发浏览器的公司)前缀。它们通常以每种浏览器的特定方式实现,因为属性或值仍处于“候选推荐”阶段之前的许多实验阶段之一,在“候选推荐阶段”中,它们被认为已准备好实现。

最常见的是

-moz-
(Mozilla Firefox),
-webkit-
(Chrome,Safari等)和
-ms-
(MicrosoftInternet Explorer),但还有更多。

我什么时候需要使用它们?

这完全取决于您要提供的浏览器,使用的属性和值以及开发网站的时间。有些网站试图保留最新列表,但它们并不总是准确或保持最新状态。

以下是一些最常见的前缀属性和值。如果您的项目不支持该属性右侧的注释中提到的浏览器,则无需将其包含在CSS中。

转场

无前缀属性有时带有前缀等价物

-webkit-transition

为了获得完整的浏览器支持,必须执行以下操作:

.foo {    -webkit-transition: <transition shorthand value>;     -moz-transition: <transition shorthand value>;        -o-transition: <transition shorthand value>;          transition: <transition shorthand value>;         }

请注意,

-ms-
存在的前缀
transition
,但是仅由不再起作用的IE10的预发布版本实现,因此不再需要它。它在IE10
RTM和更高版本中没有前缀实现。

变身

.foo {    -webkit-transform: <transform-list>;     -ms-transform: <transform-list>;         transform: <transform-list>;}

动画制作

动画需要有前缀属性 前缀,像这样相应的关键帧:

.foo {  -webkit-animation: bar;   -moz-animation: bar;      -o-animation: bar;        animation: bar;         }@-webkit-keyframes bar {  }@-moz-keyframes bar {  }@-o-keyframes bar {  }@keyframes bar {  }

弹性盒

值也可以加上前缀,例如flexbox。:为了获得最大的浏览器兼容性,具体Flexbox的-属性,如

ordinal-group
flex-flow
flex-direction
order
box-orient
,等需要在某些浏览器作为前缀 ,除了 以下几点:

.foo {    display: -webkit-box;      display: -moz-box;         display: -ms-flexbox;      display: -webkit-flex;     display: flex;             -webkit-box-flex: <flex shorthand value>;    -moz-box-flex: <flex shorthand value>;    -webkit-flex: <flex shorthand value>;    -ms-flex: <flex shorthand value>;    flex: <flex shorthand value>;}

计算

.foo {    width: -webkit-calc(<mathematical expression>);     width: -moz-calc(<mathematical expression>);        width: calc(<mathematical expression>);         }

渐变色

有关更多信息,请参见CSS技巧上的CSS渐变。

.foo {    background-color: <color>;     background-image: url(bar.svg);       background-image: -webkit-gradient(linear, left top, right top, from(<color-stop>), to(<color-stop>));       background-image: -webkit-linear-gradient(left, <color-stop>, <color-stop>);       background-image: -moz-linear-gradient(left, <color-stop>, <color-stop>);     background-image: -o-linear-gradient(left, <color-stop>, <color-stop>);     background-image: linear-gradient(to right, <color-stop>, <color-stop>); }

注意,

left
to right
代表同一个方向,左到右的,因此
left
to left
相反
的方式。

边界半径(大多数情况下不需要)

.foo {    -webkit-border-radius: <length | percentage>;     -moz-border-radius: <length | percentage>;        border-radius: <length | percentage>;}

盒子阴影(在大多数情况下不需要)

.foo {    -webkit-box-shadow: <box-shadow shorthand value>;     -moz-box-shadow: <box-shadow shorthand value>;        box-shadow: <box-shadow shorthand value>;}

如何使用Javascript实施它们?

要在Javascript中访问带前缀的属性和事件,请使用与CSS前缀等效的camelCase。同样对于事件侦听器

foo.addEventListener('webkitAnimationIteration',bar )
foo
也是DOM对象
document.getElementsById('foo')
)也是如此。

foo.style.webkitAnimation = '<animation shorthand value>';foo.style.mozAnimation = '<animation shorthand value>';foo.style.oAnimation = '<animation shorthand value>';


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402653.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号