div+css实现网格灰色图片悬浮变彩色放大交互效果代码
代码语言:html
所属分类:图片放大
代码描述:div+css实现网格灰色图片悬浮变彩色放大交互效果代码
代码标签: div css 网格 灰色 图片 悬浮 彩色 放大 交互
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> /* RESET STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ @import url("https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,100..900;1,100..900&display=swap"); :root { --height: 80vh; --half-height: calc(var(--height) / 2); --transition: all 1s; } * { box-sizing: border-box; } body { font-family: "Bitter", serif; margin: 20px 0; padding: 0 15px; background: #cae9ff; } a { color: inherit; } .notification { display: none; position: absolute; top: 0; right: 0; padding: 10px; font-size: 0.85em; background: #e9c46a; } /* MAIN STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .grid, .sub-grid, .grid .card { transition: var(--transition); } .grid { max-width: 1600px; margin: 0 auto; box-shadow: 0 15px 30px rgba(0, 0, 0, 0.35); } .card { cursor: pointer; figure, img { width: 100%; height: 100%; } figure { position: relative; margin: 0; overflow: hidden; } img { -o-object-fit: cover; object-fit: cover; background: #333; } figcaption { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: grid; place-items: center; font-size: 1.5em; line-height: 1.3; text-align: center; padding: 10px; color: white; background: rgba(0, 0, 0, 0.5); span { display: block; font-size: 0.75em; } } } @media (max-width: 899px) { .card { height: var(--half-height); } } @media (min-width: 900px) { .grid, .sub-grid { display: grid; } .grid { grid-template-columns: 2fr 1fr 1fr; } .sub-grid { grid-template-rows: var(--half-height) var(--half-height); } .sub-grid-1 { grid-template-columns: 1fr 1fr auto; } .sub-grid-1 .card:last-child { grid-column: 1/-1; } /*.sub-grid-2 { grid-template-columns: 1fr; }*/ .grid > .card { height: var(--height); } } @media (hover: hover) and (min-width: 900px) { .notification { display: block; } .grid:has(.sub-grid-1 .card:first-of-type:hover) .sub-grid-1 { grid-template-columns: 1fr 0fr auto; } .grid:has(.sub-grid-1 .card:nth-of-type(2):hover) .sub-grid-1 { grid-template-columns: 0fr 1fr auto; } .grid:has(.sub-grid-1 .card:last-of-type:hover) .sub-grid-1 { grid-template-rows: 0 var(--height); } .grid:has(> .card:hover) { grid-template-columns: 0fr 1fr 0fr; } .grid:has(.sub-grid-2 .card:first-of-type:hover) .sub-grid-2 { grid-template-rows: var(--height) 0; } .grid:has(.sub-grid-2 .card:last-of-type:hover) .sub-grid-2 { grid-template-rows: 0 var(--height); } .card { filter: grayscale(1); figcaption { opacity: 0; } &:hover { filter: grayscale(0); figcaption { opacity: 1; transition: opacity 0.5s 0.5s; } } } } /* FOOTER STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .page-footer { position: fixed; right: 0; bottom: 50px; display: flex; align-items: center; padding: 5px; font-size: 0.9em; background: white; } .page-footer a { display: flex; margin-left: 4px; } </style> </head> <body translate="no"> <div class="grid"> <div class="sub-grid su.........完整代码请登录后点击上方下载按钮下载查看
网友评论0