Arrange SASS files in your application by incorporating Bootstrap

Recently, I've embarked on the journey of working on a complex styling project for a large application. Knowing that Bootstrap 4 offers SASS files, I made the decision to align with that framework.

To streamline my workflow, I established the following file structure:

  • theme.scss: encompasses overarching theme definitions such as colors and fonts. While there is currently only one file, potential for more exists in the future.
  • global.scss: serves as the hub for Bootstrap integration, along with custom overrides and application components - for example, a field intertwined with its label forming part of the top border.
  • site.scss: houses general application styles.
  • Various page-specific SCSS files, including ones like login.scss.

The challenge I'm currently facing revolves around global.scss importing Bootstrap, which is then further imported by site.scss as well as other files such as page-specific SCSS files. Consequently, Bootstrap styles duplicate across multiple compiled CSS files, the references used within the application.

In past encounters with LESS, I could address this issue using @import (reference) "bootstrap" rather than plain @import "bootstrap". However, in the realm of SASS, no apparent solution presents itself without altering Bootstrap core files.

Are there alternative suggestions for organizing these files effectively while mitigating this complication? Are there nuances I may have overlooked or missteps I am making?

Shown here are condensed snippets from the relevant files to showcase the predicament at hand:

theme.scss

$my-primary-color: #04459a;

global.scss

@import "../theme.scss";
$primary: $my-primary-color;
@import "../../third-party/bootstrap/scss/bootstrap.scss";
%field{
    // [...]
}

site.scss

@import "global.scss";
div.field {
    @extend %field;
}
// [...]

login.scss (or similar)

@import "global.scss";
// [...]

Within the application setup, both site.css and login.css (specifically on the login page) are referenced, each inadvertently incorporating Bootstrap styles.

Answer №1

I have developed a solution that suits my needs, although I am uncertain if it is the optimal choice or what limitations it may have.

I drew inspiration from an article titled My favored SCSS setup with Bootstrap 4. Here is an overview of what I created:

  • Initially, I divided Bootstrap into two SASS files for easier importing (similar to the approach taken in the referenced article with bootstrap/_config.scss):

bootstrap/_sass-componentes.scss

@import "../../terceros/bootstrap/scss/_functions.scss";
@import "../../terceros/bootstrap/scss/_variables";
@import "../../terceros/bootstrap/scss/_mixins";

bootstrap/_config.scss

@import "_sass-componentes.scss";
// Additional bootstrap files to include:
@import "../../terceros/bootstrap/scss/_root";
@import "../../terceros/bootstrap/scss/_reboot";
@import "../../terceros/bootstrap/scss/_type";
// [...]
@import "../../terceros/bootstrap/scss/_utilities";
@import "../../terceros/bootstrap/scss/_print";
  • Next, in global.scss, I modified the import line for bootstrap.scss to only import bootstrap/_sass-componentes.scss
  • Lastly, in site.scss, I included global.scss as before and then imported the full set of Bootstrap files through bootstrap/_config.scss.

Furthermore, after importing _config.scss, I integrated my custom Bootstrap modifications. These were implemented following the suggestions in the provided article, even though they do not directly relate to my initial inquiry.

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

Issues with navigation drawer not functioning

function adjustMenu() { var navigation = document.getElementById("myTopnav"); if (navigation.className === "topnav") { navigation.className += " responsive"; } else { navigation.className = "topnav"; } } body {margin:0;} ul ...

Achieving equal height divs using Bootstrap

I have a row of 8 divs arranged horizontally, and I am looking to make them all the same height. Right now, their heights vary based on the content inside each one. Can someone offer some assistance? I've attempted multiple solutions without success s ...

Repeating linear gradients in the background

After creating a linear-gradient background animation in CSS for my to-do list, I encountered an issue. As I added more items to the list, the website became scrollable and the background started repeating, which made it look unappealing. I attempted to s ...

Guide to Utilizing Roboto Light/Thin Font from Google Fonts on Chrome

I'm struggling with using the Roboto fonts in Chrome, specifically with getting Condensed and Thin/Light font weights. I have downloaded all three complete fonts: @import url(https://fonts.googleapis.com/css?family=Roboto:100,100italic,300,300italic, ...

