-1

I'm using bootstrap 5.3 and have added the below code to the scss to add responsive font.

The issue is that the fs-lg-3 is taking priority over the fs-xl-2 and the font for the wider screen is actually displaying the lg size rather than the xl or even xxl size.

My screen width 1920px, browser full screen.

SCSS Code:

$utilities: map-merge(
  $utilities,
  (
    "font-size":
      map-merge(
        map-get($utilities, "font-size"),
        (
          responsive: true
        )
      )
  )
);

I have the following html

<p class="fs-6 fs-md-4 fs-lg-3 fs-xl-2">Some Text</p> 

The css for the element shows the following in the chrome developer tools.

@media (min-width: 1200px) {
    .fs-lg-3 {
        font-size: 1.75rem !important;
    }
}
@media (min-width: 1200px) {
    .fs-md-4 {
        font-size: 1.5rem !important;
    }
}
@media (min-width: 1200px) {
    .fs-xl-2 {
        font-size: calc(1.325rem + 0.9vw) !important;
    }
}

In the compiled css file for the respective min-width 1200px :

.fs-md-4 appears on line 11528
.fs-lg-3 appears on line 11537
.fs-xl-2 appears on line 10775

I suspect its because the fs-lg-3 appears later in the css file on line 11537, whereas fs-xl-2 is before it on 10775.

Is this a bug in bootstrap, am I misunderstanding it, or do I need to change the scss code so that is orders the font sizes in the correct order of operations?

I'm expecting the fs-xl-2 class to change the font-size, but instead the fs-lg-3 takes priority on wider screens.

9
  • 1
    md, lg and xl are supposed to stand for different breakpoints to begin with, so having them all apply styles at the same breakpoint, really doesn't make much sense.
    – CBroe
    Commented Jul 4 at 12:14
  • @CBroe I get what you mean, but the benefit is that it allows you to set a style for a range of breakpoints, not just one. In my particular case, I do need to set them individually to make this work. Unfortunately I think the order of operations has gone wrong somewhere. Commented Jul 4 at 14:13
  • "but the benefit is that it allows you to set a style for a range of breakpoints, not just one." - all these breakpoint "modifiers" make the classes work for "their" breakpoint, and the ones above. I really can't see what you are trying to achieve by your approach.
    – CBroe
    Commented Jul 5 at 6:09
  • I want the font size to change based on the different screen sizes. How else do you do this in bootstrap? You havent provided an answer other than comment its wrong, can you respond with an answer using bootstrap classes? Commented Jul 8 at 8:35
  • Why are you putting those number suffixes on your classes in the first place, what sense are those supposed to make?
    – CBroe
    Commented Jul 8 at 8:49

0

Browse other questions tagged or ask your own question.