• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

[置顶] css3 befor after 简单使用 制作时尚焦点图相框

:befor、:after是CSS的伪元素,什么是伪元素呢?伪元素用于向某些选择器设置特殊效果。

我们用CSS手册可以查询到其基本的用法:

  • E:before/E::before 设置在对象前(依据对象树的逻辑结构)发生的内容。用来和content属性一起使用
  • E:after/E::after 设置在对象后(依据对象树的逻辑结构)发生的内容。用来和content属性一起使用
  • Ie6-7 不支持 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <title>css_brfor_after</title>
    <style type="text/css">
        body {
            width: 300px;
            height: auto;
            display: block;
            margin: 0px auto;
            padding: 0px;
            text-align: left;
            text-decoration: none;
            background: #efeeea;
            background: linear-gradient(#f9f9f9, #cecbc4);
            background: -moz-linear-gradient(#f9f9f9, #cecbc4);
            background: -webkit-linear-gradient(#f9f9f9, #cecbc4);
            background: -o-linear-gradient(#f9f9f9, #cecbc4);
        }

        #box {
            width: 300px;
            height: 300px;
        }

            #box .relative {
                width: 288px;
                height: 288px;
                margin-left: 5px;
                margin-top: 5px;
                background-color: transparent;
                border-radius: 5px;
                -moz-border-radius: 5px;
                border: 2px solid red;
                position: absolute;
            }

                #box .relative:before {
                    width: 288px;
                    height: 248px;
                    background-color: transparent;
                    border-left: 2px solid #fff;
                    border-right: 2px solid #fff;
                    position: absolute;
                    content: '';
                    left: -2px;
                    top: 20px;
                }

                #box .relative:after {
                    width: 248px;
                    height: 288px;
                    background-color: transparent;
                    border-top: 2px solid #fff;
                    border-bottom: 2px solid #fff;
                    position: absolute;
                    content: '';
                    top: -2px;
                    left: 20px;
                }
    </style>
</head>

<body>
    <div id="box">
        <div class="relative"></div>
        <img src="ba.png" width="300" height="300" alt="心" title="心" />
    </div>
</body>
</html>


 

 

posted @ 2013-08-24 21:04  Class Xman  阅读(314)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3