Home>Article>Web Front-end> What three new border effects are added to css3?
There are three new border effects in css3: 1. Border image "border-image", which can add a background image to the border; 2. Border rounded corners "border-radius", which can add one or more A rounded corner effect; 3. Border shadow "box-shadow", which can add one or more shadows to the element box.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
css3 adds three new border effects
1. Border image "border-image"
border-image property can add a background image to the border. The latest versions of all major browsers now support the border-image attribute.
Syntax:
Description:
border-image attribute needs to be defined 3 aspects of content.
(1) Picture path.
(2) Cutting width: the cutting width of the four sides, in order: upper edge, right edge, lower edge, and left edge (clockwise).
(3) Tiling method: There are three values, namely repeat, round and stretch.
In all the examples in this section, we use the 90px×90px picture shown in the picture as the background picture of the border.
Code example:
The browser preview is as shown below.
Analysis:
From the preview effect, we can know that the numbers 1, 3, 7, and 9 located at the 4 corners are still Obediently located at the 4 corners. Then the 4 borders 2, 4, 6, and 8 will be continuously tiled.
Regarding the border-image attribute, we summarize it as follows:
(1) When making a border background image, 4 sides should be made, and the middle part needs to be hollowed out.
(2) The width of each side of the border background image should be the same as the corresponding border width (i.e. border-width).
2. Border rounded corners “border-radius”
The border-radius attribute can add a rounded corner effect to the border
Syntax:
If there are three values, then the first value is to set top-left, and the second value is top-right and bottom-left and they will be equal, and the third value is to set bottom-right.
If there are four values, then the first value is to set top-left, and the second value is to set top-right, the third value is to set bottom-right, and the fourth value is to set bottom- left
In addition to the above abbreviations, you can also write the four corners separately like border, as follows:
border-radius only supports the border-radius standard syntax format in the following versions of browsers: Firefox4.0, Safari5.0, Google Chrome 10.0, Opera 10.5, and IE9. For older browsers, border-radius needs to be based on Different browser kernels add different prefixes. For example, the Mozilla kernel needs to add "-moz", and the Webkit kernel needs to add "-webkit", etc. However, IE and Opera do not have private formats, so in order to maximize browser compatibility , we need to set it as follows:
Please write the standard form after the browser private form.
##3. Border shadow “box-shadow”In CSS, you can use the box-shadow attribute to achieve the border shadow effect. The box-shadow attribute can set one or more drop-down shadow boxes.
Attribute | Description | CSS |
---|---|---|
border-image | Sets the shorthand properties for all border images. | 3 |
border-radius | A shorthand property for setting all four border-*-radius properties | 3 |
Append the shadow of one or more drop-down boxes | 3 |
值 | 说明 |
---|---|
h-shadow | 必需的。水平阴影的位置。允许负值 |
v-shadow | 必需的。垂直阴影的位置。允许负值 |
blur | 可选。模糊距离 |
spread | 可选。阴影的大小 |
color | 可选。阴影的颜色。 |
inset | 可选。从外层的阴影(开始时)改变阴影内侧阴影 |
注意:boxShadow 属性把一个或多个下拉阴影添加到框上。该属性是一个用逗号分隔阴影的列表,每个阴影由 2-4 个长度值、一个可选的颜色值和一个可选的 inset 关键字来规定。省略长度的值是 0。
box-shadow属性的使用
1、水平垂直偏移为0也可以有阴影
如果offset-x或offset-y值为0,则阴影在元素背后,此时给blur-radius值或spread值可以产生阴影效果。
例子:
第一个div通过设置blur-radius产生阴影效果。
第二个div通过设置spread正值产生阴影效果。
第三个div通过设置spread负值产生阴影效果。
但是有一点要注意:扩展阴影必须和阴影模糊半径配合使用。
我个人觉得应该是没有配合使用这一说,但不可能只设置扩展阴影,因为扩展阴影和阴影模糊的取值都可以为正。如果只有扩展阴影的话,会被浏览器当做模糊阴影来解析,所以也可以简单理解为“扩展阴影必须和阴影模糊半径配合使用”,如果只用扩展阴影,可以写成:box-shadow:0 0 0 1px;。
2、设置水平垂直偏移得到阴影效果
outset情况:水平垂直偏移为0,但是不设置blur和spread,看不到阴影,因为此时box-shadow的周长和border-box一样,所以可以通过设置偏移让阴影显示出来。
inset情况:水平垂直偏移为0,不设置blur和spread,同样看不到阴影,因为此时box-shadow的周长和padding-box一样,同样可通过设置偏移让阴影显示出来。
例子:
3、投影方式
投影方式默认是outset,即外部投影,可设置inset让向内投影。
例子:第一个div默认outset,第二个设置inset,第三个同时设置两个阴影可以更好的看到outset和inset的关系,第四个div可以看出inset阴影在背景之上,内容之下。
inset阴影在背景之上,内容之下
4、如果元素同时指定border-radius属性,则阴影呈现相同的圆角。
The above is the detailed content of What three new border effects are added to css3?. For more information, please follow other related articles on the PHP Chinese website!