CSS3伪元素之Before/After

body{
                font-family: cursive;
                font-size: 14px;
            }
            .left{
                width:150px;
                height: 50px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 50px;
                text-align: center;
                border: 2px solid green;
                border-radius: 5px;
            }
            .left:before{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left: -30px;
                top: 10px;
                border: 15px solid;
                border-color: transparent green transparent transparent;
            }
            .left:after{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left: -27px;
                top: 10px;
                border: 15px solid;
                border-color: transparent #fff transparent transparent;
            }

            .right{
                width:150px;
                height: 50px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 50px;
                text-align: center;
                border: 2px solid green;
                border-radius: 5px;
            }
            .right:before{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                right: -30px;
                top: 10px;
                border: 15px solid;
                border-color: transparent transparent transparent green;
            }
            .right:after{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                right: -27px;
                top: 10px;
                border: 15px solid;
                border-color: transparent transparent transparent #fff;
            }

            .up{
                width:150px;
                height: 50px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 50px;
                text-align: center;
                border: 2px solid green;
                border-radius: 5px;
            }
            .up:before{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left:60px;
                top: -30px;
                border: 15px solid;
                border-color: transparent transparent green transparent ;
            }
            .up:after{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left:60px;
                top: -27px;
                border: 15px solid;
                border-color: transparent transparent #fff transparent;
            }

            .down{
                width:150px;
                height: 50px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 50px;
                text-align: center;
                border: 2px solid green;
                border-radius: 5px;
            }
            .down:before{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left:60px;
                top: 50px;
                border: 15px solid;
                border-color: green transparent transparent transparent ;
            }
            .down:after{
                content: ‘ ‘;
                position: absolute;
                width: 0;
                height: 0;
                left:60px;
                top: 48px;
                border: 15px solid;
                border-color: #fff transparent transparent transparent ;
            }

            .line{
                width:150px;
                height: 50px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 50px;
                text-align: center;
                border: 2px solid green;
                border-radius: 5px;
            }

            .line:before{
                border-bottom: 1px solid #3ca156;
                -webkit-transform: skewY(30deg);
                transform: skewY(30deg);
                content: ‘‘;
                width: 92px;
                position: absolute;
                left: 30px;
                top: 50%;
            }

            .line:after{
                border-bottom: 1px solid #3ca156;
                -webkit-transform: skewY(-30deg);
                transform: skewY(-30deg);
                content: ‘‘;
                width: 92px;
                position: absolute;
                left: 30px;
                top: 50%;
            }

            .fork{
                color: #fff;
                width:150px;
                height: 60px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 60px;
                text-align: center;
                background: green;
            }
            .fork:before{
                content: "";
                border: 30px solid;
                border-color: transparent transparent transparent #fff;
                position: absolute;
                top: 0px;
                left: 0px;
            }

            .fork:after{
                content: "";
                border: 30px solid;
                border-color: transparent transparent transparent green;
                position: absolute;
                top: -0px;
                right: -60px;
            }

            .fork-left{
                color: #fff;
                width:150px;
                height: 60px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 60px;
                text-align: center;
                background: green;
                border-radius: 5px;
            }
            .fork-left:before{
                content: "";
                border: 30px solid;
                border-color: transparent transparent transparent #fff;
                position: absolute;
                top: 0px;
                left: 0px;
            }

            .fork-right{
                color: #fff;
                width:150px;
                height: 60px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 60px;
                text-align: center;
                background: green;
                border-radius: 5px;
            }

            .fork-right:after{
                content: "";
                border: 30px solid;
                border-color: transparent #fff transparent transparent;
                position: absolute;
                top: 0px;
                right: 0;
            }

            .fork-up{
                color: #fff;
                width:60px;
                height: 150px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 150px;
                text-align: center;
                background: green;
                border-radius: 5px;
            }
            .fork-up:after{
                content: "";
                border: 30px solid;
                border-color: transparent  transparent #fff transparent;
                position: absolute;
                top: 90px;
                right: 0;
            }

            .fork-down{
                color: #fff;
                width:60px;
                height: 150px;
                background: #fff;
                position: relative;
                margin: 50px 0 0 50px;
                line-height: 150px;
                text-align: center;
                background: green;
                border-radius: 5px;
            }
            .fork-down:before{
                content: "";
                border: 30px solid;
                border-color: #fff transparent  transparent  transparent;
                position: absolute;
                top: 0;
                right: 0;
            }

时间: 2024-09-30 14:03:06

CSS3伪元素之Before/After的相关文章

使用 CSS3 伪元素实现立体的照片堆叠效

