我正在参加中秋创意投稿大赛,详情请看:中秋创意投稿大赛
大家好,今天我们将看到如何只使用 HTML 和 CSS 制作完全响应式的中秋礼品卡页面。
要查看演示或你想要编码教程。你可以观看下面的教程。
因此,不要浪费更多时间,让我们看看如何对此进行编码。
源码和在线演示
对于这个项目,我们只有index.html
和style.css
文件。图片我就直接用的掘金官方给的字节跳动中秋礼盒,点击这里从GitHub下载。
在线演示地址:haiyong.site/zhongqiulip…
让我们开始编码。
基本结构
首先编写基本的 HTML5 结构并将style.css
文件链接到页面。然后像这样创建产品卡结构。
HTML
<div class="product">
<div class="product-img">
<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1f0220e52f77453c893731f62630a867~tplv-k3u1fbpfcp-watermark.awebp" alt="">
<span class="tag">中秋礼盒</span>
</div>
<div class="product-listing">
</div>
</div>
复制代码
CSS
@import url('https://fonts.googleapis.com/css2?family=Dosis:wght@600&family=Roboto:wght@300;400;500;700;900&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
width: 100%;
min-height: 100vh;
position: relative;
display: flex;
justify-content: center;
align-items: center;
background: #966e4f;
font-family: 'roboto', sans-serif;
}
body::before{
content: '';
position: absolute;
left: 0%;
transform: translateX(-50%) skewX(-15deg);
width: 20px;
height: 100%;
background: #966e4f;
border-left: 60px solid #eae3d2;
border-right: 30px solid #eae3d2;
opacity: 0;
animation: slide-in 2s 1.5s forwards 1;
}
@keyframes slide-in{
100%{
opacity: 1;
left: 50%;
}
}
.product{
position: relative;
width: 1000px;
min-width: 350px;
min-height: 500px;
height: auto;
display: flex;
justify-content: center;
align-items: center;
}
.product-img{
width: 40%;
height: 500px;
background: #fff;
position: relative;
opacity: 0;
transform: translateY(-50px);
animation: fade-in 1s forwards 1;
}
.product-img img{
width: 100%;
height: 100%;
object-fit: contain;
user-select: none;
}
.tag{
position: absolute;
top: 20px;
left: -10px;
transform-origin: left;
opacity: 0;
transform: rotate(-90deg);
text-transform: capitalize;
color: #eae3d2;
padding: 5px 10px;
width: 100px;
font-size: 18px;
text-align: center;
background: #292929;
user-select: none;
animation: tag .5s 1s forwards 1;
}
@keyframes tag{
100%{
opacity: 1;
transform: rotate(-20deg);
}
}
.product-listing{
width: 60%;
min-height: 500px;
height: auto;
background: #292929;
padding: 40px;
display: flex;
justify-content: center;
color: #eae3d2;
opacity: 0;
transform: translateY(50px);
animation: fade-in 1s forwards 1;
}
@keyframes fade-in{
100%{
opacity: 1;
transform: translateY(0);
}
}
复制代码
输出
产品信息元素
很好 现在我们创建产品信息元素。这里我用的《折桂令·中秋》中的诗句,作者是元代的张养浩
一轮飞镜谁磨?照彻乾坤,印透山河。玉露泠泠,洗秋空银汉无波,比常夜清光更多,尽无碍桂影婆娑。老子高歌,为问嫦娥,良夜恹恹,不醉如何?
HTML
<div class="product-listing">
<div class="content">
<h1 class="name">中秋礼盒</h1>
<p class="info">
一轮飞镜谁磨?照彻乾坤,印透山河。玉露泠泠,洗秋空银汉无波,比常夜清光更多,尽无碍桂 影婆娑。老子高歌,为问嫦娥,良夜恹恹,不醉如何?
</p>
<p class="price">¥ 299</p>
<div class="btn-and-rating-box">
<div class="rating">
<img src="http://haiyong.site/wp-content/uploads/2021/09/star.png" alt="">
<img src="http://haiyong.site/wp-content/uploads/2021/09/star.png" alt="">
<img src="http://haiyong.site/wp-content/uploads/2021/09/star.png" alt="">
<img src="http://haiyong.site/wp-content/uploads/2021/09/star.png" alt="">
<img src="http://haiyong.site/wp-content/uploads/2021/09/star.png" alt="">
</div>
<a href="http://haiyong.site/moyu"><button class="btn">加入购物车</button></a>
</div>
</div>
</div>
复制代码
CSS
.name{
font-family: 'dosis';
font-size: 70px;
text-transform: capitalize;
}
.info{
font-size: 18px;
line-height: 30px;
margin: 50px 0;
}
.price{
font-size: 70px;
font-weight: 100;
margin-bottom: 20px;
}
.btn-and-rating-box{
width: 100%;
display: flex;
justify-content: space-between;
}
.rating{
width: fit-content;
display: flex;
justify-content: center;
align-items: center;
}
.rating img{
width: 20px;
height: 20px;
margin: 0 2px;
}
.btn{
background: #eae3d2;
color: #292929;
border: none;
text-transform: capitalize;
font-size: 16px;
padding: 10px 20px;
cursor: pointer;
}
.btn:hover{
background-color: #eedbaf;
}
复制代码
输出
使其具有响应性
到这里我们的中秋礼品卡就做好了。现在我们让它具有响应性。
@media (max-width: 1100px){
body::before{
transform: translateX(-50%) skewX(-5deg);
}
.product{
flex-direction: column;
width: 90%;
margin: 5vh 0;
}
.product-img{
width: 100%;
height: 300px;
}
.product-listing{
width: 100%;
min-height: auto;
}
.name,.price{
font-size: 50px;
}
.info{
font: 16px;
}
}
复制代码
输出
? wuhu ! 起飞 !
到这里就全部完成了。如果你还有什么疑问请在评论中告诉我。希望你在本教程中了解我是如何使用纯 HTML、CSS 创建完全响应式的中秋礼品卡。如果你愿意的话可以在我的公众号回复代码获取完整源码。
我之前使用 HTML、CSS 和 JavaScript 制作了更多类型的小工具,如果你愿意,可以查看这些设计。
基于HTML、CSS、JS的前端优质项目专栏
基于HTML、CSS 和 Three.js 的喷火龙小游戏
使用 HTML、CSS 和 JavaScript 制作的随机密码生成器
?使用 HTML、CSS 和 JavaScript 的酷黑主题模拟时钟
使用 HTML、CSS 和 JS 创建响应式可过滤的游戏+工具展示页面
使用 HTML、CSS、JS 和 API 制作一个很棒的天气 Web 应用程序
我已经写了很长一段时间的技术博客,并且主要通过掘金发表,这是我的一篇中秋礼品卡页面教程。我喜欢通过文章分享技术与快乐。你可以访问我的博客: juejin.cn/user/204034… 以了解更多信息。希望你们会喜欢!?
? 欢迎大家在评论区提出意见和建议!?
如果你真的从这篇文章中学到了一些新东西,喜欢它,收藏它并与你的小伙伴分享。?最后,不要忘了❤️或?支持一下哦。