CSS   发布时间:2022-04-17  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了css – 为什么在webkit浏览器中’margin’和’padding’的转换是滞后的?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图对margin和padding属性应用CSS转换.

我想让视觉上的背景变得更大.所以我增加了填充,并相应地减少了空白,所以文本将保持在他们当前的位置.

这是代码

.content {
    width: 600px;
    margin: auto;
}

a.btn {
    background-color: #5C9E42;
    color: #fff;
    text-decoration: none;
    font-size: 35px;
    border-radius: 5px;
    padding: 10px;
    text-shadow: 2px 2px 2px #696969;
    transition: all 0.3s ease;
}

a.btn:hover {
    background-color: #23570E;
    padding: 20px;
    margin: -10px;
}
<div class="content">
    <p>Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <a href="#" class="btn">Bello! How are you doing?</a>
</div>

当您运行代码时,您可以看到,转换是滞后的,文本在悬停时提供了混乱.

但是,它只发生在Chrome,Safari,Opera和其他Webkit浏览器中.
它在Firefox和IE中工作正常.

P.S:使a.btns显示为内联块稍微减少了滞后.可能是什么问题?

解决方法

解决方法是将转换应用于具有背景颜色的伪元素并将其缩放到悬停上.这样,文本仍然是“未经过转换的”,不会摆动:

Demo

CSS:

a.btn {
     position:relative;
    color: #fff;
    text-decoration: none;
    font-size: 35px;
    padding: 10px;
    text-shadow: 2px 2px 2px #696969;
}
a.btn:before{
    content:'';
    position:absolute;
    top:0; left:0;
    border-radius: 5px;
    width:100%; height:100%;
    background-color: #5C9E42;
    z-index:-1;

    -webkit-transition: all .3s ease;
    transition: all .3s ease;
}
a.btn:hover:before {
    background-color: #23570E;

    -webkit-transform: scaleX(1.1) scaleY(1.2);
    -ms-transform: scaleX(1.1) scaleY(1.2);
    transform: scaleX(1.1) scaleY(1.2);
}

您应该包括转换和转换CSS属性的供应商前缀,更多信息请查看CanIUse.

大佬总结

以上是大佬教程为你收集整理的css – 为什么在webkit浏览器中’margin’和’padding’的转换是滞后的?全部内容,希望文章能够帮你解决css – 为什么在webkit浏览器中’margin’和’padding’的转换是滞后的?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: