Transparent border
By default, the background color will extend to the lower border, if the border is set to the transparent color, the background color will be overwritten.
CSS3 property may be provided to background-clip
set the background elements (background image or color) is extended to the border below.
background-clip
There are four values:
border-box
: Background border extends to the outer edge (but lower in the frame)padding-box
: Background extends into the margin (padding
) the outer edge, does not draw the outer bordercontent-box
: Background extends to the content area (content box
) outer edgetext
: Background cut foreground color of the text. (Only supports Chrome, need to add-webkit-
the prefix)
[Image dump outer link failure (IMG-pu6KRalK-1562037048483) ( http://image.oldzhou.cn/FpKGstS3QYG5aEbxFSCWYfrP7VlE )]
So it will background-clip
set padding-box
you can achieve transparent border.
Reference :
Multiple Borders
box-shadow
box-shadow
Used to generate a shadow effect, if only two values are given, the browser resolves to x
the direction shift amount and y
direction of shift amount; if the third value is given, will be interpreted as the size of the blur radius; if given first four values, will be the size of unexpanded radius supervisor.
The other two properties are inset
properties (declarative) and color values.
Some have been confused and extend the radius of the blur radius, from the following example to understand box-shadow
the generation process
First, define the box-shadow
attributes:
.box {
width: 300px;
height: 200px;
background-color: yellowgreen;
box-shadow: 30px 50px 20px #000;
}
(1) First, box
generating a same element of box
exactly the same size, the shape of the shadow, the color of the color set#000
[Image dump outer link failure (IMG-pqy7g5HK-1562037048484) ( http://image.oldzhou.cn/FsV6IWhYI7_Q1bgL6TF7OHma9E0Z )]
At this time, in the shadow of the upper element
(2) offset-x
and offset-y
the shadow moves from the upper right 30px
, upward movement of50px
[Image dump outer link failure (IMG-EYFnAjdJ-1562037048485) ( http://image.oldzhou.cn/FrF8Xmp5uh3UukOsaYQiaLaG9vwo )]
(3) Then according to the set 20px
blur radius, then the four directions, each direction of the edge of the shadow as the center to both sides of the extended 10px
area, as Gaussian blur radius
To the right side, for example:
[Image dump outer link failure (IMG-bRtoz8pd-1562037048485) ( http://image.oldzhou.cn/FkPYqMg8GKKPhsJ9sajTyZhABVEw )]
(4) a final step, the shadow region overlapping the element trimmed, as shown below:
[Image dump outer link failure (IMG-esz3KX4c-1562037048486) ( http://image.oldzhou.cn/FtG6m6JEX1SUeZn6p7SgdTuJpcvq )]
(5) to give the final results:
[Image dump outer link failure (IMG-hKXzzU4B-1562037048486) ( http://image.oldzhou.cn/Fo2YmjK0hJYLXI_R1LH5Ll4iZXE7 )]
Seen from the above example, the blur radius is centered on the edge of the shadow is, half extended to both sides, as a radius, Gaussian blur. It will only be positive.
Extension radius, the shadow area is increased, the value of it 0
, the shaded area is equal to the area of the element, it is not equal 0
, the value is to increase or decrease the size of the four directions
.inner {
box-shadow: 30px 50px 0 30px #000;
}
[Image dump outer link failure (IMG-Ppfktf4U-1,562,037,048,487) ( http://image.oldzhou.cn/Fn4GZlUhMnmHGxpUWPlUJd0Xx6Q9 )]
FIG broken line is to increase the size of the radius of expansion 30px
, when set extended radius, also fuzzy blur radius increases from the shadow of the edge on both sides.
Can be x-offset
, y-offset
blur radius are set 0
, set the extended radius of different sizes to achieve multiple effects of the border:
.inner {
box-shadow: 0 0 0 5px darkgoldenrod, 0 0 0 10px darkolivegreen, 0 0 0 15px red;
}
[Image dump outer link failure (IMG-jotaSTcN-1,562,037,048,487) ( http://image.oldzhou.cn/FswhNgLNUD7PxJLo2woa0kCXqvXa )]
The advantage is very easy to achieve the above frame 2, and may be rounded corners, the border can not be achieved disadvantage of non-solid lines.
outline
+ outline-offset
outline
Or may be provided a plurality of individual profile or attributes, the profile does not occupy the space ( box-shadow
and border
occupy space)
outline-offset
It used to set a outline
gap or a border edge element
The combination of both, you can achieve a variety of borders, and can be implemented box-shadow
, non-solid line can not be achieved multiple border
.inner2 {
border: aqua dotted 5px;
outline: red dotted 5px;
outline-offset: -15px;
}
[Image dump outer link failure (IMG-mvqWlB43-1562037048488) ( http://image.oldzhou.cn/FrXgZTN2joXiIvqj7YStdIl2XUA2 )]
Advantage of this is a non-solid lines border, to achieve the above disadvantage is inconvenient to frame 2, and can not be rounded corners.
reference
- Multiple Borders @ You-need-to-know-css
- box-shadow@MDN
- Detailed Nuggets box-shadow @
- outline@MDN
- outline-offset@MDN
In the border fillet
To achieve the effect of:
[Image dump in the chain ... (img-bMQGre0c-1562037055161)]
No peripheral border fillet, internal rounded, so alone border-radius
is not enough. A portion of the content, we can see, box-shadow
it is to follow the border rounded corners, and outline
is not rounded, so we can use the combination of the three to achieve within the borders rounded corners.
Using a border-radius
set fillet, assumed r
, but not set border
, setting outline
is w
such that the outer frame is not rounded,
.inner {
background: darkgray;
border-radius: 5px;
outline: 5px solid darkgreen;
}
This time the effect is:
[Image dump in the chain ... (img-lv4PgCjz-1562037055161)]
BACKGROUND due border-radius
provided appear rounded, then we use box-shadow
these complement portion, provided only its expanded radius, color and outline
same color
.inner {
background: darkgray;
border-radius: 5px;
outline: 5px solid darkgreen;
box-shadow: 0 0 0 5px darkgreen;
}
Extended range of radius below:
[Image dump in the chain ... (img-xsjIiF4B-1562037055162)]
Review the value of the extended radius of:
[Image dump in the chain ... (img-QgbGvjxM-1562037055163)]
So this value can not exceed the maximum outline
width w
and the minimum width can not be less than the Pythagorean theorem $\sqrt{2}r - r$
, i.e. $\sqrt{2-1}r$
, on our setup, radius range is extended[5, 2.07]
Reference :