Some More Styles
OPACITY
The opacity property is used to set the transparency of an element. This can take a
value ranging from (0.0 - 1.0). The lower the value, the more transparent the element will
become.
Eg., applying opacity: 0.5; to the element below:
will show the element like this when opacity gets applied:
So, when adding transparency to the background of an element, all of its child elements
will also inherit the same transparency. This makes the text inside transparent as well.
You can use the 'rgba()' property to provide color along with opacity.
Look at the example below where we set opacity along with color using rgb() property:
#box {
width: 100px;
height: 100px;
background-color: rgb(255, 0, 0);opacity: 0.6;
}
With rgba(), you can give the opacity value, along with the rgb values:
#box {
width: 100px;
height: 100px;
background-color: rgba(255, 0, 0, 0.6);
}
1
Try this on your own!!
TRANSITION
The transition property is used to change the value of a property to some other value over
a given duration. You can provide multiple transitions to a single element by using a
comma.
The CSS syntax is -
transition: property duration timing-function delay;
The transition property is a shorthand property for:
● transition-property -specifies the name of the CSS property to apply a transition to
● transition-duration - specifies the seconds it would take to complete the transition
● transition-timing-function - specifies the speed of the transition over the duration
● transition-delay - specifies the wait before the start of the transition effect
Eg: You can apply all these properties like this:
transition: 0.5s ease-in-out;
Or specify styles separately:
transition-delay: 0.5s;
transition-duration: 1s;
transition-timing-function: ease-in-out;
will change the look of the element on hovering like this:
You’ll learn about transitions in a lot more detail, later in the course.
2
EXTRA:
You can see other 'transition-timing-function' value from the below link :
https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function
BOX SHADOW
The box-shadow property is used to produce a shadow-like effect for an element. You can
also, give multiple shadows to an element.
The CSS syntax for attaching shadow to element is -
box-shadow: none | h-offset v-offset blur spread color;
The meaning of the above options is -
● none - This is the default value. No shadow is displayed
● h-offset - this is a required value. It sets the horizontal point of the start of the
shadow. The value can be either a positive or negative number.
● v-offset - this is also a required value. It sets the vertical point of the start of the
shadow. The value can be either a positive or negative number.
● blur - this option is optional. This blurs the shadow. The higher the number, the
more blurred the shadow will be
● spread - this option is also optional. This sets the size of the shadow. The value can
be either a positive or negative number.
● color - this option is also optional. This sets the color of the shadow. The default
value will be the text color.
Eg., adding the show to a paragraph like this:
p {
border: 2px dotted #555555;
box-shadow: 1px 1px 10px 1px #3faddf inset, 2px 2px 10px 3px #AAAAAA;
}
will show the para like:
3
Now, you can see 2 shadows -
● One is outside the border.
● Other is inside the border.
We can provide inner shadow using the 'inset' option, which is optional. This option
changes the shadow from an outer shadow to an inner shadow
For example:
<html>
<head>
<style>
#box{
height: 100px;
width: 100px;
background-color: aliceblue;
box-shadow: 0px 0px 5px 12px inset black;
}
</style>
</head>
<body>
<div id="box">
</div>
</body>
</html>
Output: You can see that now the shadow is set using the inset option.