In this example, we have set the opacity of the div
element to 0.5. This makes the blue color of the element semi-transparent. We have also set the opacity of the p
element to 0.8, which makes the text semi-transparent.
Explanation
The opacity
property in CSS affects the entire element, including its content and any child elements. If you want to set the opacity of only the element's background color or border, you can use the background-color
or border-color
property instead.
Use
The opacity
property is useful for creating transparent or semi-transparent elements, such as overlays, modals, or buttons. It can also be used to create visual effects or highlight certain elements on a page.
Important Points
- The
opacity
property is not inherited by child elements.
- If the opacity of a parent element is set, it affects the opacity of all child elements within it.
- The
opacity
property affects the visibility of an element, but not its position or size.
- Elements with an opacity of 0 are still present in the page layout, but are invisible to the user.
Summary
CSS opacity is a versatile property that allows you to create transparent and semi-transparent elements on your web pages. By adjusting the opacity level of images, text, borders, and other HTML elements, you can achieve a variety of visual effects and highlight certain elements on your page.