SCSS mixins in Zurb Foundation 4 designed for creating small and large columns that are fluid and responsive

Currently in the process of developing a responsive website for my company, I am utilizing SASS and Foundation 4 CSS Framework for the first time. Progress has been smooth thus far. However, I have encountered an issue related to mixins.

 class="large-6 small-3 columns"

When attempting to create a column that is size 6 in large views and size 3 in small views using the built-in CSS classes, I realized that it may be more efficient to achieve this through a Foundation SASS mixin. The only column-related mixin I came across can be found here:

@include grid-column($columns, $last-column, $center, $offset, $push, $pull, $collapse, $float);

Upon closer inspection, it seems that viewports cannot be specified within this particular mixin.

I would greatly appreciate any insights or suggestions on how to address this matter. Thank you in advance.

Answer №1

I have created some useful mixins to simplify the process:

Check out the code on GitHub here
@mixin rgrid($phone-grid:"",$desktop-grid:""){
    @extend .small-#{$phone-grid};
    @extend .large-#{$desktop-grid};
    @extend .columns;
}

This mixin makes it easy to utilize F4 grid classes and media queries.

  • $phone-grid: indicates the number of grid columns for mobile devices.

  • $desktop-grid: specifies the number of grid columns for desktops, overriding $phone-grid when the window width is 768px or higher.

  • Only one parameter should be defined to set a value for all window widths.

For example:

@include rgrid(3,6); => 3 columns for phone, 6 columns for desktop.
@include rgrid(6); => 6 columns.

Answer №2

One way to achieve this is by using the @extend feature with a Foundation class instead of using @include with a Foundation mixin. This allows you to leverage all the functionalities that Foundation offers in their grid classes, while also being able to layer them on top of each other.

You can define the desired classes in your CSS like so:

.my-super-semantic-div {
    @extend .large-6, .small-3, .columns;
}

Rather than in the HTML markup:

<div class="large-6 small-3 columns">...</div>

Answer №3

I was curious if there is an integrated SASS mixin available for this particular task. If not, I plan to explore their @media settings and implement it on my own.

Unfortunately, it seems they do not have a built-in solution. :( For further information, you can refer to the documentation:

However, there's no need to create something from scratch! You can simply utilize the convenient respond-to Compass extension by Snugug.

In addition to using media queries by names as explained in respond-to's readme, you also have the option to trigger them based on their designated numbers.

For instance, take a look at this example with a clean indented syntax:

// Defining the breakpoint ranges
$breakpoints: 'xs' (0 400px), 's' (401px 600px), 'm' (601px 800px)

// Creating a function to access a breakpoint by number
@function bp($number)
  @return nth(nth($breakpoints, $number),1)

// Using a media query conventionally by its name
.bar
  +respond-to('s')
    @include grid-column(6)

// Implementing a media query by its assigned number
.foo
  +respond-to(bp(2))
    @include grid-column(6)

Hooray!

Answer №4

It is essential to employ semantic classes for these purposes.

class="meaningful-description"

You can also utilize various mixins in your SASS code for handling different sizes, such as:

.meaningful-description {
    @include grid-column(3)
}

@media screen and (min-width: 700px) {
    .meaningful-description {
        @include grid-column(6)
    }
}

Answer №5

When working with Sass Mixins, it is necessary to utilize media queries in order to explicitly adjust the grid layout. My approach involves creating a Mobile First website and then duplicating the Sass code defining the grid into two separate media queries:

// Mobile Grid
@media only screen and (max-width: 768px) { ... }
// Desktop & Tablet Grid
@media #{$small} { ... }

Despite my efforts, I struggled to find clear examples illustrating this process. While it is theoretically possible to define the grid in Sass and override it using the @media #{$small} {} media query, I encountered difficulties making it work in practice. Regardless of whether I placed the media query before or after the original grid declaration, the initial grid configuration persisted.

For a more detailed example, consider the case of the #dashboard element stacking and centering on mobile devices, while displaying as a 3-column layout on desktops and tablets. This would translate to

class="small-10 small-centered large-4 columns"
when using presentational classes.

// Mobile Grid
@media only screen and (max-width: 768px) {
  #dashboard { @include grid-row;
    & > #stats { @include grid-column(10, false, true); }
    & > #records { @include grid-column(10, false, true); }
    & > #results { @include grid-column(10, false, true); }
  }
}

// Desktop & Tablet Grid
@media #{$small} {
  #dashboard { @include grid-row;
    & > #stats { @include grid-column(4, false, false); }
    & > #records { @include grid-column(4, false, false); }
    & > #results { @include grid-column(4, false, false); }
  }
}

Please remember that you can further customize this approach by incorporating additional breakpoints using mixins. However, the provided method closely mirrors the default Zurb F4 presentational class behavior.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to asynchronously load image src URLs in Vue.js?

Why is the image URL printing in console but not rendering to src attribute? Is there a way to achieve this using async and await in Vue.js? <div v-for="(data, key) in imgURL" :key="key"> <img :src= "fetchImage(data)" /> </div> The i ...

Having trouble retrieving a particular element using xpath in selenium with Python

