Build it yourself - Header
यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।
Since your site will be viewed on different devices, it’s time to create a page navigation that can respond to multiple screen sizes!
Get ready to…
- Create a Header for your site that contains the Navigation component
- Make the Navigation component responsive
Try it yourself - Build a new Header component
-
Create a new Header component. Import and use your existing
Navigation.astro
component inside a<nav>
element which is inside a<header>
element.Show me the code!
Create a file named
Header.astro
insrc/components/
Try it yourself - Update your pages
-
On each page, replace your existing
<Navigation/>
component with your new header.Show me the code!
-
Check your browser preview and verify that your header is displayed on every page. It won’t look different yet, but if you inspect your preview using dev tools, you will see that you now have elements like
<header>
and<nav>
around your navigation links.
Add responsive styles
-
Update
Navigation.astro
with the CSS class to control your navigation links. Wrap the existing navigation links in a<div>
with the classnav-links
. -
Copy the CSS styles below into
global.css
. These styles:- Style and position the navigation links for mobile
- Include an
expanded
class that can be toggled to display or hide the links on mobile - Use a
@media
query to define different styles for larger screen sizes
Start by defining what should happen on small screen sizes first! Smaller screen sizes require simpler layouts. Then, adjust your styles to accommodate larger devices. If you design the complicated case first, then you have to work to try to make it simple again.
Resize your window and look for different styles being applied at different screen widths. Your header is now responsive to screen size through the use of @media
queries.
Checklist
Resources
-
Component-based Design external
-
Semantic HTML Tags external
-
Mobile-first Design external