Open In App

Foundation CSS Off-canvas Scrollbox

Last Updated : 24 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is built on Saas-like bootstrap. It is more sophisticated, flexible, and easily customizable. It also comes with CLI, so it’s easy to use it with module bundlers. It offers the Fastclick.js tool for faster rendering on mobile devices.  

Off-canvas panels are positioned outside of the viewport and slide in when activated. These off-canvas menus can open from left, right, top or bottom, overlap our content, push our content, and can work with sticky elements. These are responsive mobile patterns mainly for mobile screens. This can also be used as a sidebar on medium and desktop screens.

The off-canvas scroll box is useful in placing scrollable elements within an off-canvas. 

Foundation CSS off-canvas scroll box classes:

  • off-canvas: This class creates an off-canvas container.
  • data-off-canvas-scrollbox: This contains scrollable elements inside the off-canvas.
  • off-canvas-content: The main content of your page will be in this container.
  • button: This creates a button that can be used to open or close the panel.

Syntax:

<div class="off-canvas position-class" id="" 
    data-off-canvas data-off-canvas-scrollbox>
       <!-- menu or off-canvas content -->
</div>

<div class="off-canvas-content" 
    data-off-canvas-content>
       <!-- page content  -->
</div>

Note:

  • The data-off-canvas attribute must be added to the off-canvas container.
  • The id attribute of the off-canvas is unique so that it can be targeted by the click trigger by a button.
  • The data-off-canvas-content attribute must be added to the off-canvas-content container which consists of the content of the page.
  • The attribute data-open or data-toggle is added to any element to open an off-canvas panel when clicked on it.
  • The value of the attributes data-open or data-toggle must be equal to the unique id of the off-canvas container.
  • The data-close attribute is used to close an off-canvas panel.
  • The default value of an off-canvas container is position: fixed.

