What is powerful CSS properties that you probably don’t know?

What is powerful CSS properties that you probably don’t know

Here are some less well-known CSS properties:

1- clip-path:  allows you to clip an element to a specific shape.

The clip-path property in CSS is used to clip an element to a specific shape. The shape is defined using a <clipPath> element and an SVG path. The clipped element will be limited to the bounds of the clip path.

Here's an example of how to use clip-path in CSS:
<div class="element">
  <svg>
    <defs>
      <clipPath id="clip">
        <circle cx="50" cy="50" r="40"/>
      </clipPath>
    </defs>
  </svg>
</div>

<style>
  .element {
    width: 100px;
    height: 100px;
    clip-path: url(#clip);
    background-color: blue;
  }
</style>

In this example, the div with the class element will be clipped to a circle shape with a radius of 40 and its center located at (50, 50).

2- filter: allows you to apply various visual effects to an element, such as blur, grayscale, and brightness.

The filter property in CSS is used to apply various visual effects to an element. It allows you to adjust the brightness, contrast, hue, saturation, and blur of an element.

Here's an example of how to use filter in CSS:
<div class="element">
  <p>This text is affected by a filter.</p>
</div>

<style>
  .element {
    filter: brightness(150%) blur(2px);
  }
</style>

In this example, the filter property is applied to the div with the class element, which contains a paragraph of text. The filter will adjust the brightness by 150% and add a 2px blur to the element.

Note that different browsers may have different levels of support for the filter property and the effects it offers. You should check the compatibility of the effects you want to use with the browsers you want to support.

3- backdrop-blur: allows you to apply a background blur to an element.

The backdrop-blur property is not a standard CSS property and is not widely supported by browsers. It's used to apply a background blur to an element, meaning the background behind the element will appear blurred while the content of the element remains in focus.

This property is currently supported by WebKit-based browsers such as Safari, but it is not supported by other popular browsers such as Google Chrome and Mozilla Firefox.

As an alternative, you can use a blurred background image as the element's background and adjust the opacity of the element to control the amount of blur. This can be achieved using CSS and the background-image and opacity properties.

Here's an example:

<div class="element">

  <p>This text is displayed on a blurred background.</p>

</div>

<style>

  .element {

    background-image: url(blurred-background.jpg);

    opacity: 0.5;

  }

</style>

In this example, the blurred background image is set as the background for the .element class using the background-image property. The opacity of the element is then set to 0.5 using the opacity property to control the amount of blur applied to the background.

4- scrollbar-width: allows you to control the width of an element's scrollbars.

The scrollbar-width property in CSS is used to control the width of an element's scrollbars. It allows you to specify whether the scrollbars should be narrow, regular, or none at all.

Here's an example of how to use scrollbar-width in CSS:

<div class="element">

  <p>This is some long content that requires a scrollbar.</p>

</div>

<style>

  .element {

    overflow-y: scroll;

    scrollbar-width: thin;

  }

</style>

In this example, the overflow-y property is set to scroll to enable a vertical scrollbar on the div with the class element if its content is too tall to fit within the element's bounds. The scrollbar-width property is then set to thin to specify that the scrollbar should be narrow.

Note that the scrollbar-width property is not widely supported by browsers and is considered a non-standard property. If you want to control the appearance of scrollbars in your web pages, it's recommended to use JavaScript or a library like Perfect Scrollbar instead.

5- object-fit: allows you to control how an embedded content such as images fits within its container.

The object-fit property in CSS is used to control how the contents of a replaced element, such as an <img> or <video> element, should be resized to fit within its container.

Here's an example of how to use object-fit in CS

<div class="container">

  <img src="image.jpg" alt="An example image">

</div>

<style>

  .container {

    width: 300px;

    height: 200px;

    overflow: hidden;

  }

  .container img {

    object-fit: cover;

  }

</style>

In this example, the object-fit property is set to cover for the <img> element, which is the child of a container with the class container. The object-fit property is set to cover to ensure that the entire container is covered by the image, preserving its aspect ratio and cropping any excess image data that doesn't fit within the container.

The object-fit property has several possible values, including fill, contain, cover, none, and scale-down, each of which specifies a different way to resize the contents of the element to fit within its container.

6- line-clamp: allows you to limit the number of lines of text within an element.

The line-clamp property in CSS is used to limit the number of lines of text that should be displayed in an element. Once the specified number of lines has been reached, any additional text will be hidden and replaced with an ellipsis (...) to indicate that there is more text that is not being displayed.

Here's an example of how to use line-clamp in CSS:

<div class="element">

  <p>This is some long text that will be limited to two lines.</p>

</div>

<style>

  .element {

    display: -webkit-box;

    -webkit-box-orient: vertical;

    -webkit-line-clamp: 2;

    overflow: hidden;

  }

</style>

In this example, the line-clamp property is set to 2 for the div with the class element, which contains a paragraph of text. The display property is set to -webkit-box and the -webkit-box-orient property is set to vertical to specify that the element should be treated as a multi-line box with a maximum height. The overflow property is set to hidden to hide any text that exceeds the maximum number of lines.

Note that line-clamp is not a standard CSS property and is only supported by WebKit-based browsers such as Safari. If you need to limit the number of lines of text in other browsers, you can use JavaScript or a library like CSS Truncate to achieve the same effect.

7- background-clip: allows you to control the background painting area of an element.

The background-clip property in CSS is used to specify the area of an element that a background image or color should be applied to.

Here's an example of how to use background-clip in CSS:

<div class="element">

  <p>This is some text with a background image.</p>

</div>

<style>

  .element {

    background-image: url(image.jpg);

    background-clip: content-box;

    padding: 20px;

  }

</style>

In this example, the background-image property is set to url(image.jpg) for the div with the class element, which contains a paragraph of text. The background-clip property is set to content-box to specify that the background image should be clipped to the content box of the element, which includes only the element's padding and content, but not its border. The padding property is set to 20px to add some space around the text inside the element.

The background-clip property has several possible values, including border-box, padding-box, and content-box, each of which specifies a different area of the element that the background should be applied to. The default value is border-box, which specifies that the background should be applied to the entire element, including its border and padding.

8- mask: allows you to mask an element, revealing or hiding parts of it based on a mask image.

The mask property in CSS is used to apply a mask to an element, which determines which parts of the element are visible and which parts are transparent. A mask can be created using an image, a gradient, or a CSS <basic-shape>.

Here's an example of how to use mask in CSS:

<div class="element">

  <p>This is some text with a mask applied to it.</p>

</div>

<style>

  .element {

    mask: linear-gradient(to bottom, transparent, black);

  }

</style>

In this example, the mask property is set to a linear gradient for the div with the class element, which contains a paragraph of text. The linear gradient goes from transparent to black, which means that the top of the text will be fully transparent and the bottom of the text will be fully opaque. As a result, only the bottom half of the text will be visible.

The mask property can be used to create various visual effects, such as text fading out, image transparency, and more. It is supported by most modern browsers, but may not be supported by older browsers. If you need to support older browsers, you can use a polyfill or a fallback method such as using an image with transparency to achieve the same effect.

These properties can add an extra layer of style and visual interest to your website, making your designs more dynamic and engaging.

 If you enjoying this article or find helpful. Please like, comment and share this post.

Comments

Popular posts from this blog

What is $wpdb in WordPress?

What is FTP ? Which is best FTP Protocol How we can use It ?