πSet Font Size With Pixels
Setting the text size with pixels gives you full control over the text size:
πExample:
-----------------------------
h1 {
font-size: 60px;
}
-----------------------------
πSet Font Size With Em
To allow users to resize the text (in the browser menu), many developers use em instead of pixels.
1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px.
The size can be calculated from pixels to em using this formula: pixels/16=em
πExample:
-----------------------------
h1 {
font-size: 3.5em;
}
-----------------------------
πSet Font Size With REM
rem values are relative to the root html element, not to the parent element. That is, If font-size of the root element is 16px then 1 rem = 16px for all elements. If font-size is not explicitly defined in root element then 1rem will be equal to the default font-size provided by the browser (usually 16px).
When it comes to spacing and font-sizing, I prefer to use rem. Since rem uses root elementβs font-size instead of its parentβs font-size.
πExample:
-----------------------------
h1 {
font-size: 2.5rem;
}
-----------------------------
@html_css_tut
"w3schools .com,
medium. com "
Setting the text size with pixels gives you full control over the text size:
πExample:
-----------------------------
h1 {
font-size: 60px;
}
-----------------------------
πSet Font Size With Em
To allow users to resize the text (in the browser menu), many developers use em instead of pixels.
1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px.
The size can be calculated from pixels to em using this formula: pixels/16=em
πExample:
-----------------------------
h1 {
font-size: 3.5em;
}
-----------------------------
πSet Font Size With REM
rem values are relative to the root html element, not to the parent element. That is, If font-size of the root element is 16px then 1 rem = 16px for all elements. If font-size is not explicitly defined in root element then 1rem will be equal to the default font-size provided by the browser (usually 16px).
When it comes to spacing and font-sizing, I prefer to use rem. Since rem uses root elementβs font-size instead of its parentβs font-size.
πExample:
-----------------------------
h1 {
font-size: 2.5rem;
}
-----------------------------
@html_css_tut
"w3schools .com,
medium. com "
CSS Opacity
πThe opacity property specifies the opacity/transparency of an element.
πThe opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent.
πExample:
-------------------------------
img {
opacity: 0.5;
}
--------------------------------
@html_css_tut
"w3schools .com"
πThe opacity property specifies the opacity/transparency of an element.
πThe opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent.
πExample:
-------------------------------
img {
opacity: 0.5;
}
--------------------------------
@html_css_tut
"w3schools .com"
Transparency using RGBA
πIf you do not want to apply opacity to child elements, Use RGBA
πExample:
/* Green background with 30% opacity */
------------------------------
div {
background: rgba(76, 175, 80, 0.3) ;
}
--------------------------------
@html_css_tut
"w3schools .com"
πIf you do not want to apply opacity to child elements, Use RGBA
πExample:
/* Green background with 30% opacity */
------------------------------
div {
background: rgba(76, 175, 80, 0.3) ;
}
--------------------------------
@html_css_tut
"w3schools .com"