CSS3 里引入的伪元素让 Web 开发人员能够在不需要额外添加 HTML 标签的情况下制作出复杂的视觉效果.例如,:before 和 :after 这个两个 CSS3 伪元素就可以帮助你实现很多有趣的效果.本教程将告诉你如何使用 CSS3 为元素创建一组漂亮的图片堆叠效果. 效果演示     插件下载 您可能感兴趣的相关文章 Web 开发中很实用的10个效果[源码下载] 精心挑选的优秀jQuery Ajax分页插件和教程 12个让人惊叹的的创意的 404 错误页面设计 让网站动起来!12款优秀

CSS3伪元素 ::first-letter ::first-line ::selection

首先,关于伪元素的语法: 有的时候单冒号也能用,但最好写双冒号. 伪类:匹配的是元素(不同状态或结构的). 伪元素:匹配的是元素中的一部分内容(首字符,首行文本). ::first-letter 匹配 某元素的 首字符. 例: <!DOCTYPE html> <html> <head> <title>test010_伪元素选择器_::first-letter</title> <style type="text/css"&

css3 伪元素

今天切图的时候给了一个列表,属于常见的列表,图片如下 这样的列表属于比较常见的列表了,在pc端上实现如下: html: <ul> <li> <div class="pure-g"> <div class="pure-u-1-5 user-list-left"> <span><img src="../img" ></span> </div> <di

CSS3伪元素、伪类选择器

伪元素选择器: ::first-letter:为某个元素中的文字的首字母或第一个字使用样式. ::first-line:为某个元素的第一行文字使用样式. ::before:在某个元素之前插入一些内容. ::after:在某个元素之后插入一些内容 ::selection:匹配元素中被用户选中或处于高亮状态的部分. 伪类选择器: :link:未访问的链接. :visited:已访问的链接. :hover:鼠标移动到链接上. :active:选定的链接.   原文地址:https://www.cnbl

css3伪元素

伪元素:::before  ::after *必须添加content属性,否则后期不可见 content: ""; *默认是行级元素,如果想设置宽高,就必须转换为块级元素 position: absolute; *行内元素,需要转换成块:display:block   float:**  position: E::first-letter文本的第一个字母或字(不是词组) E::first-line 文本第一行 E::selection 可改变选中文本的样式 原文地址:https://w

css3的伪(伪类和伪元素)大合集

本文讲css3的伪,不是讲它有多虚伪,而是说它的伪元素样式.不得不说以前虽知html伪元素,但很少用,后得知借助css3伪元素可以发挥极大的便利.故总结css3的伪如下: CSS中存在一些比较特殊的属性,称之为伪类,它们之中最常用的就是定义链接的伪:link,:visited,:hover,:active等.除了它们,还有一些不被常使用的伪类,有:focus,:first-child,:lang等. 如下将一一介绍各伪类的用法. CSS 伪类 (Pseudo-classes)实例: 超链接 本例

CSS3伪类和伪元素

作为一个CSS3初学不久者来说,很容易混淆单冒号(:)和双冒号(::)的用法,以为两者可以互换着来使用.我自己之前也混淆过他们,因为两者看起来太相像了,就像孪生兄弟.但实际上,他们的区别还是挺大的,最多算得上近房亲戚. 下面我们来开始讲讲单冒号(:)伪类和双冒号(::)伪元素有什么相同和不同点(另外在CSS2中单冒号":" 也叫做伪对象,具体可看看http://www.mb5u.com/tool/css2/) 单冒号(:)早在CSS中已经存在了,相信用惯CSS的码农肯定对:hover伪

【CSS进阶】伪元素的妙用--单标签之美

最近在研读 <CSS SECRET>(CSS揭秘)这本大作,对 CSS 有了更深层次的理解,折腾了下面这个项目: CSS3奇思妙想 -- Demo (请用 Chrome 浏览器打开,非常值得一看).采用单标签完成各种图案,许多图案与本文有关. 也希望觉得不错的同学顺手在我的 Github 点个 star : CSS3奇思妙想 . 正文从这里开始,本文主要讲述一下 伪元素 before 和 after 各种妙用.    :before和::before的区别 在介绍具体用法之前,简单介绍下伪类和

CSS3与页面布局学习总结(六)——CSS3新特性(阴影、动画、渐变、变形、伪元素等)

目录 一.阴影 1.1.文字阴影 1.2.盒子阴影 二.背景 2.1.背景图像尺寸 2.2.背景图像显示的原点 三.伪元素 3.1.before 3.2.after 3.3.清除浮动 四.圆角与边框 4.1.border-radius 圆角 4.2.边框图片border-image 五.变形 transform 5.1.rotate()2D旋转 5.2.设置原点 transform-origin 5.3.平移 translate() 5.4.缩放 scale 5.5.斜切扭曲skew 六.渐变