CSS properties - box-related

revision:


Content

box-decoration-break property box-reflect property box-shadow property box-sizing property


box-decoration-break property

top

- specifies how the background, padding, border, border-image, box-shadow, margin, and clip-path of an element is applied when the box for the element is fragmented.

CSS syntax : box-decoration-break: slice | clone | initial | inherit | unset;

Property values

slice : default. Box decorations are applied to the element as a whole and break at the edges of the element fragments

clone : box decorations apply to each fragment of the element as if the fragments were individual elements. Borders wrap the four edges of each fragment of the element, and backgrounds are redrawn in full for each fragment

initial : sets this property to its default value.

inherit : inherits this property from its parent element

example: box-decoration-break property

box-decoration-break: clone:

CSS
is
easy
to learn

box-decoration-break: slice (default):

CSS
is
easy
to learn
code:
                    <div>
                        <h4>box-decoration-break: clone:</h4>
                        <span class="ex1">CSS<br>is<br>easy<br>to learn</span>
                        <h4>box-decoration-break: slice (default):</h4>
                        <span class="ex2">CSS<br>is<br>easy<br>to learn</span>
                    </div>
                    <style>
                        span.ex1, span.ex2{border: 0.3vw solid red; padding:  0vw 1vw; border-radius: 1.6vw; 
                            font-size: 2vw; line-height: 2;}
                        span.ex1 {-webkit-box-decoration-break: clone; -o-box-decoration-break: clone; 
                            box-decoration-break: clone;}
                        span.ex2 {-webkit-box-decoration-break: slice; -o-box-decoration-break: slice; 
                            box-decoration-break: slice;}
                    </style>
                

box-reflect property

top

- is used to create a reflection of an element. The value of the box-reflect property can be: below, above, left, or right.

Note: the box-reflect property is non-standard and must be written with -webkit- prefix.

CSS syntax : box-reflect: none | below | above | left | right | position offset gradient | initial | inherit;

Property values

none : default value. No reflection is displayed.

below : creates a reflection below the element.

above : creates a reflection above the element.

left : creates a reflection to the left of the element.

right : creates a reflection to the right of the element.

position offset : two value syntax: - "position" sets reflection below, above, left, or right of the element; - "offset" sets the distance to the reflection. Distance is set in px, pt, cm, etc. Default value is 0.

position offset gradient : three value syntax: - "position" sets reflection below, above, left, or right of the element; - "offset" sets the distance to the reflection. Distance is set in px, pt, cm, etc. Default value is 0; - "gradient" sets a transition for the reflection, i.e. a fading effect.

initial : sets this property to its default value.

inherit : inherits this property from its parent element

JavaScript syntax: object.style.webkitBoxReflect="below"

example: box-reflect property

Show the reflection to the right of the image:


Create reflection below this p-tag:


Create reflection right to the image, with 2vw distance, and gradually fading.

search
code:
                    <div>
                        <p>Show the reflection to the right of the image:</p>
                        <img id="image-1" src="../pics/smiley.png" width="300" height="300"><br>
                        <p id="ap-1">Create reflection below this p-tag:</p><br>
                        <p>Create reflection right to the image, with 2vw distance, and gradually 
                        fading.</p>
                        <img id="image-2" src="../pics/search.png" alt="search" width="124" height="124">
            
                    </div>
                    <style>
                        #image-1 {-webkit-box-reflect:right;}
                        #ap-1{-webkit-box-reflect: below; color: red;}
                        #image-2{-webkit-box-reflect: right 2vw linear-gradient(to bottom, rgba(0,0,0,0.0),
                            rgba(0,0,0,0.4));}
                    </style>
                

box-shadow property

top

- attaches one or more shadows to an element.

It enables to cast a drop shadow from the frame of almost any element.

A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.
If a "border-radius" is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The "z-ordering" of multiple box shadows is the same as multiple text shadows (the first specified shadow is on top).

CSS syntax : box-shadow: none | h-offset v-offset blur spread color | inset | initial | inherit;

Property values

none : default value; no shadow is displayed.

