CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



box-reflect

CSS or Cascading Style Sheets is a style sheet language used for describing the presentation of a document written in HTML or XML. It is used to style web pages and user interfaces written in HTML and XHTML. CSS has a wide range of properties that can be used to style web pages. One such property is box-reflect.

Brief Explanation of Box-Reflect

Box-reflect is a CSS property that allows you to create a reflection of an element. It is used to create a mirror-like reflection of an element on its own surface. This property is used to create a visual effect that makes an element look like it is reflecting on a surface. Box-reflect is a relatively new property in CSS and is not supported by all browsers.

The box-reflect property has four values that can be used to create a reflection. These values are:

  • box-reflect: This is the main property that is used to create a reflection. It is followed by the other three values.
  • direction: This value is used to specify the direction of the reflection. It can be set to either "above" or "below".
  • offset: This value is used to specify the distance between the element and its reflection. It can be set to any valid CSS length value.
  • mask-box-image: This value is used to specify the image that is used to mask the reflection. It can be set to any valid CSS image value.

Code Examples

Here are some examples of how to use the box-reflect property:

Example 1:

In this example, we will create a reflection of an image:

  
    <style>
      .image {
        width: 300px;
        height: 200px;
        background-image: url('image.jpg');
        box-reflect: below 0px linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0));
      }
    </style>

    <div class="image"></div>
  

In this example, we have created a div element with a class of "image". We have set the width and height of the div to 300px and 200px respectively. We have also set the background-image property to an image called "image.jpg".

The box-reflect property is set to "below 0px linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0))". This means that the reflection will be below the element, with an offset of 0px. The reflection will be a linear gradient that fades from white to transparent.

Example 2:

In this example, we will create a reflection of a text:

  
    <style>
      .text {
        font-size: 36px;
        font-weight: bold;
        color: #fff;
        text-shadow: 0px 0px 10px #000;
        box-reflect: below 0px linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0));
      }
    </style>

    <div class="text">Hello World!</div>
  

In this example, we have created a div element with a class of "text". We have set the font-size, font-weight, and color properties to style the text. We have also set the text-shadow property to create a shadow effect on the text.

The box-reflect property is set to "below 0px linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0))". This means that the reflection will be below the element, with an offset of 0px. The reflection will be a linear gradient that fades from white to transparent.

Conclusion

Box-reflect is a CSS property that allows you to create a reflection of an element. It is used to create a mirror-like reflection of an element on its own surface. This property is used to create a visual effect that makes an element look like it is reflecting on a surface. Box-reflect is a relatively new property in CSS and is not supported by all browsers.

References

Activity