Adjust the font sizes in Bootstrap4 to be in proportion with the Scss $font-size-base

I am currently customizing Bootstrap4 and facing challenges in understanding why certain elements are not functioning as anticipated.

When modifying the original _variables.scss file by adjusting the $font-size-base, ideally, it should reflect across related variables to prevent manual updates on multiple instances (e.g.

$h1-font-size: $font-size-base * 2.5
). This approach ensures that future updates from "node_modules > bootstrap" do not disrupt the customized settings.

To address this issue, I created a new file called _custom-variable.scss where I imported the necessary variables:

@import '../node_modules/bootstrap/scss/variables';

After changing $font-size-base: 1rem to $font-size-base: 0.875rem;, the compiled CSS for the body displays the correct font size adjustment:

// ../node_modules/bootstrap/scss/_reboot.scss
body {
  ...
  font-size: $font-size-base;
  ...
}

// Compiled CSS
body {
  ...
  font-size: 0.875rem;
  ...
}

However, the problem arises when targeting heading tags:

// Although I updated $font-size-base in my _custom-variable.scss file from 1rem to 0.875 
// The expected changes for heading tags should be:
h1 { font-size: 2.1875rem }
h2 { font-size: 1.75rem }
...
h6 { font-size: .875rem }

// But the actual output remains unchanged
h1 { font-size: 2.5rem }
h2 { font-size: 2rem }
...
h6 { font-size: 1rem }

This discrepancy could be due to the calculation process specified within the Bootstrap's _vairables.scss file:

//../node_modules/bootstrap/scss/_variables.scss
$h1-font-size: $font-size-base * 2.5 !default;
$h2-font-size: $font-size-base * 2 !default;
...
$h6-font-size: $font-size-base !default;

Answer №1

When updating the $font-size-base variable in your _custom-variable.scss, make sure to also update the $h1-font-size, $h2-font-size, and other related variables within the same file.

The sizes for headings are initially set in the _variables.scss file, where the value of $font-size-base remains unchanged. A scss variable retains its original value unless explicitly modified.

Alternatively, you could consider making adjustments directly within the original _variables.scss file, possibly by documenting the default values in a comment section.

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

Struggling to implement a Rock Paper Scissors game using HTML, CSS Bootstrap4, and JavaScript, specifically facing challenges in getting the function to select a new image

Recently, in my coding class, we were tasked with creating a program that would display images of dice and generate random numbers when the refresh button was clicked. To practice using querySelector and setAttribute, I decided to expand on the lesson by i ...

What could be causing my transform scale to not function properly in Bootstrap?

As a complete beginner, I am currently in the process of learning bootstrap. I have noticed that the animation breaks when I apply it, specifically the scaling part. Interestingly, the animation works perfectly fine without Bootstrap. I am wondering if the ...

The background image positioned in the center may experience cropping in HTML

I am currently facing an issue with aligning a background image horizontally in a specific scenario: The background image is large and needs to be centered horizontally The page has a minimum width requirement of 960px which may result in a scrollbar on ...

Annoying div unexpectedly wrapping content after using appendTo

Greetings, esteemed members of the SO community, I am here once again with a question that requires your assistance. Context: I am currently working on a grid system that allows users to drag and drop items onto specific grid fields. When the grid is re ...

Issues with HTML formatting after using JQuery .load()

Hey there StackOverflow community! I've encountered a problem that I need help with. Whenever I use the following code: $("#specificDIV").load("new.html") The HTML content loads into the div, but the CSS and JS don't work properly. The formatt ...

Issue with alignment of divs causing them to stack in a strange manner instead of floating left and

Check it out in action right here: All I want is for the .news div boxes to gracefully float left and right using the handy cycle helper in Rails. However, the current output isn't quite what I had in mind: This is how I envision the layout should l ...

Exploring the interaction between Bootstrap and AngularJS in creating unique menu functionality

UPDATE: added JSFiddle link I am currently working on creating a dynamic menu or set of options that will be populated based on server requests. The data structure I am dealing with is as follows (some unnecessary data has been omitted): { "name" : ...

Adjusting the image placement within a modal window (using bootstrap 3)

Behold, an example modal: <!-- Large Modal --> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

What is the right way to nest a SCSS rule for a specific selector within a list using the "&" symbol?

I have a question that I couldn't find the answer to in any documentation or on Stack Overflow. While this example may not be perfect, it should give you a basic understanding of what I'm trying to achieve. Illustration .btn-group { .btn ...

Trick for hiding CSS elements when input field is vacant

Is there a way to hide the search result when the input is empty? While everything is functioning correctly, I would like to prevent the search result from remaining visible after clearing the input field. For example, if you type 'A' and then d ...

Starting on the Legacy 1.2.0.RC4 TideSDK: Where to Begin?

I just acquired the legacy version 1.2.0.RC4 from the official website. Now that I have it downloaded, what are the next steps? How can I begin using it? ...

Customizing Material-UI Grid: Is it possible to assign a background color solely to the cells, without affecting the surrounding empty spaces?

I've been experimenting with designing a grid system that incorporates a gradient background color. The issue I'm facing is that the background color extends to the empty spaces between the grid cells as well. Is there a way to scope the gradient ...

Adjust the playlist based on the spinning motion using jQuery

Can I restrict playing French music only when the "world" angle is between 0 degrees and 27 degrees? The world rotates based on scrolling. Thank you, everyone :) $(document).ready(function() { var angle, scroll = 0; var $world = $('#world'); var ...

Illuminate the current page

I have been working on a website with around 20 pages that all have a side navigation bar. To make it easier to manage, I decided to centralize the links in a JavaScript (JS) file and include it on each HTML page. This way, any changes can be made quickly ...

Achieving text center alignment and adding color to text within a header using Bootstrap

I am looking to center the text in a header and apply color to it using Bootstrap. Unfortunately, there is no direct option for font-color or text-color in Bootstrap. Below is my HTML and CSS code: #header { width: 800px; height: 50px; color :whi ...

How can I customize the appearance of a specific tagged page on my Tumblr blog?

Although I have a solid grasp of HTML & CSS, I am encountering some difficulties with the Tag Page feature on Tumblr. Specifically, I want to change the heading displayed on the /tagged/vld tag page without altering the URL. Currently, the heading is gener ...

Start the CSS3 animation in reverse right away

I am trying to achieve a "flashing" effect by adding the .shown class to my #overlay, causing the opacity to fade in for 2 seconds and then immediately reverse, fading out for another 2 seconds. After experimenting with removing the class, I found that it ...

What is the most common method for creating a dropdown menu for a website's navigation?

Is there a common approach to creating an interactive drop-down navigation menu in the industry? I have searched on Google and found multiple methods, but as a student working on my first big web project, I am hoping to find a standard practice. I don&apo ...

implementing smooth scrolling using jquery following object insertion

I have a Ruby on Rails application with Bootstrap styling. Recently, I updated an object and reinserted it into the page. Now, I want to scroll to the top of a specific div with a smooth animation since I'm ordering based on the 'updated_at' ...

It appears that IE 10 is having trouble displaying modals, possibly due to a compatibility issue with jQuery 1.7.1's animate function

By visiting www.carsense.com and clicking on the login link in the top-right corner, you may notice that the curtain appears but the modal itself does not display, even though it exists: If you locate id="content1" and modify the inline opacity to 1, the ...