CSS Grid is a two-dimensional layout template that can be combined with CSS media queries to produce complex and responsive website layouts, including layouts for e-commerce stores.
The Internet and the devices we use to access them have grown. Web sites have become interactive applications with significant capabilities. Customers of an online retailer, for example, can shop from screens as small as a dial, as large as a TV, and everything in between .
Unfortunately, the web pages used to present these applications on different devices have not always been well suited to the task.
” Using a combination of tables, JavaScript, or neat measures on floating elements, the authors have discovered workarounds to get the desired layouts “wrote the writers of the World Wide Web Consortium. ]
"Arrangements adapted to the available space were often fragile and resulted in counterintuitive behavior as space became limited. As an alternative, the authors of many web applications have opted for a fixed layout that can not take advantage of changes in rendering space available on a screen. ”
Grid systems and CSS grid layout
In the quote above, the W3C is a bit difficult on some of the current and popular workarounds. Consider a common e-commerce layout: a category page with seven products.
A product category page is an example of a common e-commerce layout.
You can use a popular CSS framework that includes a "grid system". Grid systems are one of the "workaround" layout solutions that generally rely on carefully measured floats. A grid system should not be confused with the CSS structure named in the same way, or CSS Grid as it is often called.
The first uses floats to create grids and nested grids. The latter is a layout module first released as a W3C project in 2011 and now supported by all major web browsers, including the latest versions of Chrome, Firefox, Safari, Edge, Opera, Chrome and the Android browser.
Here are some examples of HTML tags to show you how a grid system might work.
Four men's diamond square t-shirt
...
The element section with the class name of ” container-fluid ” and the div element with the class ” row ” add the Space around the contained items, which in this example are the products we want to appear on the category page of products.
Class ” col-sm-3 ” refers to the 12-column layout of this grid system and to a set of CSS media queries that use different style statements, depending on the width from the screen of the user. This class could say that on screens of 768 pixels wide or more, the div element should occupy three of the 12 available columns. Indeed, this would list four products across the rank.
In the style sheet, this class is set to occupy a quarter of the available space and ” float ” left, which means that it will be aligned on the left side of its container (parent element). The floating element is removed from the normal flow of the page.
This particular div element – with the class name ” col-sm-3 ” – will be repeated for each product on the page.
For products to look as expected, you must close the div ” row ” after using 12 columns and reopen a new line for the other items. Given seven products, you would need two rows.
Men's T-shirt Four Square Diamonds From $ 23.50
... // three other products
Men's T-shirt of eight red squares
... // the other two products
You could give up the line divs, and with only seven products, the page would probably be formatted without a problem. But if you had 47 products, the grid system could become ” brittle “as the W3C says, and the layout might break. Your lines would become disjoint and the floats might not align.
If the pages in your product category have been generated dynamically, which is common for ecommerce sites, you will need a logic in your page template to close and open the lines. This would likely involve having a variable to store a number of products. After each fourth product, the conditional code is executed by adding the line elements.
The markup needed to produce the same product category page with the new CSS layout is similar.
<img class = ” wp-image-142643 size-large ” src = ” https://www.practicalecommerce.com/wp-content/uploads/2017/10/101217-example- grid-layout-570×307.png ” alt = ” A product category page is likely to include more than just product lines. There will be a header element, a sidebar, and in this example, a split footer. ” width = ” 570 ” height = ” 307 ” />
A product category page is likely to include more than just rows of products. There will be a header element, a sidebar, and in this example, a split footer.
If we returned to a grid system (again a grid system and not the [CSS CSS ), this would require fairly complex HTML markup that can be difficult to read given the number of div elements, class names and indentation levels.
...
...
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.