In this module, you’ll use semantic HTML, meta tags and Open Graph protocol to create a modern HTML structure for the web app. You will also use CSS grid and other CSS styling to set up a responsive, clear and inviting website.
Learning Objectives
- Set up a responsive website
- Use React components to create multiple views
- Design and style a responsive UI
Semantic structure
Video: Setting up a semantic HTML document
Summary of Module 2: Semantic Structure
In this lesson, you’ll review and apply techniques for organizing the structure of your capstone project, specifically focusing on semantic HTML. You’ll:
- Brush up on HTML: Review HTML5 syntax and focus on semantic HTML, which makes webpages more understandable for people, screen readers, and search engines.
- Set up an HTML document: Properly format your HTML structure using semantic HTML5 tags, such as
nav
,header
,footer
,main
,aside
, andarticle
. - Understand the importance of semantic HTML: Learn why using
div
elements everywhere is not a best practice and how semantic HTML5 tags help signal intent for both people and machines. - Work with meta tags and Open Graph protocol: Set up meta tags and Open Graph protocol settings to assist with search engine optimization and social media sharing.
- Complete readiness checks: Complete two readiness checks, one for meta tags and Open Graph protocol settings, and another for tracking progress with Git.
- Take a quiz and access additional resources: Complete a quiz and access additional reading materials to further reinforce your knowledge of semantic HTML, meta tags, and Open Graph tags.
By the end of this lesson, you’ll have a solid understanding of semantic HTML and how to apply it to your capstone project.
With HTML 5, you should use the <div> element instead of semantic tags.
False
That’s correct. In line with the proper HTML 5 semantics, you should focus instead on using the many semantic HTML 5 tags that are available today, rather than relying on the <div> element.
Welcome to Module 2 of this
course, Project Foundations. In this lesson entitled
Semantic Structure, you’ll revise the techniques
and technologies related to properly organizing
the structure of your capstone project, continuing your work on the reserve a table Web
App for Little Lemon. From the vantage
point of this lesson, this means that you’ll need
to brush up on your HTML. Specifically, you’ll be
focusing on semantic HTML, a more modern HTML5 syntax that makes webpages
convey more meaning, allowing people, screen readers, and search engines to better
understand a site’s markup. The first exercise of this
lesson will deal with properly setting up
your HTML document. You will subsequently
be quizzed on your progress regarding
the semantic HTML. You may be wondering
why this is important. Well, the point of
these lesson items is to ensure that
you properly format your HTML structure
so that it’s in line with a proper
HTML5 semantics. You’ll be reminded that using the div element everywhere
is not a best practice, and that you should
focus on using the many semantic HTML5 tags that are available
today instead. These tags which
can be used to find the various web page sections include but are not limited
to the nav element, the header element,
the footer element, the main element,
the aside element, and the article element. You’ll also be reacquainted
with the history of HTML, the difference between
HTML4 and HTML5, and why HTML5 spec has such
a focus on semantic tags. You’ll revisit the need to
have a more expressive syntax to help signal intent for
both people and machines, including search engine bots, crawling countless
HTML pages online. After you’ve set up a
semantic HTML document, you’ll need to shift your
focus onto working with meta tags and setting
up Open Graph protocol. To assist you with this part
of the capstone project, you will revisit what you
learned on the subject in the HTML and CSS
in-depth course. You’ll then be tasked with completing two readiness checks, one for completing the meta tags in the Open Graph
protocol settings, and the other one related to tracking your progress with Git. You will complete
this lesson with a quiz and a reading
linking you to additional related resources
and useful reading materials to further reinforce
your knowledge related to semantic HTML, meta tags and Open Graph tags. Now, let’s get going.
Reading: Recap: Semantic HTML
Reading
Overview
In this reading, you will recap semantic HTML. The revision topics in this reading are from the HTML and CSS in-depth course from the Front-End developer program, with a particular focus on the Semantic and Meta tags lesson in the HTML in-depth module.
What are semantic tags?
Semantic tags are a way to describe the meaning of your web page through tags. For example, older, non-semantic HTML used the following HTML structure to style a main menu section of a web page:
<div>
<ul>
<li><a href="/home">Homepage</a></li>
<li><a href="/about">About Us</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
</div>
The above structure is not signaling that it’s a menu for navigation in any way. Instead, to create a more semantic HTML structure, you replace the <div> element with the HTML5 <nav> element.
<nav>
<ul>
<li><a href="/home">Homepage</a></li>
<li><a href="/about">About Us</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
</nav>
The code example above is a better way to signal intent. Let’s explore why.
The nav versus div elements
In the example above, the <nav> element describes the meaning of the particular section of the webpage as the element itself is meant to be used to contain some kind of navigation. However, a <div> tag is just there to group any collection of HTML elements when there is no better (more semantic) way to group them. This means that the <div> tag is less semantic or less meaningful. In other words, it conveys less meaning about what exactly the given HTML snippet’s role and purpose is. The <nav> tag is more semantic because it signals that the given structure is meant to be used as some sort of navigation menu. This is a simple but effective example for reminding you what semantic HTML is all about.
Metadata and meta tags
To further revise the purpose of semantic HTML, please revisit the following lesson items from the HTML and CSS in-depth course:
It’s important to remember that <meta> tags are tags that contain data about a given web page. They are used to define SEO-relevant data, responsive and mobile behavior of a given web page, encoding and more.
The role attribute
The role attribute is another tool you have at your disposal when writing semantic HTML. The role attribute describes the role of an element in a web page. This attribute is global meaning you can use it on any element. While many elements have implicit roles, you can make them explicit by adding a role attribute.
<a href="/book" role="button">Book a table</a>
Conclusion
In this reading, you revisited the concept of semantic tags in HTML and the role attribute. Following this quick revision of semantic HTML, including meta tags, you should be ready to complete the exercise in the next lesson item, which involves setting up the HTML document for the Little Lemon web app.
Reading: Exercise: Setting up the HTML document
Reading
Overview
Using semantic HTML and understanding how it works in React is the next fundamental step in the process of creating the reserve-a-table web functionality for Little Lemon. In this exercise, you will organize your JSX code so that it follows HTML5 best practices.
To revisit using semantic HTML in webpages, you may find it helpful to refer to the following lesson items in the HTML and CSS in-depth course now or as you progress through the exercise:
Scenario
By completing this exercise, your React app will use a semantic HTML structure to better describe the intention and semantics of the document. As you have learned, semantic HTML is important for describing the meaning, or semantics, of your HTML document. It also assists accessibility software, such as screen readers, in describing your content to users with disabilities.
Instructions
Step 1: Set up the initial semantic structure
- Open your project in Visual Studio Code.
- Open the App.js file.
- The App component’s root element uses a div element. As this is not a semantic tag, replace it with a React fragment.
Tip: Remember, a fragment starts with a <> tag and ends with a </> tag.
- Review your UI/UX and decide how each of the sections of the design will be represented using semantic tags.
Tip: Use the header, nav, main and footer semantic tags.
- Inside the fragment, add the semantic tags.
Step 2: Break the sections down into React components
Now that you have planned your semantic structure, it is important to decide which sections will be dynamically updated and if those sections should be child components of the App component.
Tip: For simplicity, you can create a component for each semantic element you added to App.js.
- Create a JavaScript file for each semantic element that will be a React component, for example, Header.js, Nav.js, Main.js and Footer.js.
- In each component, return the semantic HTML element.
- In App.js, replace the semantic tags with the corresponding child components, for example <header></header> will be replaced with <Header/>.
Step 3: Add the logo and navigation elements
The initial components are now set up. You will now add the details for the logo and navigation.
- Add the Little Lemon logo to the appropriate React component using the <img> tag.
- Add the website navigation to the Nav component. It is important to add a hyperlink for each key page of the website based on your mockup.
Tip: Use a <ul> element and add an <li> element for each <a> hyperlink.
Step 4: Add the footer content
Review your design and add the necessary HTML elements to the footer component.
Conclusion
By completing this exercise, you have now set up the semantic foundations to build the rest of your application. As you progress through the course, ensure that you apply the appropriate semantic HTML elements to the content that you are building.
Reading: Recap: Meta tags and Open Graph protocol
Reading
Overview
In this reading, you will revisit the concepts of Open Graph protocol and Open Graph meta tags.
What is Open Graph protocol (OGP)?
Open Graph protocol is an internet protocol that was built by Facebook. It’s a structured way to describe the content of a web page. Before OGP, there were many ways to turn a web page into a rich object, ready to be shared on social media. The OGP brought about a single, simple technology for making this possible.
A review of meta tags and OGP
Meta tags have many purposes, but the most important are:
- Sharing your web pages on social media
- Improving your website’s search engine optimization using your code (often referred to as technical SEO)
Just like regular HTML, Open Graph meta tags can be validated. Most web and IT professionals know that SEO is a moving target, just like most other technologies on the web. However, for the most part, SEO is not directly affected by the use of meta tags. Additionally, meta tags are very important because they allow you to increase conversions because they affect the way that shared content looks on social media sites.
However, keep in mind that poorly formatted meta tags might end up in, for example, a user sharing a link to your web app, but instead of a relevant image showing up in the shared preview, some other image displays. Although this other image still exists on your site, it’s different from the one that you’d like to show up when your web app’s URLs are shared on social media.
Meta tags examples
Here are a few specific examples of meta tags in use:
description
A meta description is a summary of what a given page is about.
<meta name="description" content="Get all your sports fishing equipment at One Place Fishing. Open Monday to Friday, 9 to 5, in the Great Lake area."/>
og:title
The og:title meta tag is there for you to give a title for your shared link or shared content.
<meta name="og:title" content="One Place Fishing"/>
og:description
A title is usually followed by a description, which is what the og:description meta tag is for.
<meta name="og:description" content="some description here"/>
og:image
The og:image meta tag specifies the image to serve when a link is shared on social media.
<meta name="og:image" content="https://example.com/one-place-fishing-store.jpg"/>
You can find out more information about the OGP and about how to use the Open Graph tags from the ogp.me website.
To re-iterate, meta tags are “tags about HTML tags”. In other words, they give some additional information about the web page itself. You might say that the Open Graph tags are a subset of meta tags, with this subset being specifically responsible for formatting previews to your web app’s content when its URLs are shared as links. What’s so great about the OGP is that it plugs into the existing system of meta tags in HTML5 and allows developers to seamlessly turn web pages into rich objects in a social graph.
Conclusion
You’ve revisited meta tags and the Open Graph protocol in this reading. You should now be prepared to add meta tags to your project as well as set up OGP.
Mark as completedLikeDislikeReport an issue
Reading: Exercise: Adding meta tags and setting up OGP
Reading
Overview
Building a website is an important part of marketing a business. Equally, word of mouth and social media are important for bringing in new customers. In this exercise, you will prepare the Little Lemon web app for search engines and social media platforms, by adding meta tags and setting up Open Graph protocol (OGP).
Scenario
The Little Lemon restaurant makes great food and the owners hope that happy customers will recommend the restaurant to others by sharing the website on social media. Potential customers may also try to find the website using popular search engines. It is an important task to make sure that the website is presented correctly on both search engines and social media platforms. In this exercise, you will add metatags and set up the Open Graph protocol (OGP) to help ensure the correct presentation of your project on these various platforms. You may find it helpful to refer to the following lesson items in the HTML and CSS in-depth course now or as you progress through the exercise:
Instructions
You will apply the following to the index.html file in your project.
Step 1: Add the appropriate description (meta tag)
Add your own description for your Little Lemon restaurant application:
<meta name="description" content="your text goes here"/>
Step 2: Add the og:title meta tag
Add the Open Graph’s title for your Little Lemon restaurant application, inside the double quotes in the content HTML attribute:
<meta name="og:title" content=""/>
Step 3: Add the og:description meta tag
Add your own description for your Little Lemon restaurant application, inside the double quotes in the content HTML attribute:
<meta name="og:description" content=""/>
Step 4: Add the og:image meta tag
Add your own Open Graph image for your Little Lemon restaurant application, inside the double quotes in the content HTML attribute:
<meta name="og:image" content=""/>
Conclusion
In this exercise, you prepared the Little Lemon web app for search engines and social media platforms using Open Graph meta tags. When the app is launched online, it will appear with the correct information for potential customers.
Practice Assignment: Knowledge check: Semantic structure
Which of the following are semantic HTML tags? Choose all that apply.
<article>
<div>
<h1>
<header>
<table>
<article>
That’s correct. The <article> tag is a semantic HTML tag used to represent a standalone piece of content, such as a blog post or news article.
<h1>
That’s correct. The <h1> tag is a semantic HTML tag used to represent the main heading of a webpage or section of content.
<header>
That’s correct. The <header> tag is a semantic HTML tag used to represent the header of a webpage or section of content.
<table>
llama 3.2
The following are semantic HTML tags:
<article>
: This tag represents a self-contained piece of content, such as a blog post or a news article.<h1>
: This tag represents a heading, specifically the most important heading on a page.<header>
: This tag represents the header section of a document or section, typically containing the title, logo, and navigation.<table>
: This tag represents a table of data, with rows and columns.
The following is not a semantic HTML tag:
<div>
: This tag is a generic container element, and does not provide any specific meaning or structure to the content it contains. It is often used as a fallback when a more specific semantic tag is not available.
Semantic HTML tags provide meaning and structure to the content of a web page, making it easier for search engines, screen readers, and other tools to understand the content and provide a better user experience.
Here are some other examples of semantic HTML tags:
<nav>
: Represents a navigation section.<footer>
: Represents the footer section of a document or section.<section>
: Represents a self-contained section of related content.<aside>
: Represents a piece of content that is related to the main content, but is not essential to the understanding of the main content.<figure>
: Represents a piece of content that is related to the main content, such as an image or a diagram.<figcaption>
: Represents the caption for a<figure>
element.<main>
: Represents the main content of a document or section.<summary>
: Represents a summary or abstract of a piece of content.<details>
: Represents a piece of content that can be expanded or collapsed.
It’s worth noting that while semantic HTML tags provide meaning and structure to the content of a web page, they do not affect the visual styling of the content. That is typically handled by CSS.
Complete the sentence: Semantic tags are a way to…
Give meaning to the content of a webpage or document.
Create a layout for a webpage or document.
Create a table of data.
Add style to a webpage or document.
Give meaning to the content of a webpage or document.
That’s correct. Semantic tags give meaning to the content of a webpage or document by indicating the purpose or function of the content. This makes it easier for search engines and screen readers to understand the content and helps improve the overall accessibility of the webpage or document.
llama 3.2
The correct answer is:
Semantic tags are a way to give meaning to the content of a webpage or document.
Semantic tags, also known as semantic HTML, are a way to add meaning and structure to the content of a webpage or document. They provide a way to describe the purpose and function of different elements on a webpage, such as headings, paragraphs, images, and links. This makes it easier for search engines, screen readers, and other tools to understand the content and provide a better user experience.
The other options are not correct because:
Adding style to a webpage or document is done using CSS, not semantic tags.
Creating a layout for a webpage or document is typically done using CSS (Cascading Style Sheets).
Creating a table of data is done using the <table>
element, which is a specific type of semantic tag, but not the primary purpose of semantic tags.
What is Open Graph protocol (OGP)?
A protocol for sending and receiving email messages
A protocol for describing the shared content on social media platforms
A protocol for transmitting audio and video over the internet
A protocol for encrypting data transmitted over the internet
A protocol for describing the shared content on social media platforms
That’s correct. The Open Graph protocol is a protocol for sharing content on social media platforms. It allows developers to specify how content should be displayed when shared on social media sites such as Facebook.
llama 3.2
The correct answer is:
A protocol for describing the shared content on social media platforms
The Open Graph protocol (OGP) is a protocol that allows web developers to define how their web pages are represented on social media platforms, such as Facebook, Twitter, and LinkedIn. It provides a way to describe the content of a web page, including its title, description, image, and other metadata, in a format that can be easily understood by social media platforms.
When a user shares a link to a web page on a social media platform, the platform uses the Open Graph protocol to retrieve the metadata associated with the web page and display it in a rich and engaging way. This can include displaying an image, title, and description of the web page, as well as other metadata such as the author and publisher.
The Open Graph protocol is used by many social media platforms, including Facebook, Twitter, LinkedIn, and Pinterest, and is widely supported by web developers and content creators.
The other options are not correct because:
- The protocol for sending and receiving email messages is called Simple Mail Transfer Protocol (SMTP).
- The protocol for transmitting audio and video over the internet is called Real-time Transport Protocol (RTP).
- The protocol for encrypting data transmitted over the internet is called Transport Layer Security (TLS) or Secure Sockets Layer (SSL).
Here is an example of how Open Graph protocol is used:
<meta property="og:title" content="Example Web Page" />
<meta property="og:description" content="This is an example web page" />
<meta property="og:image" content="https://example.com/image.jpg" />
This code defines the metadata for a web page using the Open Graph protocol, including the title, description, and image. When a user shares a link to this web page on a social media platform, the platform will use this metadata to display a rich and engaging representation of the web page.
HTML meta tags are used to provide information about a webpage to search engines and other web services.
True
False
True
That’s correct. HTML meta tags provide information about a webpage, such as its title, description and keywords, to search engines and other web services. This information is used to help search engines understand the webpage’s content and improve its ranking in search results.
llama 3.2
True
HTML meta tags are used to provide information about a webpage to search engines and other web services. They are a way to describe the content, keywords, and other attributes of a webpage, which can help search engines and other web services understand the context and relevance of the webpage.
Meta tags are typically placed in the <head>
section of an HTML document and are used to provide information such as:
- Title and description of the webpage
- Keywords and phrases related to the webpage
- Author and publisher of the webpage
- Date and time of publication
- Robots instructions (e.g., “noindex”, “nofollow”)
- Open Graph protocol metadata (e.g., title, description, image)
Search engines like Google, Bing, and Yahoo use meta tags to:
- Index and rank webpages
- Display webpage titles and descriptions in search results
- Understand the context and relevance of webpages
Other web services, such as social media platforms and content aggregators, also use meta tags to:
- Display webpage titles and descriptions in social media posts
- Understand the context and relevance of webpages for content aggregation
Here is an example of a basic HTML meta tag:
<meta name="description" content="This is a webpage about HTML meta tags">
This meta tag provides a description of the webpage, which can be used by search engines and other web services to understand the context and relevance of the webpage.
Which of the following meta tags are valid? Choose all that apply.
responsive
description
viewport
og:title
description
That’s correct. The description tag is a valid HTML meta name used to specify a description of the content of a webpage.
viewport
That’s correct. This is a valid HTML meta name used to specify the viewport for a webpage. The viewport is the area of the webpage that is visible to the user and determines how the webpage is displayed on different devices.
og:title
That’s correct. The og:title is a valid Open Graph protocol (OGP) meta name used to specify the title of a webpage when it is shared on social media platforms.
llama 3.2
The following meta tags are valid:
- description: This meta tag is used to provide a brief summary of the webpage’s content. It is a standard meta tag that is widely supported by search engines and other web services.
- viewport: This meta tag is used to control the zooming and scaling of a webpage on mobile devices. It is a standard meta tag that is widely supported by mobile browsers.
- og:title: This meta tag is used to specify the title of a webpage for Open Graph protocol. It is a valid meta tag that is widely supported by social media platforms and other web services.
The following meta tag is not valid:
- responsive: This is not a standard meta tag. While it is a common term used to describe web design, it is not a valid meta tag that is recognized by search engines or other web services.
Here is an example of how these meta tags can be used:
<meta name="description" content="This is a webpage about HTML meta tags">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="HTML Meta Tags">
Note that the og:title
meta tag is part of the Open Graph protocol, which is a separate set of meta tags that are used to provide additional information about a webpage to social media platforms and other web services.
Reading: Additional resources
Reading
Here is a list of lesson items from the HTML and CSS in-depth course that may be helpful as you continue your learning journey. These resources provide some more in-depth information on the topics covered in this module.
Styling and responsiveness
Video: Styling elements
The lesson discusses the evolution of CSS layout techniques and the importance of understanding modern CSS layout techniques, specifically CSS Grid and Flexbox.
Key Points:
- History of CSS layouts: The lesson briefly covers the history of CSS layouts, from table-based layouts to floats, and then to Flexbox and CSS Grid.
- Flexbox and CSS Grid: Flexbox is a one-dimensional layout technique used to arrange items in rows or columns, while CSS Grid is a two-dimensional layout technique used to build web layouts.
- Evolution of CSS Grid: CSS Grid was first introduced in the early 2010s, but it wasn’t widely adopted until 2018, when modern browsers caught up with the specification.
- Benefits of using CSS Grid and Flexbox: Both CSS Grid and Flexbox have their own benefits and use cases, and it’s essential to know both to make informed decisions about layout choices.
- Importance of understanding modern CSS layout techniques: Understanding modern CSS layout techniques is crucial for making informed decisions about layout choices and determining whether existing code is up to modern standards.
Learning Objectives:
By the end of this lesson, you should be able to:
- Understand the history of CSS layouts and the evolution of CSS Grid and Flexbox.
- Know the benefits and use cases of CSS Grid and Flexbox.
- Make informed decisions about layout choices.
- Determine whether existing code is up to modern standards.
- Choose the right approach for building CSS layouts.
Focus of the lesson: The lesson will mainly focus on building CSS layouts using CSS Grid, as it’s the most comprehensive and versatile tool in the modern CSS layout toolbox.
Which of the following are modern ways to build CSS layouts?
Grid layout, Flexbox layout
That’s correct. Modern CSS layouts use CSS Flexbox, in addition to another modern alternative.
In this lesson, you’ll revisit
the topic of styling web pages and web apps in order to apply
the little lemon style guide and layout designs created
earlier in the course. To begin with, you’ll explore working with CSS in
isolation without focusing on react. After that, you’ll work with CSS. From the perspective of react, you may recall that CSS has been
around since the late 1990s. This means that there have been
various ways of laying out websites. Let’s explore them briefly. It all started off with
table-based layouts, which are now an outdated
way to build layouts. After that in the early two thousand’s,
another technique became popular floats. As a CSS property, a float is intended to remove HTML
element from the normal document flow. In other words, when you float an element, it no longer obeys
the normal document flow. Floats were popular for quite some time,
however, because they were not intended for building web layouts, proper
layout syntax was still needed in CSS. With the consensus that something
better was needed in the early 2010s, there were a few attempts at
introducing the CSS flexible layout module specification or flex box layout. Which is a one dimensional layout
technique used to arrange items in rows or columns. If you’d like to read up
more on flex box layouts, you can consult the additional
resources for this lesson. However, it’s worth noting this initial
attempt at the flex box layout in the CSS specification was not entirely
successful due to constantly shifting specifications and inconsistent and
spotty support across browsers. Finally, in the second half of the 2010s
decade, flex box saw a new specification and wide adoption with the CSS grid
specification following soon after it. The CSS grid layout technique really
took off somewhere around 2018 with the CSS grid layout module
being the part of the CSS spec whose purpose is to build web layouts. The reason is simple, it took a while for the browsers to catch up with the CSS
grid spec and for the older browsers that were not built to support CSS grid
to lose most of their market share. So after modern browsers caught up with
the CSS grid and older browsers that didn’t support it became obsolete,
CSS grid was widely adopted. There are various benefits to using
both CSS flex box and CSS grid. And in this lesson, you’ll revisit
the pros and cons of using each. You should not underestimate the role and
place of CSS flex box. And it’s important to keep in mind
that CSS grid is not a replacement for CSS flex box, it’s good if you know either
of them, but it’s best if you know both. Another reason to be aware of the various
layout techniques out there is to be able to make informed decisions
about layout choices. In their day to day work, developers
are very often faced with having to decide whether a piece of code is
good enough or if it needs changing. A lot of that decision making
process comes with experience. Still having a general idea about
modern CSS layout techniques and where they should be used is important for
a well rounded front end developer. Indeed, the more knowledge
you have on this topic, the better you’ll be at choosing the right
approach and determining whether the existing code in any project you
work on is up to modern standards. Furthermore, you’ll be able to
determine the best tool for the job. All that being said, the focus of this
lesson will mainly be on building CSS layouts using CSS grid as it’s
the most comprehensive and versatile tool in the modern
CSS layout toolbox. Time to get started.
Reading: Recap: CSS grids
Reading
Overview
In this reading, you will recap CSS Grids in preparation for setting up a CSS grid in your Little Lemon web app project.
What is a CSS Grid?
CSS Grids are two-dimensional web page layouts that are responsible and compatible with various browsers. They are an alternative to Flexbox and tables. In a Grid Layout, columns are vertical tracks and rows are horizontal tracks.
Using CSS Grid layouts
You can use a CSS grid layout on any collection of elements on your web page. To do so, you need to use the display property and set it to the value of grid. You can think of the display: grid CSS property as sort of a switch that turns the grid display on.
Once you have the CSS grid activated, you can quickly define a simple grid by just using grid-template-columns and grid-template-rows properties.As a reminder, here’s an example of this, taken from the CSS Grids lesson item from the HTML and CSS in depth course, an earlier course in the Front-End developer program:
.container {
display: grid;
grid-template-columns: 100px 100px 100px;
grid-template-rows: 2fr 1fr;
}
The fraction unit
Let’s explore the above code snippet, remember that grids introduce a new unit, fr, which stands for fraction. The fraction unit is a quick way to divide your grid in a straightforward and versatile way. Remember that you can use fraction and pixel values interchangeably in both grid rows and grid columns.
The repeat function
Another really useful tool in the grid layout is the repeat CSS function, which allows you to repeat columns or rows so that the code itself is less repetitive. As an example, here’s how you’d re-write the above code snippet using the repeat function:
.container {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: 2fr 1fr;
}
The first value given to the repeat function above is the number 3, meaning, there should be three columns in this grid. The second value is the width of each column in the grid – in this case, the width of each column is 100px.
The minmax function
Another useful function that you can utilize is the minmax function. In the example below, the grid-auto-rows property is used with a call to the minmax function, which sets the value for this grid’s rows to 150px each.
.container {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-auto-rows: minmax(150px, auto);
}
More on using CSS Grids
It’s important to note that the HTML and CSS in-depth course has additional lesson items that describe how to use CSS grid in more depth. If you need to brush up on additional topics, please take your time to do it. The following links may be helpful.
Conclusion
In this reading, you revisited the topics of CSS Grid and Grid layouts. With this recap on CSS grids completed, you are now positioned well to complete the exercise in the next lesson item, Setting up the CSS Grid.
Reading: Exercise: Setting up the CSS layout
Reading
Overview
To build upon the wireframes you designed for the Little Lemon reserve-a-table web app functionality, your next task is to create the web app layout using HTML and CSS. In this exercise, you will use your CSS skills to code reusable sections of your app’s layout. The code you write in this exercise is one of many building blocks that you can use and reuse in different parts of your React app.
Scenario
Visitors to the Little Lemon website will be viewing the content on different devices, from small devices such as mobile phones to large devices like desktops and tablets. Therefore, the owners of Little Lemon have requested that the website is responsive. To achieve this you will need to implement the responsive column layout that you previously planned, using either a CSS Grid or Flexbox Layout. In this exercise, you will create the necessary CSS rules to allow for a responsive layout. You will apply these rules throughout the course. As you progress through the exercise, it may be helpful to revisit the following lesson items from the HTML and CSS in-depth course:
- CSS web layout
- CSS units of measurement
- Understanding Flexbox
- Basic Flexbox
- CSS Grids
- Grids and Flexbox cheat sheet
Instructions
Step 1: Set up the CSS rules
- Based on the mockup, decide if you will use a CSS Grid or Flexbox Layout
- Open the app.
- Based on the mockup, add the required CSS Grid or Flexbox rules to the file.
Tip: If you are unsure which rules to add, refer to the Grids and Flexbox cheat sheet lesson item.
Step 2: Apply the CSS rules to HTML elements
- Open the index.html file and apply the CSS rules to the HTML elements.
- Open your previously created component files and apply the CSS rules to the HTML elements.
Step 3: Verify that the HTML elements are positioned correctly
- Run your app using the npm start command
- Open the web browser and go to http://localhost:3000 to view the web app.
- Ensure that the elements are positioned correctly in the web browser
- Using the web browser developer tools to view the web page in responsive mode, ensure that the elements are positioned correctly on a mobile device.
Conclusion
By completing this exercise, the Little Lemon website’s visual layout will display correctly on different device sizes. This will provide a good user experience to visitors of the website.