Content...
% @side_nav = "js" %>
Section 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Section 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Section 2. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Sections replace a few things that you are used to from Foundation 3. We've taken the accordion, the tabs and the vertical nav and combined them into this really flexible plugin that can handle all of those. The single JS file handles all the interactions, but the classes you add to the element control how it gets rendered and styled across our breakpoint.
There are two ways to build sections in Foundation 4, with our predefined HTML classes or with our structure and mixins. Building a sections using our predefined classes is super-easy, you just need to create a <div class="section-container" data-section>
as a wrapper for the sections themselves. Inside of this wrapper, you'll create either a <section class="section">
or <div class="section">
. Within that you'll include some sort of .title
(this can be headers or a paragraph) and a <div class="content">
. Here is the markup you'll need:
If you want to use ZURB's default styles for section elements you can apply the auto
, tabs
, accordion
, vertical-nav
, or horizontal-nav
classes. By default, section elements will be an accordion on mobile and tabs on desktops and tablets. If you want to adjust this behavior and force a particular format for your section, you will need to set data-section
equal to the format you want to force as shown in the variations below.
This example will automatically switch between tabs and accordion based on the resolution of the device.
The class options:
For these styles to come across, make sure you have the default Foundation CSS package or that you've selected section from a custom package. These should be linked up following our default HTML page structure.
Adding an accordion
class to the section container will show an accordion on both small and large screens.
Adding a tabs
class to the section container will enable tabs on both small and large screens.
Adding a vertical-tabs
class to the section container and setting data-section="vertical-tabs"
will enable tabs on both small and large screens.
Adding a vertical-nav
class to the section container will enable vertical navigation elements on large screens and show an accordion on small screens.
Vertical navigation elements usually appear within the grid so the width can be controlled on desktop.
Use the side-nav
class on the list to apply the Foundation navigation styles
Content to the right of the navigation.
Content to the right of the navigation.
Adding a horizontal-nav
class to the section container will enable horizontal navigation elements on large screens and show an accordion on small screens.
Horizontal navigation is a combination of the tab setting with vertical navigation drop downs.
Use the side-nav
class on the list to apply the Foundation navigation styles
Set deep-linking
to true to enable deep linking to sections of content. Deep linking allows visitors to visit a predefined URL with a hash that points to a particular section of the content. Deep linking also requires a matching data-slug
on the content section that the hash should point to, without the pound (#) sign.
You can infinitely nest Section elements to create more complicated Section layouts.
Content 1 Summary Paragraphs
Detail awesome stuff!
Detail awesome stuff numeroe duo.
Content 2
Content 1 Summary Paragraphs
Detail awesome stuff!
Detail awesome stuff numeroe duo.
Content 2
Note: The section
element can be replaced with a div.section
element if you do not want to use HTML5 elements.
If you are keen on SCSS and use it for your Foundation projects, you have access to mixins that will let you create any type of section you want and change it within a media query too! Building a section with our mixins requires a bit of predefined structure, but you can choose the classes or ID's to style them with. Start with some sort of block-level container, we use a <div>
. This container needs to have data-section="type-of-section"
. The section types are explained above. Inside this you create "sections", which can be an HTML5 section
element or a <div class="section">
, that will hold content.
Inside of these "sections" you created you'll need to add a title and content. To create the title element, use something like a <p>
, <h5>
, etc and give it an attribute of data-section-title
. After this, you add <div data-section-content>
and fill it with your content.
Here's an example structure you might use with the section mixin:
<%= code_example ' ', :html %>Here's a look at the available options for the mixins you need to create sections:
<%= code_example ' @include section-container($base-style, $section-type) { ... } /* Container Options */ /* This controls whether or not you include default styles when chaining classes, set to true or false */ $base-style: true /* This controls the style for the section you are using: accordion, tabs, vertical-tabs, vertical-nav, horizontal-nav */ $section-type: accordion @include section($section-type, $title-selector, $content-selector, $title-padding, $title-color, $title-font-size, $title-bg, $title-bg-hover, $title-bg-active, $title-color-active, $content-bg, $content-padding, $section-border-size, $section-border-style, $section-border-color) { ... } /* Section Options */ /* Control which section type styles come across: accordion, tabs, vertical-tabs, vertical-nav, horizontal-nav */ $section-type: accordion /* You can set the class that is used for the title elements */ $title-selector: ".title" /* You can set the class that is used for the content elements */ $content-selector: ".content" /* Give the titles some padding, can be any px or emCalc() value */ $title-padding: $section-padding /* give the titles a color, any color value */ $title-color: $section-title-color /* Set the font size for titles */ $title-font-size: $section-font-size /* Set the background color for titles */ $title-bg: $section-title-bg /* Change title background for hover */ $title-bg-hover: $section-title-bg-hover /* Change title background for .active */ $title-bg-active: $section-title-bg-active /* Change title color for .active */ $title-color-active: $section-title-color /* Content area background color */ $content-bg: $section-content-bg /* Content area padding */ $content-padding: $section-content-padding /* Border size in pixels */ $section-border-size: $section-border-size /* Border style */ $section-border-style: $section-border-style /* Border color */ $section-border-color: $section-border-color', :css %>The default use case for our section plugin is to create accordions on small screens and tabs on large screens.
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample { @include section-container($section-type:accordion); & > section { @include section($section-type:accordion, $title-selector:".title-sample", $content-selector:".content-sample"); } @media #{$small} { @include section-container(false,$section-type:tabs); & > section { @include section($section-type:tabs, $title-selector:".title-sample", $content-selector:".content-sample"); } } }', :css %>You can have your section act like an accordion the entire time, like so:
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample-accordion { @include section-container($section-type:accordion); & > section { @include section($section-type:accordion, $title-selector:".title-sample", $content-selector:".content-sample"); } }', :css %>You can have your section act like tabs the entire time, like so:
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample-tabs { @include section-container($section-type:tabs); & > section { @include section($section-type:tabs, $title-selector:".title-sample", $content-selector:".content-sample"); } }', :css %>You can have your section act like vertical tabs on large screen and go back to accordion on small screens, like so:
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample-vtabs { @include section-container($section-type:accordion); & > section { @include section($section-type:accordion, $title-selector:".title-sample", $content-selector:".content-sample"); } } @media #{$small} { .section-auto-sample-vtabs { @include section-container($section-type:vertical-tabs); & > section { @include section($section-type:vertical-tabs, $title-selector:".title-sample", $content-selector:".content-sample"); } } }', :css %>You can have your section act like vertical navigation the entire time, like so:
<%= code_example ' ', :html %> <%= code_example ' .nav-container { @include grid-row($behavior:nest); > nav { @include grid-column($columns:4); } } .section-auto-sample-vnav { @include section-container($section-type:accordion); & > section { @include section($section-type:accordion, $title-selector:".title-sample", $content-selector:".content-sample"); } } @media #{$small} { .section-auto-sample-vnav { @include section-container($section-type:vertical-nav); & > section { @include section($section-type:vertical-nav, $title-selector:".title-sample", $content-selector:".content-sample"); } } }', :css %>You can have your section act like horizontal navigation the entire time, like so:
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample-hnav { @include section-container($section-type:accordion); & > section { @include section($section-type:accordion, $title-selector:".title-sample", $content-selector:".content-sample"); } } @media #{$small} { .section-auto-sample-hnav { @include section-container($section-type:horizontal-nav); & > section { @include section($section-type:horizontal-nav, $title-selector:".title-sample", $content-selector:".content-sample"); } } }', :css %>You have access to a few options that will make styling the sections really easy and you can add onto it as you want. You'll still need the data-section attribute to match the style you give the mixin.
<%= code_example ' ', :html %> <%= code_example ' .section-auto-sample-custom { @include section-container($section-type:tabs); & > section { @include section($section-type:tabs, $title-selector:".title-sample", $content-selector:".content-sample", $title-padding: 10px 50px, $title-color:#000, $title-bg:pink, $title-bg-hover:darken(pink,5%), $title-bg-active: #fff, $title-color-active: darken(pink,10%)); } }', :css %>Note: emCalc();
is a function we wrote to convert px
to em
.
You'll need to include zepto.js
and foundation.js
above the sections plugin. Above your closing </body>
tag include the following line of code and make sure you have the JS in your directory.
Read how to install Foundation JavaScript
Required Foundation Library: foundation.section.js
Then, you'll need to add a data-attribute to make the JS work properly on that element. That looks like:
<%= code_example ' ', :html %>Note: If you are using Sections in a Modal, or they are being loaded via AJAX, or they are hidden when Foundation is initialized, you will need to reflow the sections to get tabs to display properly:
<%= code_example " $('#myModal').on('opened', function () { $(this).foundation('section', 'reflow'); }); ", :json %>You can either set these options in a data-options
attribute in the markup, data-options="option: value; option2: value syntax"
, or pass in on initialization.