
今天我們練習的這個案例是一個産品卡片,這個也是一個很常見且實用的效果,具體效果見下圖:
HTML代碼:
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>【每日一練】29—CSS實作美食卡 UI 設計效果</title>
</head>
<body>
<div class="container">
<div class="card">
<div class="imgBx">
<img src="img1.jpg">
</div>
<div class="contentBx">
<h2>唯有美食不能辜負</h2>
<p>人世間除了美人和美景,還有美食,最不能辜負的就是人間美食,我們花了五千年的時間修煉成為人,來人世間一趟多不容易呀,想吃就吃。</p>
<div class="price">
<h3><sup>¥</sup>19<small>.99</small></h3>
<a href="http://www.webqdkf.com" target="_blank">想吃就吃</a>
</div>
</div>
</div>
<div class="card">
<div class="imgBx">
<img src="img2.jpg">
</div>
<div class="contentBx">
<h2>唯有美食不能辜負</h2>
<p>人世間除了美人和美景,還有美食,最不能辜負的就是人間美食,我們花了五千年的時間修煉成為人,來人世間一趟多不容易呀,想吃就吃</p>
<div class="price">
<h3><sup>¥</sup>29<small>.99</small></h3>
<a href="http://www.webqdkf.com" target="_blank">想吃就吃</a>
</div>
</div>
</div>
<div class="card">
<div class="imgBx">
<img src="img3.jpg">
</div>
<div class="contentBx">
<h2>唯有美食不能辜負</h2>
<p>人世間除了美人和美景,還有美食,最不能辜負的就是人間美食,我們花了五千年的時間修煉成為人,來人世間一趟多不容易呀,想吃就吃</p>
<div class="price">
<h3><sup>¥</sup>39<small>.99</small></h3>
<a href="http://www.webqdkf.com" target="_blank">想吃就吃</a>
</div>
</div>
</div>
</div>
</body>
</html>
CSS代碼:
*
{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
body
{
display: flex;
justify-content: center;
align-items: center;
background: #122746;
min-height: 100vh;
}
.container
{
position: relative;
width: 1100px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 40px 0;
}
.container .card
{
position: relative;
width: 300px;
margin: 20px;
background: #fff;
}
.container .card .imgBx
{
position: relative;
width: 300px;
height: 225px;
}
.container .card .imgBx img
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.container .card .contentBx
{
position: relative;
padding: 20px;
}
.container .card .contentBx h2
{
font-size: 20px;
font-weight: 700;
letter-spacing: 1px;
color: #111;
}
.container .card .contentBx p
{
color: #111;
}
.container .card .contentBx .price
{
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
}
.container .card .contentBx .price h3
{
font-size: 28px;
color: #607d8b;
}
.container .card .contentBx .price h3 sup
{
font-weight: 500;
}
.container .card .contentBx .price a
{
position: relative;
display: inline-block;
background: #ff5064;
padding: 7px 15px;
text-decoration: none;
color: #fff;
letter-spacing: 1px;
font-weight: 500;
}
.container .card .contentBx .price a:hover
{
background: #fb2d45;
}
寫在最後
以上就是我們今天的【每日一練】的全部内容,希望今天的小練習對你有用,如果你覺得有幫助的話,請點贊我,關注我,并将它分享給你身邊做開發的朋友,也許能夠幫助到他。
我是楊小愛,我們明天見。
推薦視訊内容