Currently, I am working on extracting wind direction information using selenium and I have found that using xpath is the most straightforward approach to retrieve this data. There is a table containing all the necessary details, and the structure of the el ...

CSS tooltip within the document styling

Previously, I utilized the following code: I am seeking guidance on how to position the tooltip inline (to the right) with the parent div instead of above. Thank you for reviewing For a more user-friendly version, refer to this jsFiddle link HTML: < ...

Unable to generate webpage source code

Having some trouble with my Next.js project as I'm using getStaticProps and getStaticPath to build a page, but unfortunately, the HTML is not being generated in the page source. This issue is causing problems with SEO, and I haven't implemented r ...

D3: Ensuring Map is Scaled Correctly and Oriented Correctly

I am attempting to integrate a map into a website using D3 and topoJSON that resembles the following: https://i.sstatic.net/1brVx.png However, when I create the map with D3/topoJSON, it shows up small and inverted. https://i.sstatic.net/LgQBd.png Even ...

Navigational assistance on the keyboard - Improving Accessibility

My situation involves selecting an option from a dropdown menu on X-page, which triggers the opening of Modal-1 while disabling the background. If a selection is made within Modal-1, it leads to Modal-2. I am facing two issues/questions: Upon opening Moda ...

The website showcases mobile responsiveness; however, it does not translate to mobile devices

Hello Stockoverflow Community, Recently, I encountered an issue with the responsiveness of my website: The design on desktop appears as: [deleted] However, the mobile version displays as: [deleted] I have already tried clearing my cache, both on Cloudf ...

What is the step-by-step process for executing the following functions: 1. magnify -> 2. spin 360 degrees -> 3. restore to original size before magnification -> 4. switch colors on and

Can you show me a demo featuring the following functions in order: 1. enlarge -> 2. rotate 360 degrees -> 3. resize to original size -> 4. change color (toggle) $(document).ready(function() { $('.tlist td div').click(function() { ...

Creating a div that takes up 100% of its parent's height, regardless of the children's dimensions, in a sophisticated layout

My webpage layout is structured as follows: https://i.sstatic.net/5rdiw.png The left side, identified as D, functions perfectly. It contains a significant amount of content that scrolls correctly. Even as the content increases, the height stays at 100% o ...

CSS not reflecting changes after the href of the <link> tag has been updated

Hey there, I'm a beginner in the world of programming and currently facing an issue that I need help with. My goal is to dynamically update the CSS of my webpage by using JQuery to change the 'href' value in the link tag. In order to test t ...

How can I float a square to the right in Bootstrap with a col-md-4 size but with a height restricted to only 200 px

Looking to add a small square on the page for users to search and purchase courses directly. The square should be 4 columns wide, follow Bootstrap4 grid template, and be around 200-300 px in length. It needs to remain visible as the user scrolls down the p ...

Creating an Android game with the utilization of HTML5 and Javascript involves the adaptation of images to various screen resolutions

Currently, I am working on creating a basic game for android devices by utilizing HTML5, javascript, and cordova for wrapping it up. One of the key features of my game will involve using an image as a background and animating it to create a dynamic visua ...

Adjust the appearance of an element in a different parent when hovering over a specific element with a matching index

I have implemented a menu on my site in two different ways - one using text and the other using pictures. Users can click on both types of menus. Now, I am looking to create an interactive feature where hovering over a specific item in the text menu (such ...

Capturing Vuejs data for various pathways

Currently, I am developing a Vue file that contains the following code: <router-link :to="{name: 'detailed'}" tag='li' @click='getData("test")'> testing</router-link> In the script section, the code looks like th ...

Bootstrap 4 offers a full-height, full-width layout that is optimized for Chrome, but may not display as well on Firefox or

My current project has a basic prototype that functions fine in Chrome, but encounters issues in Firefox and IE11. I am utilizing 'container-fluid' for full-width, 'h-100' for full-height, and 'overflow-y' to enable vertical s ...

Investigate the dynamic form validation using jQuery

I have set up an input field using jQuery. When the button "add a step" is clicked, jQuery will generate the following structure in the div all_steps: <div class="step"> <div class="header_step">Step '+ (x + 1) +' of the Tutoria ...

Tips for swapping out text with a hyperlink using JavaScript

I need to create hyperlinks for certain words in my posts. I found a code snippet that does this: document.body.innerHTML = document.body.innerHTML.replace('Ronaldo', '<a href="www.ronaldo.com">Ronaldo</a>'); Whil ...

I'm attempting to render HTML emails in ReactJS

I have been attempting to display an HTML page in React JS, but I am not achieving the same appearance. Here is the code snippet I used in React JS: <div dangerouslySetInnerHTML={{ __html: data }}/> When executed in regular HTML, the page looks lik ...

Tips for transferring an array between pug mixins?

My pug template features an array that I want to transfer to a mixin in order to populate JSON schema.org markup. Below is the code: profile.pug include ../components/bio-seo - var person = {} - person.title = "Name, title of person" - person.url = "ht ...

How can I implement a loop to showcase bootstrap popover content?

I'm having issues with my popover content always displaying the first item in the list. How can I make it display each individual item? Below is the snippet of Razor HTML code I am using: @{ foreach(item in Model.SomeObject) { <div clas ...