๐ง 21. What is CSS?
CSS stands for Cascading Style Sheets.
It is used to style and design HTML elements.
CSS helps to:
โข Add colors
โข Set fonts
โข Create layouts
โข Add animations
โข Make websites responsive
Example:
h1 {
color: blue;
font-size: 40px;
}๐ง 22. Difference Between Inline, Internal, and External CSS
Type : Description
Inline CSS : Written inside HTML element
Internal CSS : Written inside
<style> tag External CSS : Written in separate .css file
Inline CSS:
<h1 style="color:red;">Hello</h1>
Internal CSS:
<style>
h1 {
color: blue;
}
</style>
External CSS:
<link rel="stylesheet" href="style.css">
๐ง 23. What is Specificity in CSS?
Specificity determines which CSS rule is applied when multiple rules target the same element.
Priority Order:
1. Inline CSS
2. ID Selector
3. Class Selector
4. Element Selector
Example:
#title {
color: red;
}
.heading {
color: blue;
}ID selector has higher priority.
๐ง 24. Explain CSS Box Model
Every HTML element is treated as a box.
The box model contains:
โข Content
โข Padding
โข Border
โข Margin
Structure:
Margin
โ Border
โ Padding
โ Content
Example:
div {
padding: 20px;
border: 2px solid black;
margin: 10px;
}๐ง 25. Difference Between Margin and Padding
Margin : Space outside border
Creates gap between elements
Padding : Space inside border
Creates inner spacing
Example:
div {
margin: 20px;
padding: 20px;
}๐ง 26. What is Flexbox?
Flexbox is a one-dimensional layout system used for alignment and spacing.
Benefits:
โ Easy alignment
โ Responsive layouts
โ Flexible spacing
Example:
.container {
display: flex;
justify-content: center;
align-items: center;
}๐ง 27. What is CSS Grid?
CSS Grid is a two-dimensional layout system.
It handles:
โข Rows
โข Columns
Example:
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}๐ง 28. Difference Between Relative, Absolute, Fixed, and Sticky Positioning
Position : Description
relative : Positioned relative to itself
absolute : Positioned relative to parent
fixed : Fixed on screen
sticky : Sticks during scrolling
Example:
div {
position: absolute;
top: 20px;
}๐ง 29. What is z-index?
z-index controls stack order of elements.
Higher z-index appears on top.
Example:
.box {
z-index: 10;
}๐ง 30. Difference Between em, rem, %, px, vh, and vw
Unit : Meaning
px : Fixed pixels
% : Relative percentage
em : Relative to parent
rem : Relative to root
vh : Viewport height
vw : Viewport width
Example:
h1 {
font-size: 2rem;
}๐ง 31. What are Pseudo-Classes?
Pseudo-classes define special states of elements.
Examples:
a:hover {
color: red;
}Common Pseudo-Classes:
โข :hover
โข :focus
โข :first-child
โข :last-child
๐ง 32. What are Pseudo-Elements?
Pseudo-elements style specific parts of elements.
Example:
p::first-letter {
font-size: 40px;
}Common Pseudo-Elements:
โข ::before
โข ::after
โข ::first-letter
๐ง 33. Difference Between visibility:hidden and display:none
visibility:hidden : Element hidden but space remains
display:none : Element removed completely
Example:
.box {
display: none;
}๐ง 34. What is Media Query?
Media queries make websites responsive.
Example:
@media (max-width: 768px) {
body {
background: lightblue;
}
}๐ง 35. Explain Responsive Design
Responsive design ensures websites work on:
โข Mobile
โข Tablet
โข Desktop
Techniques:
โ Media Queries
โ Flexible layouts
โ Responsive images
๐ง 36. What is Mobile-First Design?
Mobile-first design means designing for smaller screens first and then scaling upward.
Benefits:
โ Better performance
โ Better UX on mobile devices