Using Sass to create unique breakpoints for media queries based on the body class

I am currently in the process of creating a series of web pages that will be accessed from various websites, each with its unique content template. Even though these pages are very similar, they require different media query breakpoints based on the specific site they are served from.

It would be ideal to allow each site to customize the page by adding their site name as a class to the body container, ensuring that the appropriate breakpoints are applied for that particular site.

I have experimented with several methods using mixins and more, but so far, I have not been successful in achieving the desired outcome.

Currently, I have defined my breakpoints mixin in the abstracts/_mixins.scss file:

@mixin breakpoint ($breakpoint) {

    @if $breakpoint ==small {
        @media screen and (min-height: $xsmall) and (min-width: $xsmall-width) {
            @content
        }
    }

    @if $breakpoint ==medium {
        @media screen and (min-height: $small) and (min-width: $small-width) {
            @content
        }
    }
...

I apply these breakpoints using @include breakpoints(small){}

If there is a more efficient way to achieve this without relying on setting the parent container class, I am open to exploring alternatives. My goal is to avoid having separate stylesheets for each site to ensure easier maintenance.

Answer №1

It's not a definite answer, but have you considered presenting the information in this way?

@use 'data' as d; 
// You can access data from the partial file using d
// Make sure the partial file is named _data.scss
@mixin custom-style (d.$style) {

    @if d.$style == d.$basic {
        @media screen and (min-height: d.$small) and (min-width: d.$small-width) {
            @content
        }
    }

    @if $style == d.$specified {
        @media screen and (min-height: d.$medium) and (min-width: d.$medium-width) {
            @content
        }
    }

It's not a guaranteed solution, but perhaps something along these lines could be effective.

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

I recently created a Python3 script utilizing selenium to automate message sending, but unfortunately, it is not functioning as expected

I've written a script (https://pastebin.com/dWLFvirn) that I'm trying to run through the terminal, but it's giving me an error. Here's a screenshot of the error (https://ibb.co/NSfLgL8). I would like to use "" as the link to make the s ...

Square Power Box

I have been attempting to create two equal sections, one displaying an image and the other showing text, both maintaining a square shape with identical width and height. I am using the Avada theme on Wordpress along with Element Builder and custom CSS to a ...

I'm puzzled as to why my media query for `max-width: 470px` isn't functioning correctly

I'm struggling to get my code to work properly. I've tried adjusting some parts to be more specific and others more general, but it's not functioning as expected. Please review my code and any advice or assistance would be greatly appreciat ...

Ways to retrieve HTML tags from a website's DOM and shadowDOM

I am currently working on a project using NodeJS where I need to extract the HTML structure of multiple websites. However, I am facing some challenges with this task. My goal is to retrieve only the HTML structure of the document without any content. It is ...

CSS styles are not being displayed on elements that have been dynamically added using jQuery

I have searched through similar questions, but none of them addressed my issue. (they all seemed to be related to typos) This is just for fun. I am trying to create a table using jQuery based on JSON data. The problem is that the appended table rows do no ...

Finding a Div ID with Python and Selenium

Currently, I am facing an issue where I have to interact with an image of a dropdown arrow in order to select an item that will automatically fill the input box. Both the dropdown arrow and input box are components within the dev id:decision. I require ass ...

Is there a way to switch out the navigation icons on the react-material-ui datepicker?

Can the navigation icons on the react-material-ui datepicker be customized? I've attempted various solutions without any success. <button class="MuiButtonBase-root MuiIconButton-root MuiPickersCalendarHeader-iconButton" tabindex="0&q ...

Utilizing Javascript to Call a .NET Web Service with HTML5 (Using HTTP POST)

I need assistance with this issue regarding my use of HTML5 on my website along with a .NET Service (.asmx). I have a method called getText() that returns a string of text. How can I properly call this method and display it on my HTML5 webpage? Here is th ...

PHP array is not displaying properly in two dimensions

Looking at the array of dates and places, I need to figure out how to properly format this information for display. Here is an example of what I am trying to achieve: 20140411 Basingstoke Salisbury 20140405 Basingstoke 20140419 Salisbury ...and ...

Angular material chips showcase a row of five chips

I am working with the basic mat-chips from angular material and I want to arrange them in rows of five without increasing their size: Chip1 Chip2 Chip3 Chip4 Chip5 ..................(space left) Chip6 Chip7 Chip8 Chip9 Chip10 ...............(space le ...

What is the best way to include a validation process for Login Details in case of errors

Is it possible to implement Login Details confirmation for incorrect entries? My desired outcome is that when a user enters their credentials and the userID and Password are correct, but the user type is wrong, upon clicking the login button it should di ...

Unleash the power of WordPress Revolution Slider captions with exclusive CSS styling

Struggling with adding custom captions? I'm using a Multisite WordPress setup and trying to avoid editing the captions.css file in the plugins folder. Here's what I attempted: .rev_slider .tp-caption .my_head{ position: absolute; ...

Issue with AngularJS: Not able to get second app in template to function properly

I have encountered a puzzling issue with my two nearly identical apps. The first one seems to be running smoothly as expected, while the second one doesn't appear to be executing at all. Here is my code (jsfiddle): <div ng-app="passwdtool" ng-con ...

I am creating an HTML page that incorporates p5.js, and the text I'm rendering

It seems like the draw loop is continuously refreshing every x seconds, causing this behavior. Is there a way to slow down or disable the frame update without affecting the video refresh rate? I was thinking of adding an fps counter and implementing an i ...

Integrating ASPX with HTML pages to create a seamless and dynamic user experience

I've recently created a responsive website for our qualifications-based company. We have a third-party team working on updating course pages and database within ASPX. They claim that ASPX pages cannot be made responsive and take up full width across t ...

Styling and theming in PrimeNG

Seeking advice on how to customize the appearance of the background for the primeNG panel component. I attempted to override the styling using the specific names in my scss file for the component, but it did not work. I also tried inline with <p-panel ...

Tips for passing parameters in the $http GET request to transmit information from a dropdown menu using AngularJS

In the modal window I have for creating a new object, there are three forms: 1) a simple input to create "Name"; 2) A dropdown with "Types"; 3) A dropdown with "Ids". The issue arises when trying to send the data after filling out all the forms. An error o ...

When the browser width decreases, the layout's rows become wider

Here is the code snippet I'm using: <style> a.item { border:1px solid #aaa; background:#ddd; padding:10px; ...

Guide on moving to the following page of a website with the help of CSS selectors

I'm currently in the process of retrieving property details from a specific website (Find Properties For Sale). Initially, I successfully scraped the information from the initial page. However, upon attempting to gather data from subsequent pages, my ...

What is the most effective approach for updating a CSS file to a newer version?

Whenever I make changes to the CSS, I typically update the version of the CSS file in the master. This requires me to upload both the CSS and master files. Is there a way to change the CSS version without having to upload the master file? <link rel="st ...