首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS过渡背景- Safari中的图像跳转悬停

问CSS过渡背景- Safari中的图像跳转悬停
EN

Stack Overflow用户
提问于 2017-08-12 22:45:29
回答 2查看 1.9K关注 0票数 1

我在Safari中遇到了一个过渡效果的问题,需要一些帮助。我的CSS悬停像它应该的那样交换了背景图像,但是悬停图像从它的位置向上和向左‘跳跃’(这是我不想发生的)。谢谢。

结构:

​

代码语言:javascript
复制
.sidebar .widget {
	height: 276px;
	width: 326px;
	background:url('/wp-content/themes/a-theme/svg/polygon-image.svg') no-repeat center center;
	background-size: 100%;
}

.sidebar .widget:hover {
	background:url('/wp-content/themes/a-theme/svg/polygon-image-hover.svg') no-repeat center center;
	background-size: 100%;
	transition: 0.5s ease-in-out;
}
代码语言:javascript
复制
<div class="sidebar">
	<aside id="black-studio-tinymce-18" class="widget widget_black_studio_tinymce">
		<div class="textwidget">
			<h3 style="text-align: center;">Sample Text<br></h3>
		</div>
	</aside>
</div>

​

EN

回答 2

Stack Overflow用户

发布于 2017-08-12 22:58:06

避免浏览器的bug并进行清理:

代码语言:javascript
复制
.sidebar .widget {
    height: 276px;
    width: 326px;
    background-repeat:no-repeat;
    background-position: center center;
    background-image:url(/wp-content/themes/a-theme/svg/polygon-image.svg);
    background-size: 100%;
    transition:background-image 0.5s ease-in-out;
}
.sidebar .widget:hover {
    background-image:url(/wp-content/themes/a-theme/svg/polygon-image-hover.svg);
}
票数 0
EN

Stack Overflow用户

发布于 2017-08-14 20:56:00

在您的帮助下,我修改了我的CSS以获得我需要的内容。我有一个多边形形状的背景图像和一个图形在它的中间。我保留了图形,转而使用CSS多边形作为形状,现在我的悬停效果在Firefox、Chrome和Safari中都有效。

请看我下面的CSS,再次感谢你的回复。

​

代码语言:javascript
复制
sidebar .widget {
	background: url('/wp-content/uploads/2017/08/image.png') no-repeat center center;
	background-color: rgba(255, 165, 0, 0.85);
	background-size: 70%;
	-webkit-clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
	clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
	height: 276px;
	width: 326px;
	display: flex;
	justify-content: center;
	align-items: center;
}

.sidebar .widget:hover {
	background: url('/wp-content/uploads/2017/08/image.png') no-repeat center center;
	background-color: rgba(108, 218, 244, 0.8);
	background-size: 80%;
	-webkit-clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
	clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
	height: 276px;
	width: 326px;
	transition: 0.5s ease-in-out;
}

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45651510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档