- Basic - "user agent stylesheet" is default browser style
-
ViewPort¶
-
The viewport is the user's visible area of a web page.
-
The viewport varies with the device, and will be smaller on a mobile phone than on a computer screen
-
HTML5 introduced a method to let web designers take control over the viewport, through the tag.
-
<meta. name="viewport" content="width=device-width, initial-scale=1.0"> -
px vs rem vs em¶
-
PX: Pixels (px) are considered absolute units, although they are relative to the DPI and resolution of the viewing device.
-
EM: Relative to the parent element
-
REM: Relative to the root element (HTML tag)
-
%: Relative to the parent element
-
VW: Relative to the viewport’s width
-
VH: Relative to the viewport’s height
-
Keyframes¶
-
The @keyframes rule specifies the animation code.
-
The animation is created by gradually changing from one set of CSS styles to another.
-
During the animation, you can change the set of CSS styles many times.
-
Specify when the style change will happen in percent, or with the keywords "from" and "to", which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the animation is complete.
-
This gives more control over intermediate steps of the animation sequence than transition
-
ad and dis of css¶
-
ad
-
better looking website
-
easy to maintain
-
better device compatibility
-
-
dis
-
cross browser issues
-
security issues
-
sometimes maintaining it becomes difficult
-
-
Class vs Id selector¶
-
The basic difference between ID and Class is that the ID selector is applied only to one element in a page, whereas the class selector can be applied to several elements on a single page.
-
Only one ID selector can be attached to an element. hence ID's are stronger than class seletor as they are specific and hence, also, they are faster than class selector
-
Multiple class selectors can be attached to an element.
-
CSS position - Absolute- Relative- static-fixed¶
-
https://www.freecodecamp.org/news/css-positioning-position-absolute-and-relative/
-
Display: none vs Visibility: hidden¶
-
visibility:hidden hides the element, but it still takes up space in the layout.
-
display:none removes the element from the document. It does not take up any space.
-
CSS Pseudo-elements¶
-
A CSS pseudo-element is used to style specified parts of an element. - For example - it can be used to: Style the first letter, or line, of an element Insert content before, or after, the content of an element
-
- p::first-letter {
color: #ff0000;
font-size: xx-large;
}
-
-
Pseudo-classes¶
-
A pseudo-class is used to define a special state of an element.
-
For example
-
to Style an element when a user mouses over it, Style visited and unvisited links differently, Style an element when it gets focus
a:hover { color: #FF00FF; } -
Z-index¶
-
The z-index property specifies the stack order of an element.
-
An element with greater stack order is always in front/top of an element with a lower stack order.
-
Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).
-
Note: If two positioned elements overlap without a z-index specified, the element positioned last in the HTML code will be shown on top.
-
Box model¶
-
The CSS box model is essentially a box that wraps around every HTML element.
-
The set of rules that governs the size, shape, spacing, borders, and margins of page elements. - It consists of: margins, borders, padding, and the actual content
-
ways to add css and its precedence¶
-
inline style - inline css ( html style attribute ) overrides css rules in style tag and css file
-
Internal style
-
External CSS
-
rules that appear later in the code override earlier rules if both have the same specificity.
-
a more specific selector takes precedence over a less specific one
-
A css rule with !important always takes precedence.
-
https://stackoverflow.com/questions/25105736/what-is-the-order-of-precedence-for-css
-
Flex box¶
1. Parent flex container with display:flex 1. flex items are children of flex container 1. | Flex Container Props | Flex Item Props |
| :------------------- | :-------------: |
| flex-direction | order |
| flex--wrap | flex-grow |
| flex-flow | flex-shrink |
| flex-content | flex-basic |
| flex-items | align-self |
| flex-content | --|
-
align-self to align these items within their container.
-
justify-content- Instead of aligning each individual item, say we wanted to align all items together within the container. For that, we’ll use justify-content
-
space between - equal space between items
-
space around - equal space between border and items
-
svg vs canvas - https://www.geeksforgeeks.org/difference-between-svg-and-html-5-canvas¶
https://css-tricks.com/when-to-use-svg-vs-when-to-use-canvas/
-
. CSS Position¶
-
static
-
is default position of all html elements
-
Static works just like html elements
-
top bottom, left and right doesn't work on static
-
-
Relative
-
works same as static but with addition of top, bottom, left and right positioning of element
-
basically relative helps you to move element relative to static i.e. where it is originally
-
it overflows parent and other elements top, bottom, left and right of it
-
but it does not affect document flow of other elements
-
it should not be used
-
-
Absolute
-
no longer part of document flow
-
it does not take full width but only width required for its content
-
absolute completely removes element from document flow and rest of the things are rendered as if absolute element is not present in document
-
top left right bottom - absolutely positions itself in some parent element it can reference
-
parent element position shd be relative to use absolute in child element
-
it looks for first element that is not static and sets its own position accr to that non static element
-
if you want element inside div to be absolute then set div position as relative
-
i.e. absolute is nothing but fixed position wrt to parent element
-
-
Fixed
-
it is position according to entire html page and has nothing to do with parent element
-
no longer part of document flow
-
they stay in same position when you scroll page i.e. not affected by scrolling
-
-
Sticky
-
combination of relative and fixed position
-
fixed within boundary of parent div / section
-
it moves until it reaches 0px of its parent
-
-
floats and clears https://www.youtube.com/watch?v=3YW65K6LcIA
-
float make all elements which are coded after it wrap around it.
-
clear used to clear things from floating things
-
-
In how many ways can we position an HTML element? Or what are the permissible values of the position attribute?
-
static: Default value. Here the element is positioned according to the normal flow of the document.
-
absolute: Here the element is positioned relative to its parent element. The final position is determined by the values of left, right, top, bottom.
-
fixed: This is similar to absolute except here the elements are positioned relative to the element.
-
relative: Here the element is positioned according to the normal flow of the document and positioned relative to its original/ normal position.
-
inherit: Here the element inherits or takes the property of its parent
-
-
How to specify the link in HTML and explain the target attribute?
-
_self: This is a default value. It opens the document in the same window or tab as it was clicked.
-
_blank: It opens the document in a new window or tab.
-
_parent: It opens the document in a parent frame.
-
_top: It opens the document in a full-body window
-