Is it possible to adjust the font size in Bootstrap 4 using only CSS?

Recently, I made the switch from Bootstrap 3 to Bootstrap 4 and have been struggling with adjusting the font size for elements such as h1, p, and span.

UPDATE: I am looking to change the font size based on screen size using Media Queries.

I appreciate @ZimSystem for providing insight on how to adjust the font size. However, I am curious about changing it dynamically according to different screen resolutions through media queries.

Check out this Sample Fiddle

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) {  
    h1 {
      font-size: 30px;
    }
}

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { 
    h1 {
      font-size: 100px;
    }
}

// Large devices (desktops, 992px and up)
@media (min-width: 992px) { 
   h1 {
      font-size: 150px;
  } 
}

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { 
   h1 {
      font-size: 200px;
  }
}

Here's a snippet of my HTML code:

<img class="img-responsive mx-auto d-block" src="./assets/brand/cmm.png" />

<div class="row">
  <div class="col-md-12 text-center">
    <h1><strong>This is a sample title</strong></h1>
    <h2 class="text-white">South Florida's Community of Creatives Come together</h2>
  </div>
</div>

Unfortunately, even this approach isn't yielding the desired results.

Am I overlooking something here? Or does Bootstrap 4 not allow for responsive font-size changes purely through CSS?

Answer №1

Depending on where and how you make the changes, it should function properly. Just ensure that any custom CSS additions are in line with the bootstrap.css file, and you probably won't need to use !important

See it in action: https://www.example.com/code-demo

Answer №2

Consider using vw units instead of px for better font display results based on my personal experience.

// Adjusting font size for different screen sizes using vw units
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) {  
     h1 {
         font-size: 30vw;
     }
}

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { 
    h1 {
        font-size: 100vw;
    }
}

 // Large devices (desktops, 992px and up)
 @media (min-width: 992px) {
     h1 {
         font-size: 150vw;
     }
 }

 // Extra large devices (large desktops, 1200px and up)
 @media (min-width: 1200px) {
     h1 {
         font-size: 200vw;
     }
 } 

Answer №3

To customize your styles, simply build upon the foundation of bootstrap css and modify the specific selectors as needed without relying on !important declarations.

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

Position the icon to the left within a bootstrap 5 card

Struggling with alignment in Bootstrap 5, facing two issues: 1- How to align my icon with the left border of the card body? 2- Increasing the icon size affects the vertical alignment of my card item (see image below) https://i.sstatic.net/dR7DD.png Try ...

Changing colors when hovering over different elements

I am struggling to create a hover color change effect that applies to all elements (icon, text, and button) from top to bottom. Currently, the hover effect only changes the color of either the text and icon or the button individually. Below is the code sn ...

The lower section of the webpage conceals the information in the div element located

I am facing a problem on codesandbox where I am trying to add a footer, but the content above it is getting hidden. Can anyone help me figure out how to fix this issue? What mistake could I be making? The footer component has been commented out in the app ...

Background and border presentation issues arising from CSS conflict

While working on a webpage, I encountered a design conflict within a div that contains a group of other div elements. The current appearance can be seen at , and the desired look is shown in the image here: enter image description here ...

Changing the background color of tabs in Angular

Being a beginner in HTML and CSS, I recently utilized the angular-tabs-component to create tabs. Now, I am looking to change the background color of the tab. Can someone guide me on how to achieve this? Below is the code snippet: HTML: <tabs (currentT ...

Is it possible to create a mouse-following effect with lighting using Javascript

Recently, I've been honing my Javascript skills and decided to create a follow-mouse function. After successfully implementing it, I started brainstorming a new concept that I'm unsure is achievable. Is there a way to develop an "orb of vision" ...

Tips for aligning the child elements of a dropdown menu to stick with the parent's top position

It's important that progress and my goals are clearly outlined here: View my CodePen When it comes to the "Offices" section, I need the child objects to display directly below and ideally match the width of the parent element. Here is the code snip ...

:before pseudo-element causing interference with child elements

Struggling to understand how an absolutely positioned :before element works. I need a large quote mark to be placed behind a testimonial. I opted for a :before element because it is a font, making it scalable for retina displays and saving an extra HTTP re ...

The primary content division is trapped behind the side navigation bar

Why is my sidebar fixed on the left of the screen overlapping with the main content? I want the main content to be displayed next to the navbar and scroll up and down while keeping the nav bar in place, but no matter what styling I apply, it doesn't w ...

The updated bootstrap.min.css file may have compatibility issues with Bootstrap navigation, while an earlier version should work seamlessly

Currently, I am working on developing a menu using bootstrap. When the menu is toggleable, it collapses into a hamburger menu. However, I have encountered an issue where the navigation only works with an earlier version of bootstap.min.css and not with t ...

Dealing with a problem in CSS Flexbox while aligning child elements using the `align-self`

Check out this test code here - https://jsfiddle.net/8dgeh9r3/1/ I have set up two scenarios to simulate. In the first scenario, there is a main parent flex container with multiple intermediary parents (which are also flex boxes that inherit properties fr ...

Click to shift the div downwards

Currently, I have a piece of javascript applied to a div that directs the user to a specific link: <div style="cursor:pointer;" onclick="location.href='http://www.test.com';"> I am wondering if there is a way to add an effect where, upon ...

Adjusting the height of the navbar items to align with the size of the

In the bootstrap navbar below, I am trying to enlarge the search field to be large using 'input-lg', but this causes the other items in the navbar not to vertically center correctly. How can I align the other items in the navbar with the large in ...

Update the CSS classes exclusively for the specified ID

Attempting to modify and override certain classes within the complex control (dxList) of DevExtreme has been successful thus far. .dx-loadpanel-content { transform: translate(0px, 0px) !important; margin: auto !important; left: 0px !important; ...

D3.js: Difficulty fitting the chart within my bootstrap div

Currently, I'm encountering a problem where the "card" component from Bootstrap is not adjusting responsively with my d3.chart. The screenshot below displays the outcome: https://i.sstatic.net/2MhBx.png Chart Code const sample = [ { languag ...

Centralized and secure masthead

Currently, I am focusing on showcasing my portfolio at www.bbellmedia.com/mywork The specific requirement I have is to center the text 'Bryan Bell' and ensure that it remains fixed even when the user scrolls. Can anyone suggest the most effecti ...

Assistance required in forming a Button Group featuring a Pointer Shape

https://i.sstatic.net/bBwqi.png I came up with this idea for a button group. <div class="btngroup"> <button type="button" class="btn">Organization</button> <button type="button" class="btn">Project</button> <butto ...

A CSS-based puzzle game inspired by the classic game of Tetris

CLICK HERE TO ACCESS PLAYGROUND CHALLENGE To create a two-column div layout without any spaces using CSS is the challenge at hand. STARTING LAYOUT Each box is represented as: <div class=A1">A1</div> https://i.sstatic.net/FlZ8k.jpg DESIRED ...

Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far. Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it ...

wordpress website experiencing a logo consistency issue on mobile devices

Issue with displaying custom logo on mobile devices persists even after updating theme options. Since the default logo continues to appear, the next step is to locate the default logo in the theme coding and replace it with the desired custom logo specific ...