h-offset : required; the horizontal offset of the shadow; a "positive value" puts the shadow on the right side of the box, a "negative value" puts the shadow on the left side of the box.

v-offset : required; the vertical offset of the shadow; a "positive value" puts the shadow below the box, a "negative value" puts the shadow above the box.

blur : optional; the blur radius; the higher the number, the more blurred the shadow will be.

spread : optional; the spread radius; a "positive value" increases the size of the shadow, a "negative value" decreases the size of the shadow.

color : optional; the color of the shadow; the default value is the text color. In Safari (on PC) the color parameter is required. If you do not specify the color, the shadow is not displayed at all.

inset : optional; changes the shadow from an outer shadow (outset) to an inner shadow.

initial : sets this property to its default value.

inherit : inherits this property from its parent element.

To attach more than one shadow to an element, add a comma-separated list of shadows.

JavaScript syntax: object.style.boxShadow="10px 20px 30px blue"

Syntax examples

/* Keyword values */
box-shadow: none;

/* offset-x | offset-y | color */
box-shadow: 60px -16px teal;

/* offset-x | offset-y | blur-radius | color */
box-shadow: 10px 5px 5px black;

/* offset-x | offset-y | blur-radius | spread-radius | color */
box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);

/* inset | offset-x | offset-y | color */
box-shadow: inset 5em 1em gold;

/* Any number of shadows, separated by commas */
box-shadow: 3px 3px red, -1em 0 0.4em olive;

/* Global keywords */
box-shadow: inherit;
box-shadow: initial;
box-shadow: revert;
box-shadow: unset;

Specify a single box-shadow using two, three, or four "length" values.

If only two values are given, they are interpreted as <offset-x> and <offset-y> values.
If a third value is given, it is interpreted as a <blur-radius>.
If a fourth value is given, it is interpreted as a <spread-radius>.

To specify multiple shadows, provide a comma-separated list of shadows.

example: box-shadow property

box-shadow: 0.5vw 1vw:

A div element with a shadow. The first value is the horizontal offset and the second value is the vertical offset. The shadow color will be inherited from the text color.

box-shadow: 0.5vw 1vw grey:

You can also define the color of the shadow. Here the shadow color is grey.

box-shadow: 0.5w 1vw red:

A red shadow.

code:

                    <style>
                        #example11 {margin-left: 1vw; border: 0.1vw solid red; padding: 1vw; box-shadow: 0.5vw 1vw;}
                        #example21 {margin-left: 1vw; border: 0.1vw solid blue; padding: 1vw; box-shadow: 0.5vw 1vw grey;}
                        #example31 {margin-left: 1vw; border: 0.2vw solid green; padding: 1vw; box-shadow: 0.5vw 1vw red;}
                    </style>
                    <h4>box-shadow: 0.5vw 1vw:</h4>
                    <div id="example11">
                        <p class="spec">A div element with a shadow. The first value is the horizontal offset and the
                        second value is the vertical offset. 
                        The shadow color will be inherited from the text color.</p>
                    </div>
                    <h4>box-shadow: 0.5vw 1vw grey:</h4>
                    <div id="example21">
                    <p class="spec">You can also define the color of the shadow. Here the shadow color is grey.</p>
                    </div>
                    <h4>box-shadow: 0.5w 1vw red:</h4>
                    <div id="example31">
                    <p class="spec">A red shadow.</p>
                    </div>
                
                
example: box-shadow property

internal box-shadow

You may shoot me with your words,
You may cut me with your eyes,
You may kill me with your hatefulness,
But still, like air, I'll rise.

— Maya Angelou

code:

                    <style>
                        blockquote {padding: 2vw; box-shadow: inset 0 -3vw 3vw green, 0 0  0 0.4vw  gray, 1vw 1vw 
                            3vw blue;}
                </style>
                <h4>internal box-shadow</h4>
                <blockquote><q>You may shoot me with your words,<br/>
                    You may cut me with your eyes,<br/>
                    You may kill me with your hatefulness,<br/>
                    But still, like air, I'll rise.</q>
                    <p class="spec">& mdash; Maya Angelou</p>
                </blockquote>
                

