gpt4 book ai didi

基于媒体查询的 CSS 过渡

转载 作者:行者123 更新时间:2023-12-05 00:21:54 28 4
gpt4 key购买 nike

我正在尝试使使用 background-image 设置的背景图像随着页面变窄而淡出。我很确定它可以使用 CSS 转换来完成,但我对它们相当不熟悉。我想我想问的是,你能根据媒体查询将背景图片转换出来吗?

最佳答案

是的,你可以。我做了几个活生生的例子:

@media screen and (max-width: 400px) {
    div { background: navy; }
}

@media screen and (min-width: 400px) {
    div { background: green; }
}
div {
    transition: background 2s linear;
    width: 400px; text-align: center; color: white;
}
@media screen and (max-width: 400px) {
    div { opacity: 0; }
}
@media screen and (min-width: 400px) {
    div { opacity: 1; }
}
div {
    background: url(http://placekitten.com/400/300/);
    transition: opacity 1s linear;
    width: 400px; height: 300px; text-align: center; color: white;
}

我作弊了一点,因为淡出背景图像没有得到广泛支持,但请尝试建议的 cross-fade() 语法(示例在 http://peter.sh/files/examples/cross-fading.html )。

关于基于媒体查询的 CSS 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11149023/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com