CSS伪类 :before :after的小实例(仿京东)

本文详细介绍了使用HTML和CSS进行网页布局的方法,包括如何创建响应式设计,利用相对定位和绝对定位实现元素精确布局,以及如何通过背景颜色和边框增强视觉效果。文章还展示了如何使用伪元素和伪类来优化页面元素的样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link ref="sheetstyle" type="text/css" href="assets/css/iconfont.css">
</head>
<style>
    *{
        margin: 0;
        padding: 0;
    }
    .box{
        width: 390px;
        height: 450px;
        margin: 100px auto;
    }
    .act_inner{
        position: relative;
        width: 100%;
        height: 100%;
    }
    .act_inner:before {
        content: '';
        position: absolute;
        display: block;
        width: 340px;
        height: 420px;
        border: solid 5px #333;
        top: 20px;
        right: 0;
    }
    .act_lk{
        position: relative;
        z-index: 1;
        float: right;
        width: 340px;
        height: 420px;
        margin: 0 30px;
    }
    .act_img{
        position: relative;
        width: 100%;
        height: 100%;
    }
    .act_inner:after {
        content: '';
        z-index: 0;
        display: block;
        position: absolute;
        width: 340px;
        height: 420px;
        right: 30px;
        top: 0;
        background: #f0f3ef;
    }
    .container{
        position: relative;
        width: 50px;
        height: 50px;
        background: blue;
    }
    .box1{
        position: absolute;
        width: 100px;
        top: 50px;
        left: 0;
        background: red;
        border: 1px solid #333;
        border-radius: 3px;
    }
    .box1::before{
        content: '';
        position: absolute;
        display: block;
        width: 0;
        height: 0;
        left: 50%;
        top: -9px;
        border: 5px solid #333;
        border-color: transparent transparent red transparent;
    }
</style>
<body>
    <div class="box">
        <div class="act_inner">
            <a class="act_lk">
                <div class="act_img">
                    <img src="assets/imgs/pic.png" alt="">
                </div>
            </a>
        </div>
    </div>
</body>
</html>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值