π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"
CSS The !important Rule
πThe !important rule in CSS is used to add more importance to a property/value than normal.
πIn fact, if you use the !important rule, it will override ALL previous styling rules for that specific property on that element!
πIt is good to know about the !important rule, you might see it in some CSS source code. However, do not use it unless you absolutely have to.
πOne way to use !important is if you have to override a style that cannot be overridden in any other way. This could be if you are working on a Content Management System (CMS) and cannot edit the CSS code. Then you can set some custom styles to override some of the CMS styles.
@html_css_tut
"w3schools .com"
πThe !important rule in CSS is used to add more importance to a property/value than normal.
πIn fact, if you use the !important rule, it will override ALL previous styling rules for that specific property on that element!
πIt is good to know about the !important rule, you might see it in some CSS source code. However, do not use it unless you absolutely have to.
πOne way to use !important is if you have to override a style that cannot be overridden in any other way. This could be if you are working on a Content Management System (CMS) and cannot edit the CSS code. Then you can set some custom styles to override some of the CMS styles.
@html_css_tut
"w3schools .com"
CSS Box Sizing
πThe CSS box-sizing property allows us to include the padding and border in an element's total width and height.
πWithout the CSS box-sizing Property
β By default, the width and height of an element is calculated like this:
πwidth + padding + border = actual width of an element
π height + padding + border = actual height of an element
πThe box-sizing property allows us to include the padding and border in an element's total width and height.
πIf you set
box-sizing: border-box;
on an element, padding and border are included in the width and height:
@html_css_tut
"w3schools .com"
πThe CSS box-sizing property allows us to include the padding and border in an element's total width and height.
πWithout the CSS box-sizing Property
β By default, the width and height of an element is calculated like this:
πwidth + padding + border = actual width of an element
π height + padding + border = actual height of an element
πThe box-sizing property allows us to include the padding and border in an element's total width and height.
πIf you set
box-sizing: border-box;
on an element, padding and border are included in the width and height:
@html_css_tut
"w3schools .com"
πbox-sizing: border-box
πThe code below ensures that all elements are sized in this more intuitive way. Many browsers already use box-sizing: border-box; for many form elements (but not all - which is why inputs and text areas look different at width: 100%;).
πApplying this to all elements is safe and wise:
________________
* {
box-sizing: border-box;
}
_________________
@html_css_tut
"w3schools .com"
πThe code below ensures that all elements are sized in this more intuitive way. Many browsers already use box-sizing: border-box; for many form elements (but not all - which is why inputs and text areas look different at width: 100%;).
πApplying this to all elements is safe and wise:
________________
* {
box-sizing: border-box;
}
_________________
@html_css_tut
"w3schools .com"