example: box-shadow property

value: h-offset, v-offset

code:

                    <style>
                        .container {display: flex; justify-content: center; align-items: center; min-height: 20vh;}
                        .square {width: 10vw; height: 10vw; background: #3366cc; box-shadow: 0vw 0vw 2vw 1vw #4bf090;}
                    </style>
                    <h4>value: h-offset, v-offset</h4>
                    <div class="container">
                        <div class="square"></div>
                    </div>
                


example: box-shadow property

code:

                    <style>
                        .container_b {display: flex; margin-left: 8vw; justify-content: center; align-items: center; border: 0.2vw solid blue;
                            width: 15vw; height:15vw; border-radius: 50% / 50%; box-shadow: 2vw -3vw 0vw 1vw green;}
                        .circle_b{width: 10vw; height: 10vw; border-radius: 50% / 50%; background: #3366cc;
                            box-shadow: 0vw 0vw 1vw 2vw #4bf090;}
                    </style>
                    <div class="container_b">
                        <div class="circle_b"></div>
                    </div>
                

example: box-shadow property

value: blur

box-shadow: 0.5vw 1vw 0.8vw red:

The optional third value adds a blur effect to the shadow.

box-shadow: 0.5vw 1vw 1.8vw blue:

More blurred.

box-shadow: 0.5 1vw 2.8vw red:

More blurred and green.

code:

                    <style>
                        #example1a {margin-left: 1vw; border: 0.2vw solid; padding: 1vw; box-shadow: 0.5vw 1vw 0.8vw red;}
                        #example2a {margin-left: 1vw; border: 0.2vw solid; padding: 1vw; box-shadow: 0.5vw 1vw 1.8vw blue;}
                        #example3a {margin-left: 1vw; border: 0.2vw solid; padding: 1vw; box-shadow: 0.5vw 1vw 2.2vw green;}
                </style>
                <h4>value: blur</h4>
                    <h5>box-shadow: 0.5vw 1vw 0.8vw red:</h5>
                    <div id="example1">
                    <p class="spec">The optional third value adds a blur effect to the shadow.</p>
                    </div>
                    <h5>box-shadow: 0.5vw 1vw 1.8vw blue:</h5>
                    <div id="example2">
                    <p class="spec">More blurred.</p>
                    </div>
                    <h5>box-shadow: 0.5 1vw 2.8vw red:</h5>
                    <div id="example3">
                    <p class="spec">More blurred and green.</p>
                    </div>
                
example: box-shadow property

value: spread

box-shadow: 0.5vw 1vw 0.8vw 1vw red:

The optional fourth value defines the spread of the shadow.

code:

                    <style>
                        #example4a {margin-left: 1vw; border: 0.1vw solid; padding: 1vw; box-shadow: 0.5vw 1vw 0.8vw 1vw red;}
                    </style>
                    <h4>value: spread</h4>
                <h5>box-shadow: 0.5vw 1vw 0.8vw 1vw red:</h5>
                <div id="example4a">
                    <p class="spec">The optional fourth value defines the spread of the shadow.</p>
                </div>
                
example: box-shadow property

value: inset

box-shadow: 0.5vw 1vw inset:

The inset keyword changes the shadow to one inside the frame.

box-shadow: -0.5vw -1vw 2vw red inset:

Inset, red and blur.

code:

                    <style>
                        #example8 {margin-left: 1vw; border: 0.1vw solid; padding: 1vw; box-shadow: 0.5vw 1vw inset;}
                        #example9 {margin-left: 1vw; border: 0.1vw solid; padding: 1vw; box-shadow: -0.5vw -1vw 2vw red inset;}
                    </style>
                    <h4>value: inset</h4>
                    <h5>box-shadow: 0.5vw 1vw inset:</h5>
                <div id="example8">
                    <p class="spec">The inset keyword changes the shadow to one inside the frame.</p>
                </div>
                    <h5>box-shadow: -0.5vw -1vw 2vw red inset:</h5>
                <div id="example9">
                    <p class="spec">Inset, red and blur.</p>
                </div>
                
example: box-shadow property

multiple shadows

box-shadow: 0.5vw 0.5vw blue, 1vw 1vw red, 1.5vw 1.5vw green:

Define multiple shadows.


box-shadow: 0.5vw 0.5vw 0.8vw blue, 1vw 1vw 0.8vw red, 1.5vw 1.5vw 0.8vw green:

Define multiple shadows with blur effect.

code:

                    <style>
                        #example6 {margin-left: 1vw; border: 0.2vw solid; padding: 1vw; box-shadow: 0.5vw 0.5vw blue, 1vw 1vw red, 1.5vw 1.5vw green;}
                        #example7 {margin-left: 1vw; border: 0.2vw solid; padding: 1vw; box-shadow: 0.5vw 0.5vw 0.8vw blue, 
                            1vw 1vw 0.8vw red, 1.5vw 1.5vw 0.8vw green;}
                    </style>
                    <h4>multiple shadows</h4>
                    <h5>box-shadow: 0.5vw 0.5vw blue, 1vw 1vw red, 1.5vw 1.5vw green:</h5>
                    <div id="example6">
                        <p class="spec">Define multiple shadows.</p>
                    </div><br>
                    <h5>box-shadow: 0.5vw 0.5vw 0.8vw blue, 1vw 1vw 0.8vw red, 1.5vw 1.5vw 0.8vw 
                    green:</h5>
                    <div id="example7">
                        <p class="spec">Define multiple shadows with blur effect.</p>
                    </div>
                

example: box-shadow property

Hello World

code:

                    <style>
                        p.new {box-shadow: 0 0 0 2vw #F4AAB9, 0 0 0 4vw #66CCFF; margin: 4vw; 
                            padding:1vw;}
                    </style>
                    <div style="margin-left:4vw" ><p class="spec new">Hello World</p></div>
                

example: box-shadow property

border-radius and box-shadow

code:

                    <style>
                        .container_a {display: flex; justify-content: center; align-items: center; min-height: 15vh;}
                        .square_a {width: 20vw; height: 20vw; background: #3366cc; border-radius: 4vw; 
                            box-shadow: 1.5vw 1.5vw 2vw 1vw #4bf090;}
                    </style>
                    <h4>border-radius and box-shadow</h4>
                    <div class="container_a">
                        <div class="square_a"></div>
                    </div>
                



box-sizing property

top

- defines how the width and height of an element are calculated: should they include padding and borders, or not.

CSS syntax : box-sizing: content-box | border-box | initial | inherit;

Property values

content-box : default. The width and height properties (and min/max properties) includes only the content. Border and padding are not included

border-box : the width and height properties (and min/max properties) includes content, padding and border

initial : sets this property to its default value.

inherit : inherits this property from its parent element

JavaScript syntax: object.style.boxSizing="border-box"

example: box-sizing property

box-sizing: content-box (default):

Width and height only apply to the content of the element:

This div has a width of 300px. But the full width is 300px + 20px (left and right border) + 60px (left and right padding) = 380px!

box-sizing: border-box:

Width and height apply to all parts of the element: content, padding and borders:

Here, the full width is 300px, no matter what!
code:
                    <div>
                        <h4>box-sizing: content-box (default):</h4>
                        <p>Width and height only apply to the content of the element:</p>
                        <div id="box-A">This div has a width of 300px. But the full width is 300px + 20px (left and right border) 
                        + 60px (left and right padding) = 380px!</div>
                        <h4>box-sizing: border-box:</h4>
                        <p>Width and height apply to all parts of the element: content, padding and borders:</p>
                        <div id="box-B">Here, the full width is 300px, no matter what!</div>
                    </div>
                    <style>
                        #box-A {box-sizing: content-box; width: 300px; height: 100px; padding: 30px; border: 10px solid blue;}
                        #box-B {box-sizing: border-box;  width: 300px; height: 100px; padding: 30px; border: 10px solid blue;}    
                    </style>