Media queries help your website adapt to different screen sizes π, so it looks good on phones, tablets, laptops, and big screens! π₯οΈπ±
A media query checks the screen size and applies different CSS rules based on it.
π Example:
Big screen? Show a large menu π₯οΈ
Phone? Show a mobile-friendly menu π±
β Basic SyntaxΒ
π‘ It works like an "if" statement for CSS!Β
Letβs change the background only for small screens (phones).
π‘ Breakpoints are screen sizes where the layout should change.
β Example with Multiple DevicesΒ
π Test it by resizing your screen!Β
Make text bigger on small screens for better readability! π
β HTMLΒ
β CSSΒ
π Now the menu stacks vertically on small screens!Β
Want to hide something on mobile but show it on desktop?
π‘ Use this to create mobile-friendly navigation!Β
π¨ Try this code! Copy & paste it into index.html and open in a browser.
π What to Do Next?
βοΈ Resize your screenβwatch the background and text change automatically!
βοΈ Try different breakpoints for tablets, laptops, etc.
βοΈ Hide/show elements based on screen size!
β @media (max-width: 600px) β Styles for small screens π±
β Change colors, fonts, layouts based on screen size π¨
β Hide or show elements (display: none;) π
β Helps create responsive websites for all devices! π
Flexbox is one of the most powerful CSS layout systems! It makes arranging elements super easyβperfect for responsive designs, navigation bars, and centering elements! π―
Flexbox (Flexible Box Layout) is a way to arrange items inside a container. It helps with:
β Centering items (vertically & horizontally)
β Creating flexible layouts
β Making responsive designs
β Basic SyntaxΒ
π This makes everything inside .container flexible!Β
The element that holds the flex items
You apply display: flex; to it
The elements inside the flex container
They automatically adjust based on available space
πΉ Example:Β
π Now the boxes sit side by side! πΒ
Makes child elements flexible π―Β
πΉ Now, your link will look like a green button that changes on hover! πΒ
Controls the main axis direction (horizontal or vertical).
βοΈ row β Left to right (default)
βοΈ row-reverse β Right to left
βοΈ column β Top to bottom
βοΈ column-reverse β Bottom to top
πΉ Try this:Β
π Now it becomes mobile-friendly! π±Β
Controls how items align along the main axis.
βοΈ flex-start β Items start from the left
βοΈ flex-end β Items move to the right
βοΈ center β Items are centered
βοΈ space-between β Items are evenly spaced
βοΈ space-around β Adds space around each item
πΉ Try this for a cool effect! π¨Β
Controls how items align on the cross axis (vertical if row, horizontal if column).
βοΈ stretch β Items stretch to fill height (default)
βοΈ flex-start β Items align to the top
βοΈ flex-end β Items align to the bottom
βοΈ center β Items center
π Perfect for centering elements! π―Β
Should items wrap to the next line if there's not enough space?
βοΈ nowrap β No wrapping (default)
βοΈ wrap β Items wrap to the next row
βοΈ wrap-reverse β Wraps in reverse order
πΉ Test this by resizing your screen!
Now, letβs build a real navigation bar using Flexbox! π
β Step 1: The HTMLΒ
β Step 2: The CSSΒ
π¨ Try this! Copy & paste into index.html and open in a browser.
π What to Do Next?
βοΈ Try changing justify-content and align-items
βοΈ Add more nav links & see how Flexbox handles them
βοΈ Experiment with flex-wrap for different screen sizes
β Use color and text-decoration to style links.
β Customize hover, active, and visited states for a better user experience.
β Turn links into buttons using display: inline-block and background-color.
β Add smooth transitions for cool hover effects.
β Flexbox makes layouts easy & responsive
β display: flex; β Activates Flexbox
β justify-content β Aligns items on the main axis
β align-items β Aligns items on the cross axis
CSS Grid is a powerful layout system that lets you create complex designs easily. Unlike Flexbox (which works in one direction), CSS Grid works in both rows & columns at the same time! ποΈπ¨
CSS Grid is a 2D layout system that helps create responsive, grid-based designs.
β Place elements in rows & columns π
β Align items easily without extra divs π
β Perfect for web pages, galleries, and dashboards!
β Basic SyntaxΒ
π This creates a 3-column layout! π¨Β
Letβs make a simple grid with 3 columns and 2 rows.
β Step 2: The CSSΒ
Defines the number & size of rows.
Adds space between grid items (like margin but for the grid).
Controls horizontal alignment of the whole grid.
β start β Aligns grid left
β center β Centers the grid
β end β Aligns grid right
Controls vertical alignment of the whole grid.
β start β Aligns grid to the top
β center β Centers the grid
β end β Aligns grid to the bottom
Sometimes, you want specific items to span multiple columns or rows.
β 2. grid-row (Span Rows)Β
π Great for making featured sections! π¨Β
Letβs make a responsive grid that changes on smaller screens!
β Step 2: The CSSΒ
π Now the layout adjusts for different screen sizes! π±Β
π¨ Try this! Copy & paste into index.html and open in a browser.
π What to Do Next?
βοΈ Try different grid-template-columns values
βοΈ Make items span multiple columns & rows
βοΈ Test justify-content and align-content
β display: grid; β Activates Grid
β grid-template-columns β Defines columns
β grid-template-rows β Defines rows
β gap β Adds space between grid items
β Great for layouts, galleries, and dashboards!
Cards are awesome for displaying content in an organized and stylish way. Letβs build a fully responsive card layout using CSS Grid & Flexbox! π¨π±
A card is a container that holds an image, title, description, and a button. It's used for product listings, blog posts, user profiles, etc.
π³ Product Cards
π° Blog Post Previews
π€ Profile Cards
Letβs create 3 cards inside a container.
π This creates 3 simple cards! π¨Β
Now, letβs add CSS to style the cards.
π Now our cards look stylish & interactive! β¨Β
Letβs make the cards adjust for smaller screens.
π Now the layout adjusts for tablets & phones! π±Β
π¨ Try this! Copy & paste into index.html and open in a browser.
π What to Do Next?
βοΈ Change the number of columns in grid-template-columns
βοΈ Add more cards and see how the layout adjusts
βοΈ Experiment with different button styles & colors
β Cards organize content in a stylish way
β display: grid; makes the layout responsive
β gap: 20px; adds spacing between cards
β Hover effects make the cards interactive
β Responsive media queries adjust for small screens
π Great Job!Β