【每日一练】176—CSS实现的卡片效果

每日一练2年前 (2023)发布 admin
2,003 0

我们一起来看一下今天的练习,具体效果如下:

【每日一练】176—CSS实现的卡片效果

HTML代码:

<!DOCTYPE html>
<html lang=”en” >
<head>
<meta charset=”UTF-8″>
<title>【每日一练】176—CSS实现的卡片效果</title>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<link rel=”icon” type=”image/png” sizes=”32×32″ href=”images/favicon-32×32.png”>
<title>卡片效果</title><link rel=”stylesheet” href=”style.css”>

</head>
<body>
<body>
<div class=”card-container”>
<a href=”/” class=”hero-image-container”>
<img class=”hero-image” src=”https://i.postimg.cc/NfR2yhNs/image-equilibrium.jpg” alt=”Spinning glass cube”/>
</a>
<main class=”main-content”>
<h1><a href=”http://www.webqdkf.com”>五一快乐!</a></h1>
<p>一到放假,所有的不快乐都烟消云散了。</p>
<div class=”flex-row”>
<div class=”coin-base”>
<img src=”https://i.postimg.cc/T1F1K0bW/Ethereum.png” alt=”Ethereum” class=”small-image”/>
<h2>五月天</h2>
</div>
<div class=”time-left”>
<img src=”https://i.postimg.cc/prpyV4mH/clock-selection-no-bg.png” alt=”clock” class=”small-image”/>
<p>05-01</p>
</div>
</div>
</main>
<div class=”card-attribute”>
<img src=”web-01.png” alt=”avatar” class=”small-avatar”/>
<p><a href=”http://www.webqdkf.com”>web前端开发</a></p>
</div>
</div>
</div>
</body>

</body>
</html>

CSS代码:

:root {

font-size: 15px;
–var-soft-blue: hsl(215, 51%, 70%);
–var-cyan: hsl(178, 100%, 50%);
–var-main-darkest: hsl(217, 54%, 11%);
–var-card-dark: hsl(216, 50%, 16%);
–var-line-dark: hsl(215, 32%, 27%);
–var-lightest: white;
–var-heading: normal normal 600 1.5em/1.6em ‘Outfit’, sans-serif;
–var-small-heading: normal normal 400 1em/1em ‘Outfit’, sans-serif;
–var-para: normal normal 300 1em/1.55em ‘Outfit’, sans-serif;
}

html {
box-sizing: border-box;
}

*, *::before, *::after {
box-sizing: inherit;
margin: 0;
}

body {
background-color: var(–var-main-darkest);
}

img {
width: 100%;
border-radius: 15px;
display: block;
}

a {
color: inherit;
}

h1 {
font: var(–var-heading);
color: var(–var-lightest);
padding: 1.2em 0;
}

h2 {
font: var(–var-small-heading);
color: var(–var-lightest);
}

p {
font: var(–var-para);
color: var(–var-soft-blue);
}

span {
color: white;
}

.card-container {
width: 100%;
max-width: 400px;
margin: 2em auto;
background-color: var(–var-card-dark);
border-radius: 15px;
margin-bottom: 1rem;
padding: 2rem;
}

div.flex-row {
display: flex;
justify-content: space-between;
align-items: center;
}

div.coin-base, .time-left, .card-attribute {
display: flex;
align-items: center;
padding: 1em 0;
}

.card-attribute {
padding-bottom: 1.5em;
border-top: 2px solid var(–var-line-dark);
}

a.hero-image-container {
position: relative;
display: block;
}

img.eye {
position: absolute;
width: 100%;
max-width: 2em;
top: 44%;
left: 43%;
}
@media (min-width:400px) {
img.eye {
max-width: 3em;
}
}

.hero-image-container::after {
content: ”;
background-image: url(“https://i.postimg.cc/9MtT4GZY/view.png”);
background-position: center;
background-repeat: no-repeat;
background-size: 5rem;
background-color: hsla(178, 100%, 50%, 0.3);
width: 100%;
height: 100%;
border-radius: 1rem;
position: absolute;
top: 0;
left: 0;
display: block;
z-index: 2;
opacity: 0;
transition: opacity 0.3s ease-out;
}

.hero-image-container:hover::after {
opacity: 1;
}

.small-image {
width: 1.2em;
margin-right: .5em;
}

.small-avatar {
width: 2em;
border-radius: 200px;
outline: 2px solid white;
margin-right: 1.4em;
}

div.attribution {
margin: 0 auto;
width: 100%;
font: var(–var-para);
text-align: center;
padding: 1.5em 0 4em 0;
color: var(–var-line-dark);
}
.attribution a {
color: var(–var-soft-blue);
}

@media (min-width:600px) {
body {
font-size: 18px;
}
}

写在最后

以上就是【每日一练】的全部内容,希望今天的小练习对你有用,如果你觉得有帮助的话,请点赞我,关注我,并将它分享给你身边做开发的朋友,也许能够帮助到他。

我是杨小爱,我们明天见。

© 版权声明

相关文章

暂无评论

暂无评论...