如何利用CSS3 逐渐发光的方格边框

html-css07

如何利用CSS3 逐渐发光的方格边框,第1张

一个使用伪元素来实现边框逐渐发光的代码,主要用到scale和opacity这两个属性。

Html代码

<div>

<img src="http://tva2.sinaimg.cn/crop.0.0.180.180.180/6830a53bjw8f2qo4xzc2zj20500500t0.jpg"/>

<div>

<p>CSS3 逐渐发光的方格边框</p>

<p>CSS3 逐渐发光的方格边框</p>

</div>

</div>

Css代码

.light{

background: #fff

width: 180px

height: 180px

margin: 100px auto

position: relative

text-align: center

color: #333

transform:translate3d(0,0,0)

}

.light-inner{

padding: 60px 30px 0

pointer-events: none

position: absolute

left: 0

top: 0

bottom: 0

right: 0

text-align: center

transition: background 0.35s

backface-visibility: hidden

}

.light-inner:before, .light-inner:after{

display: block

content: ""

position: absolute

left: 30px

top: 30px

right: 30px

bottom: 30px

border: 1px solid #fff

opacity: 0

transition: opacity 0.35s, transform 0.35s

}

.light-inner:before{

border-left: 0

border-right: 0

transform:scaleX(0,1)

}

.light-inner:after{

border-top: 0

border-bottom: 0

transform: scaleY(1,0)

}

.light:hover .light-inner{

background: #458fd2

}

.light:hover .light-inner:before, .light:hover .light-inner:after{

opacity: 1

transform: scale3d(1,1,1)

}

.light-inner p{

transition: opacity .35s, transform 0.35s

transform: translate3d(0,20px,0)

color: #fff

opacity: 0

line-height: 30px

}

.light:hover .light-inner p{

transform: translate3d(0,0,0)

opacity: 1

}

属性:一个最多可指定四个border-*-radius属性的 符合属性 ,这个属性允许你为元素添加圆角边框!

语法:border-radius:1-4 length|% / 1-4length|%

【length可为任意长度单位,比如px、em。

当使用%的时候,相对的不是字体的大小而是对应边的长度的百分比,例如border-top-left-radius:50%,那么左上角的圆角在左边的弧度是边框左边长度的50%、在上边的弧度是边框上边长度的50%;

因此如果设置border-radius:50%,那么边框将会变为一个椭圆】

兼容性:IE9+、Firefox4+,Chrome,Safari5+,Opera

-------------------------------------------------

CSS3指定每个圆角:

多值:

border-radius(四个值):左上角 右上角 右下角 左下角

border-radius(三个值):左上角 右上角和左下角 右下角

border-radius(两个值):左上角和右下角 右上角和左下角

border-radius(一个值):四个圆角值相同

border-top-left-radius:定义了左上角的弧度

border-top-right-radius:定义了右上角的弧度

border-bottom-left-radius:定义了右下角的弧度

border-bottom-right-radius:定义了左下角的弧度

box-shadow属性:可以设置一个或多个下拉阴影的框

语法:

box-shadow:h-shadow(水平位置偏移量)允许负值。必写;

v-shadow(处置位置偏移量)允许负值。必写;

blur(模糊距离)可选;

spread(阴影尺寸)可选;

color(阴影颜色)可选;

inset(内部阴影)可选;扩展属性,正值缩小,负值增大

box-shadow: 10px(横向,正值往右,负值往左) 10px(纵向,正值往下,负值网上) 10px(模糊,从边框到内容,完成渐变模糊) 10px(扩展,四周边界往外扩展10px) yellow(阴影颜色)

border-image

属性:使用border-image-*属性来构建美丽的可扩展按钮

语法:border-image:source slice width outset repeat;

兼容性:IE不兼容、Firefox、Chrome、Safari6+、Opera不兼容

-------------------------------------------------

border-image-source属性

border-image-source属性指定要使用的图像,而不是由border-style属性设置的边框样式

语法

border-image-source:none;

border-image-source:url("...");

-------------------------------------------------

border-image-slice属性

border-image-slice属性指定图像的边界向内偏移

语法

border-image-slice:number|%|fill;

-------------------------------------------------

border-image-width属性

brder-image-width属性指定图像边界的宽度

语法

border-image-width:number|%|auto;

-------------------------------------------------

border-image-outset属性

border-image-outset用于指定在边框外部绘制border-image-area的量

语法

border-image-outset:length|number;

-------------------------------------------------

border-image-repeat属性

该属性用于图像边界是否重复(repeated)、拉伸(stretched)或铺满(rounded)

语法:border-image-repeat:stretch|repeat|round|initial|inherit;

你好,我这里用CSS实现了三种带边框三角,效果分别如图:

实例代码如下,根据你个人的情况调整代码吧:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Arrow</title>

</head>

<body>

<style>

/* scale */

.arrow,

.arrow:after{

    position: relative

    display: inline-block

    width: 0

    height: 0

    border-top: 0

    border-left: 30px dotted transparent

    border-right: 30px dotted transparent

    border-bottom: 30px dashed #000

}

.arrow:after {

    position: absolute

    top: 0

    content: ''

    transform: translateX(-50%) scale(.8)

    border-bottom: 30px dashed #fff

}

/* width & height */

.arrow1,

.arrow1:after {

    position: relative

    display: inline-block

    width: 0

    height: 0

    border-top: 0

    border-left: 30px dotted transparent

    border-right: 30px dotted transparent

    border-bottom: 30px dashed #000

}

.arrow1:after {

    position: absolute

    left: -26px 

    top: 2px

    content: ''

    width: 0 

    height: 0 

    border-top: 0 

    border-left: 26px dotted transparent 

    border-right: 26px dotted transparent 

    border-bottom: 26px dashed #fff

}

/* border & after */

.arrow2 {

    position: relative

    display: inline-block

    width: 28px

    height: 28px

    border: 0

    border-top: 2px solid #000

    border-right: 2px solid #000

    -webkit-transform: translate(7px, 14px) rotate(-45deg)

    -ms-transform: translate(7px, 14px) rotate(-45deg)

    -o-transform: translate(7px, 14px) rotate(-45deg)

    transform: translate(7px, 14px) rotate(-45deg)

}

.arrow2:after {

    position: absolute

    left: 0

    top: -2px

    width: 42px

    height: 2px

    content: ''

    border-radius: 2px

    background-color: #000

    -webkit-transform-origin: left top

    -moz-transform-origin: left top

    -ms-transform-origin: left top

    -o-transform-origin: left top

    transform-origin: left top

    -webkit-transform: rotate(45deg)

    -ms-transform: rotate(45deg)

    -o-transform: rotate(45deg)

    transform: rotate(45deg)

}

</style>

<span class="arrow"></span>

<span class="arrow1"></span>

<span class="arrow2"></span>

</body>

</html>

希望能帮到你,如有疑问请追问,望采纳~