纯css实现带图片卡片选择效果代码
代码语言:html
所属分类:布局界面
代码描述:纯css实现带图片卡片选择效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/reset.min.css"> <style> .card { --background: #fff; --background-checkbox: #0082ff; --background-image: #fff, rgba(0, 107, 175, 0.2); --text-color: #666; --text-headline: #000; --card-shadow: #0082ff; --card-height: 190px; --card-width: 190px; --card-radius: 12px; --header-height: 47px; --blend-mode: overlay; --transition: 0.15s; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .card:nth-child(odd) .card__body-cover-image { --x-y1: 100% 90%; --x-y2: 67% 83%; --x-y3: 33% 90%; --x-y4: 0% 85%; } .card:nth-child(even) .card__body-cover-image { --x-y1: 100% 85%; --x-y2: 73% 93%; --x-y3: 25% 85%; --x-y4: 0% 90%; } .card__input { position: absolute; display: block; outline: none; border: none; background: none; padding: 0; margin: 0; -webkit-appearance: none; } .card__input:checked ~ .card__body { --shadow: 0 0 0 3px var(--card-shadow); } .card__input:checked ~ .card__body .card__body-cover-checkbox { --check-bg: var(--background-checkbox); --check-border: #fff; --check-scale: 1; --check-opacity: 1; } .card__input:checked ~ .card__body .card__body-cover-checkbox--svg { --stroke-color: #fff; --stroke-dashoffset: 0; } .card__input:checked ~ .card__body .card__body-cover:after { --opacity-bg: 0; } .card__input:checked ~ .card__body .card__body-cover-image { --filter-bg: grayscale(0); } .card__input:disabled ~ .card__body { cursor: not-allowed; opacity: 0.5; } .card__input:disabled ~ .card__body:active { --scale: 1; } .card__body { display: grid; grid-auto-rows: calc(var(--card-height) - var(--header-height)) auto; background: var(--background); height: var(--card-height); width: var(--card-width); border-radius: var(--card-radius); overflow: hidden; position: relative; cursor: pointer; box-shadow: var(--shadow, 0 4px 4px 0 rgba(0, 0, 0, 0.02)); -webkit-transition: box-shadow var(--transition), -webkit-transform var(--transition); transition: box-shadow var(--transition), -webkit-transform var(--transition); transition: transform var(--transition), box-shadow var(--transition); transition: transform var(--transition), box-shadow var(--transition), -webkit-transform var(--transition); -webkit-transform: scale(var(--scale, 1)) translateZ(0); transform: scale(var(--scale, 1)) translateZ(0); } .card__body:active { --scale: 0.96; } .card__body-cover { --c-border: var(--card-radius) var(--card-radius) 0 0; --c-width: 100%; --c-height: 100%; position: relative; overflow: hidden; } .card__body-cover:after { content: ""; position: absolute; left: 0; top: 0; width: var(--c-width); height: var(--c-height); border-radius: var(--c-border); background: -webkit-gradient(linear, left top, right bottom, from(var(--background-image))); background: linear-gradient(to bottom right, var(--background-image)); mix-blend-mode: var(--blend-mode); opacity: var(--opacity-bg, 1); -webkit-transition: opacity var(--transition) linear; transition: opacity var(--transition) linear; } .card__body-cover-image { width: var(--c-width); height: var(--c-height); -o-object-fit: cover; object-fit: cover; border-radius: var(--c-border); -webkit-filter: var(--filter-bg, grayscale(1)); filter: var(--filter-bg, grayscale(1)); -webkit-clip-path: polygon(0% 0%, 100% 0%, var(--x-y1, 100% 90%), var(--x-y2, 67% 83%), var(--x-y3, 33% 90%), var(--x-y4, 0% 85%)); clip-path: polygon(0% 0%, 100% 0%, var(--x-y1, 100% 90%), var(--x-y2, 67% 83%), var(--x-y3, 33% 90%), var(--x-y4, 0% 85%)); } .card__body-cover-checkbox { background: var(--check-bg, var(--background-checkbox)); border: 2px solid var(--check-border, #fff); position: absolute; right: 10px; top: 10px; z-index: 1; width: 28px; height: 28px; border-radius: 50%; opacity: var(--check-opacity, 0); transition: transform var(--transition), opacity calc(var(--transition) * 1.2) linear, -webkit-transform var(--transition) ease; -webkit-transform: scale(var(--check-scale, 0)); transform: scale(var(--check-scale, 0)); } .card__body-cover-checkbox--svg { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0