Example 1: This is a basic example illustrating the left side off-canvas scroll box created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Foundation CSS Off-canvas Scrollbox</title>
  
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css" />
  
    <!-- Compressed JavaScript -->
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        body {
            margin-left: 10px;
            margin-right: 10px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <strong>Foundation CSS Off-canvas Scrollbox</strong>
  
    <div class="off-canvas-wrapper">
        <div class="off-canvas-content" 
            data-off-canvas-content style="min-height:300px;">
            <div class="grid-x">
                <div class="cell">
                    <button type="button" class="button" 
                        data-toggle="offCanvasScrollbox">
                        Open Off-canvas
                    </button> <br /><br />
                </div>
            </div>
  
            <div class="off-canvas-absolute position-left" 
                id="offCanvasScrollbox" data-off-canvas
                data-content-scroll="false">
                <div style="padding:0 1rem;">
                    <article data-off-canvas-scrollbox 
                        style="max-height:290px; 
                            overflow:auto; padding:0.5rem 0;
                                margin-bottom:1rem; 
    box-shadow:inset 0 -10px 10px -10px rgba(0,0,0,0.65);">
                        <p>List 1</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                    <article style="max-height:290px; 
                        overflow:auto; padding:0.5rem 0; 
                           margin-bottom:1rem; 
box-shadow:inset 0 -10px 10px -10px rgba(0,0,0,0.65);">
                        <p>List 2</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                    <article style="padding:0.5rem 0;">
                        <p>List 3</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

 

Example 2: This is a basic example illustrating the right side off-canvas scroll box created using Foundation CSS.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Foundation CSS Off-canvas Scrollbox</title>
    <!-- Compressed CSS -->
    <link rel="stylesheet" href=
    <link rel="stylesheet" href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css" />
    <!-- Compressed JavaScript -->
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        body {
            margin-left: 10px;
            margin-right: 10px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <strong>Foundation CSS Off-canvas Scrollbox</strong>
  
    <div class="off-canvas-wrapper">
        <div class="off-canvas-content" 
            data-off-canvas-content style="min-height:300px;">
            <div class="grid-x">
                <div class="cell">
                    <button type="button" class="button" 
                        data-toggle="offCanvasScrollbox">
                        Open Off-canvas
                    </button>
                </div>
            </div>
            <div class="off-canvas-absolute position-right" 
                id="offCanvasScrollbox" data-off-canvas
                data-content-scroll="false">
                <div style="padding: 0 1rem;">
                    <article data-off-canvas-scrollbox 
                        style="max-height:290px; overflow:auto; 
                        padding:0.5rem 0; margin-bottom:1rem; 
    box-shadow:inset 0 -10px 10px -10px rgba(0,0,0,0.65);">
                        <p>List 1</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                    <article style="max-height:290px;
                        overflow:auto; padding:0.5rem 0; 
                        margin-bottom: 1rem; 
box-shadow:inset 0 -10px 10px -10px rgba(0,0,0,0.65);">
                        <p>List 2</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                    <article style="padding:0.5rem 0;">
                        <p>List 3</p>
                        <ul>
                            <li>Item 01</li>
                            <li>Item 02</li>
                            <li>Item 03</li>
                            <li>Item 04</li>
                            <li>Item 05</li>
                            <li>Item 06</li>
                            <li>Item 07</li>
                            <li>Item 08</li>
                            <li>Item 09</li>
                            <li>Item 10</li>
                        </ul>
                    </article>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).foundation();
    </script>
</body>
  
</html>


Output:

 

Reference: https://get.foundation/sites/docs/off-canvas#off-canvas-scrollbox



Previous Article
Next Article

Similar Reads

How to create a responsive scrollbox in CSS ?
The purpose of this article is to create a responsive scrollbar in HTML page structure using CSS. In CSS, responsive scroll box is an interaction technique which contains text, images, or any other elements. They can be scrolled in preset directions, which allows users to scroll if the contents are larger for the box. Scroll boxes are often used wh
2 min read
Foundation CSS Off-canvas Multiple Panels
Foundation CSS is a front-end framework for creating flexible web designs that are free and open-source. It's one of the most powerful CSS frameworks, with a responsive grid, HTML and CSS UI components, templates, and more that operate across all platforms. It also has a number of optional JavaScript Extension capabilities. Thanks to the integratio
4 min read
Foundation CSS Off-canvas Directions
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing &amp; can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
4 min read
Foundation CSS Off-canvas Transitions
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing &amp; can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
3 min read
Foundation CSS Off-canvas Combining with Title Bar
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing &amp; can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
4 min read
Foundation CSS Off-canvas Position
Foundation CSS is a free, open-source front-end framework that allows you to create dynamic web designs. It's one of the most advanced CSS frameworks, including a responsive grid, HTML and CSS UI components, templates, and more. It also has a variety of JavaScript Extension features that can be enabled or disabled. It also renders swiftly on mobile
4 min read
Foundation CSS Off-canvas Reveal on Larger Screens
Foundation CSS is a free, open-source front-end framework for generating flexible web designs. With a responsive grid, HTML and CSS UI components, templates, and more, it's one of the most powerful CSS frameworks. It also contains a number of JavaScript Extension capabilities that may be turned on or off. It also renders quickly on mobile devices t
4 min read
Foundation CSS Nested Off-Canvas
Foundation CSS is a free and open-source front-end framework for generating flexible web designs. With a responsive grid, HTML and CSS UI components, templates, and more, it's one of the most powerful CSS frameworks. It also contains a number of JavaScript extension capabilities that may be turned on or off. Thanks to the integration of the Fastcli
5 min read
Foundation CSS Off-canvas Sticky
Foundation CSS is a free, open-source front-end framework for creating dynamic web designs. It includes a responsive grid, HTML and CSS UI components, templates, and more, making it one of the most comprehensive CSS frameworks. It also has a number of JavaScript Extension features that can be turned on or off. It also renders quickly on mobile devi
4 min read
Foundation CSS Off-canvas Sass Reference
Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is bui
5 min read