Why is my Tailwind Grid displaying elements in a horizontal layout?

<div className='grid grid-cols-12 gap-12 mb-8'> <div className='col-span-8'> <div className='box'></div> </div> <div className='col-span-4'> <d ...

"Resolving the Problem of a CSS Width Setting at 100

Encountering difficulties when using 100% in the container CSS. Referencing the attached image, you can see the RED background color displayed on the right side image. Below is the link to my CSS code on jsfiddle. Please review it and advise on the modifi ...

Move a button using jQueryUI

HTML code resides below <!doctype html> <html> <head> <title>jQuery UI: Alphabet Matcher</title> <link href="css/normalize.css" rel="stylesheet"> <link href="matchalphabate.css" rel="styl ...

The screen size dominates all the other specifications

I've been attempting to adjust the category images based on screen size, but it seems that only the first specified width is being applied. It appears that subsequent rows of code are being overridden by the initial max-width setting (769px) on this w ...

Picture with bordered corners - area underneath the image

Looking to create an image with borders in opposite corners, using ::after and ::before. Almost there - but the image isn't covering the whole space in the div. There is some weird empty space below the image (marked red in the jsfiddle). I'm stu ...

In which location are HTML files stored within WordPress plugins?

Can someone help me locate the HTML files within WordPress plugins? I'm looking to make edits to the HTML and CSS files of a plugin, but I can't seem to find the specific HTML file. Any guidance on where these files are stored would be greatly ap ...

Clickable button functionality problems in Outlook email responses

Is there a way to create a button that is fully clickable (not just the text), aligned to the left on desktop and full width on mobile, while also being compatible with Outlook? I've experimented with various types of buttons like bulletproof, bombpro ...

IE - Adjusting the Width of the Vertical Spry Menu Bar

As I delve into the world of web design using Dreamweaver, I find myself faced with some challenges as a beginner. One specific issue I'm encountering is related to a vertical Spry Menu Bar on my website that functions well in most browsers except for ...

Certain parts of the CSS grid are not aligning properly within the grid lines

I'm having trouble with my CSS grid. The red section fits in the first square, but the rest of the content seems to be out of place in the grid. I'm new to all this and I can't figure out what I'm missing. I've tried everything but ...

Using JavaFX to showcase FontAwesome icons

I've been working on a project to create a custom icon class that can load FontAwesome icons, but I'm facing issues with reading the fontawesome-webfont.ttf file. Here is the code for creating an icon: import javafx.scene.control.Label; import ...

`The Safari browser showing glitches with CSS animations`

Despite using both the -webkit-animation and animation, my animation does not work in Safari, only in Chrome and Firefox. The CSS code I have utilized is displayed below: .bar{ height: 30px; max-width: 800px; margin: 0 auto 10px auto; line-height: ...

Ways to troubleshoot an unusual margin issue in a static column of an HTML table

I have been exploring various resources to create an HTML table with a fixed first column using CSS only. Despite my efforts, the fixed column is consistently appearing lower than the rest of the content, and I'm unsure why. Check out the code I&apos ...

Changing the text color of an active button in Bootstrap

Hello everyone, I've been struggling to find a solution to my issue and I could really use some help. The problem I'm facing is changing the text color of the active button in Bootstrap. Specifically, after clicking on a button, I want it to tra ...

Drop-down and autocomplete feature in Material UI design framework

Encountering an issue with aligning a label with a dropdown in material UI, and for some reason, this behavior is observed: https://i.sstatic.net/n7pj8.png Struggling to get them aligned on the same row. This is the code snippet of my component: const us ...

Modify the arrow design for the expansion panel's default arrow style

Looking to customize the design of an angular expansion panel? Check out the images below for inspiration: Before Customization: https://i.sstatic.net/4u6NS.png After Customization (Not expanded): https://i.sstatic.net/8N6Br.png After Customization (E ...

CSS animation fails to execute

I created a rotating carousel using CSS. The carousel is constructed using the 'ul' tag. To navigate left or right, I dynamically add a 'li' element to the left or right of the list by cloning the necessary value and appending/prependin ...