flex实战——购物商品详情页面实现

本文中复现了类似购物界面的页面,基本上包含了所有的Flex知识点。通过网页版模拟手机版实现前端购物界面,内容大致包括以下几部分:

  • 内容展现部分
    该部分中所有显示出来的文字信息都是通过Flex布局方式设计,好处是没有给文字或图片设置具体位置,会根据不同的手机或屏幕大小,伸展成合适的大小(浏览器打开时一定要选择手机模拟,拉伸浏览器大小可以看到效果)
  • 底部固定区域部分
    底部区域设置position:fixed,设置成fixed会被移除正常文档流,即元素的位置在屏幕滚动时不会发生变化。

FlexBox理论部分链接: https://blog.csdn.net/weixin_43675314/article/details/134402257
源码链接https://gitee.com/pan-fahui/flexbox

内容

具体的index.html部分为:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/index.css">
    <title>商品详情页</title>
</head>
<body>
    <img class="book_cover" src="./images/book-cover.jpg" alt="">
    <div class="head">
        <div class="price">
            <div class="price_now">¥54</div>
            <div class="price_origin">¥99
                <div class="line"></div>
            </div>
        </div>
        <div class="look">25人看过</div>
    </div>
    <div class="title-area">
        <div class="title">代码整洁之道</div>
        <div class="product">推广商品</div>
    </div>
    <div class="goods-area">
        <div class="goods">发货</div>
        <div class="express-area">
            <div class="express-title">快递包邮发货</div>
            <div class="express-content">付款后48小时发货</div>
        </div>
    </div>
    <div class="grey"></div>
    <div class="recommdand-area">
        <div class="recommand">
            <div class="shop">本店推荐</div>
            <div class="all-product">全部商品</div>
        </div>
        <div class="book-display">
            <div  class="displa">
                <img class="image" src="./images/book-cover.jpg" alt="">
                <div class="display-title">
                    <div class="title">代码整洁之道</div>
                    <div class="price">¥54</div>
                </div>
            </div>
            <div class="displa">
                <img class="image" src="./images/book-cover.jpg" alt="">
                <div class="display-title">
                    <div class="title">代码整洁之道</div>
                    <div class="price">¥54</div>
                </div>
            </div>
            <div class="displa">
                <img class="image" src="./images/book-cover.jpg" alt="">
                <div class="display-title">
                    <div class="title">代码整洁之道</div>
                    <div class="price">¥54</div>
                </div>
            </div>
        </div>
    </div>
    <div class="grey"></div>
    <div class="product-detail">
        <div class="detail">商品详情</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="detail-content">ISBN: 978-7-115-52413-3</div>
        <div class="title">【商品详情】</div>
        <p>软件质量,不但依赖架构及项目管理,而且与代码质量
            紧密相关。这一点,无论是敏捷开发流派还是传统开发
            流派.都不得不承认
            本书提出一种观点:代码质量与其整洁度成正比。干净
            的代码,既在质量上较为可靠,也为后期维护、升级奠
            定了良好基础。作为编程领域的佼佼者,本书作者给出
            了
            一 系列行之有效的整洁代码操作实践。</p>
    </div>
    <div class="buttom-area">
        <div class="shop-area">
            <img class="image" src="./images/home.png" alt="">
            <p class="name">店铺</p>
        </div>
        <div class="shop-area">
            <img class="image" src="./images/chat.png" alt="">
            <p class="name">客服</p>
        </div>
        <div class="shop-area">
            <img class="image" src="./images/shopping.png" alt="">
            <p class="name">购物袋</p>
        </div>
        <div class="add">加入购物车</div>
        <div class="buy"><div class="inner">买</div></div>
    </div>

    
</body>
</html>

index.css部分为:

body{
    margin: 0;
    padding: 0;
}
.book_cover{
    display: flex;
    justify-content: center;
    width: 100%;
    height: 420rpx;
}
.head{
    display: flex;
    justify-content: space-between;
    margin: 5px 23px;
    .price{
        display: flex;
        .price_now{
            font-size: 26px;
            color: #ed7955;
        }
        .price_origin{
            font-size: 13px;
            color: #ccccce;
            .line{
                border: 1px solid #ccccce;
                margin-top: -9px;
                width: 110%;

            }
        }
    }
    .look{
        font-size: 17px;
        color: #e3d6cc;
    }
}
.title-area{
    display: flex;
    justify-content: space-between;
    margin: 22px 23px;
    padding-bottom: 23px;
    border-bottom: 1px solid #e2e2e2;
    .title{
        font-size: 20px;
    }
    .product{
        font-size: 16px;
    }
}
.goods-area{
    display: flex;
    margin-left: 22px;
    margin-bottom: 24px;
    .goods{
        color: #999999;
        font-size: 17px;
        margin-right: 15px;
    }
    .express-area{
        .express-title{
            font-size: 17px;
            margin-bottom: 8px;
        }
        .express-content{
            color: #cfdbeb;
            font-size: 14px;
        }
    }
}
.grey{
    height: 5px;
    width: 100vw;
    background-color: #cccccc;
}
.recommdand-area{
    display: flex;
    flex-direction: column;
    margin: 20px 20px;
    .recommand{
        margin-bottom: 28px;
        display: flex;
        justify-content: space-between;
        .shop{
            font-size: 17px;
            font-weight: bold;
        }
        .all-product{
            font-size: 17px;
            color: #a69999;
        }
    }
    .book-display{
        display: flex;
        justify-content: space-evenly;
        .displa{
            display: flex;
            flex-direction: column;

            .image{
                width: 100px;
                height: 120px;
            }
            .display-title{
                .title{
                    font-size: 15px;
                }
                .price{
                    font-size: 13px;
                    color: #f4a655;
                }
            }
        }
    }
}
.product-detail{
    margin-top: 20px;
    margin-left: 20px;
    margin-right: 40px;
    margin-bottom: 40px;    
    .detail{
        font-size: 17px;
        font-weight: bold;
        margin-bottom: 20px;
    }
    .detail-content{
        font-size: 13px;
        margin-bottom: 23px;
    }
    .title{
        font-size: 17px;
        font-weight: bold;
    }

}
.buttom-area{
    position: fixed;
    bottom: 0;
    left: 0;
    display: flex;
    width: 100%;
    background-color: white;
    align-items: center;
    padding-left: 20px;
    .shop-area{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-right: 29px;
        .image{
            width: 18px;
            height: 18px;
        }
        .name{
            font-size: 14px;
        }
    }
    .add{
        width: 100px;
        height: 48px;
        font-size: 17px;
        text-align: center;
        line-height: 48px;
        margin-left: -10px;
        border-radius: 10px;
        background-color: #cccccc;
    }
    .buy{
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100px;
        height: 100px;
        border-radius: 50px;
        background-color: white;
        line-height: 100px;
        position: absolute;
        right: 47px;
        .inner{
            color: white;
            height: 70px;
            width: 70px;
            font-size: 30px;
            background-color: #ed7955;
            font-size: 30px;
            border-radius: 35px;
            line-height: 70px;
            text-align: center;
        }
    }
}

具体实现的界面图如下:
在这里插入图片描述

在这里插入图片描述

总结

以上实现的功能,主要是对Flex理论部分的加深与实践,更加熟练的掌握Flex布局。
Flex理论部分可以参考该博客链接: https://blog.csdn.net/weixin_43675314/article/details/134402257

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值