Tips for customizing the base font size in a Bootstrap 4 template

My Java/Spring Boot webapp utilizes Thymeleaf HTML page templates and Bootstrap 4, with the foundation being a free Bootstrap 4 site template called 'Simple Sidebar': . The current setup is functioning smoothly for me.

I am interested in adjusting the CSS from the 'Simple Sidebar' Bootstrap template to decrease the default text font size throughout the entire template. The purpose of this web application is for internal use within a company, only accessible on PC browsers. It is crucial that the font size accommodates displaying a substantial amount of information on the screen simultaneously.

QUERIES:

  1. Is it feasible to make this type of modification in a Bootstrap 4 template?
  2. If so, do I have to directly edit the CSS files provided with the template, or is there a method to override their CSS classes using a custom CSS file within my project? (Ideally, I would like to refrain from altering the original CSS files that accompany the Bootstrap template)

Answer №1

I recently came across an informative tutorial that I found to be quite helpful:
https://bootstrapcreative.com/can-adjust-text-size-bootstrap-responsive-design

The tutorial suggested a method where the font-size is adjusted based on the category of the window/screen size where the page is being viewed. I decided to implement this approach in my own application, and it provided me with the flexibility I was looking for.

For testing purposes, I set some unusually large values for commonly used HTML elements. As expected, the text appeared very large within those elements.

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
  a {font-size:3.5rem;} /*1rem = 16px*/
  td {font-size:3.5rem;} /*1rem = 16px*/
  p {font-size:3.5rem;} /*1rem = 16px*/
  h1 {font-size:3.5rem;} /*1rem = 16px*/
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
  a {font-size:5rem;} /*1rem = 16px*/
  td {font-size:5rem;} /*1rem = 16px*/
  p {font-size:5rem;} /*1rem = 16px*/
  h1 {font-size:5rem;} /*1rem = 16px*/
}

The flexibility also works in the opposite direction with very small values like this:

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
  a {font-size:0.5rem;} /*1rem = 16px*/
  td {font-size:0.5rem;} /*1rem = 16px*/
  p {font-size:0.5rem;} /*1rem = 16px*/
  h1 {font-size:0.5rem;} /*1rem = 16px*/
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
  a {font-size:0.75rem;} /*1rem = 16px*/
  td {font-size:0.75rem;} /*1rem = 16px*/
  p {font-size:0.75rem;} /*1rem = 16px*/
  h1 {font-size:0.75rem;} /*1rem = 16px*/
}

I appreciate how the font size automatically adjusts itself on my computer when I resize the browser window. It's important to provide sensible values for the different window sizes for this feature to function properly.

I managed to implement this without altering any of the files included in the Bootstrap template bundle. I created a separate CSS file called my-custom-styles.css, which I placed in the same directory as the simple-sidebar.css file that comes with the Bootstrap template.

Lastly, within the <head> section of my HTML template, the following links need to be included:

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet"
        th:href="@{/vendor/bootstrap/css/bootstrap.min.css}"
        href="../../static/vendor/bootstrap/css/bootstrap.min.css" />
  <!-- Custom styles for this Boostrap template -->
  <link rel="stylesheet"
        th:href="@{/css/simple-sidebar.css}"
        href="../../static/css/simple-sidebar.css" />
  <!-- Custom styles for my application that override the Bootstrap template -->
  <link rel="stylesheet"
        th:href="@{/css/my-custom-styles.css}"
        href="../static/css/my-custom-styles.css" />

NOTE: The th:href attributes are specific to the Thymeleaf template library and are not present in the final HTML sent to the client's browser.

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

When utilizing CKEDITOR, the default TEXTAREA is obscured, and CKEDITOR does not appear

I am trying to incorporate CKEDITOR into my project. I have added the ckeditor script in the footer and replaced all instances of it. <script src="<?= site_url('theme/black/assets/plugins/ckeditor/ckeditor.min.js') ?>" type="text/javasc ...

Element with a fixed position within an iScroll container

Has anyone encountered an issue with fixing an element with position: fixed inside a big Iscroll page? It seems like the element scrolls along with the content due to the transition imposed by Iscroll. I'm trying to fix the "FIXTHIS" element, but it ...

How can you determine the dimensions of an image in HTML using Python?

Is there a way to extract image size information from source code using Python? tree = etree.HTML(source_page_text) image_list = tree.xpath('//img[@src]') The 'img' tags with 'src' attributes can be found using xpath as show ...

Tips for implementing a sticky sidebar in HTML5 with jQuery

I currently have two files: index.php and aside.php. I've already created the contents of aside.php. Now, I want to make the aside page sticky. To achieve this, I referred to the following link: http://codepen.io/pouretrebelle/pen/yvcBz My struggle ...

How can I center two images using a hover effect in WordPress?

When the mouse hovers over an image, it changes to another image. Everything works smoothly except for one issue - the image is not centered. Below is the code I am currently using: HTML: <figure> <a> <img class="hover" src="na ...

The z-index issue with Bootstrap modal is not being resolved on Firefox and Internet Explorer

I am encountering an issue with my bootstrap modal that includes a jquery datepicker. Specifically, the datepicker is styled as follows: .datepicker{ z-index:1000;} Interestingly, it functions perfectly on Google Chrome, displaying like this: However, ...

Dynamic CSS sizing

Currently, I am in the process of creating a component and my goal is to achieve a specific layout without the use of JavaScript, preferably utilizing flexbox. Essentially, envision a messenger chat screen with a header and footer containing controls. htt ...

Aligning Text Vertically with an Image in ul/li List Items

Apologies if this question has already been asked, but I've checked several similar inquiries in an attempt to merge the solution without much luck. I currently have a bootstrap row with two col-md-6's. The first column contains an image, while t ...

Alter the position of the anchor object in the center using JavaScript upon page load

When my page loads, I want to automatically jump to a specific anchor tag and ensure that the anchor object is centered in the window. Initially, I implemented a basic function to achieve this: <body onload="goToAnchor();"> <script type="text/ja ...

Ensuring the Angular Material bottom sheet (popover) stays attached to the button

Recently, I've been working on an Angular project where I successfully integrated a bottom sheet from Angular Material. However, I encountered an issue when trying to make the opened popup sticky to the bottom and responsive to its position, but unfor ...

The scroll function is executed only one time

I'm currently working on implementing a sticky sidebar snippet using jQuery. However, I am facing an issue where the function within .scroll() is only executing once instead of on every scroll event. Can anyone help me identify what I might be doing i ...

Do arrays permanently retain the strings stored within them?

As an 11-year-old who has been learning Javascript for the past month and a half, I am currently working on creating a login/register system. Right now, my focus is on the register part. I have a question: when adding a string/number/boolean to an array, d ...

In relation to User Interface: Analyzing target tracking and studying the flow of time

Is there a way to track mouse cursor movements, button clicks, and click times to an external database using only CSS, HTML5, and Javascript? I am curious about the possibility of conducting usability studies in this manner. ...

Is there a way to create an effect where the color of a floating action button changes when you hover over it, similar to a filter?

I'm new to using the <Fab /> element and I'm struggling to figure out how to implement a hover effect that will change the button's color. Here's what I have so far: JavaScript: <Fab variant="extended" className=&quo ...

What causes the <td> element to extend beyond the boundaries of the <table>?

I need to add next and previous buttons to a <td> that has an asp:DropDownList. However, when I do this, the <td> ends up overflowing the width of the table. Here is the edited code snippet with the entire table included: <table class=" ...

Unable to view the image in browsers other than Internet Explorer

On a webpage, there is a feature where clicking on the "Add More" link should display an input box and a "Delete" button image. Surprisingly, this functionality works perfectly on IE browsers, but not on Mozilla or Chrome. In non-IE browsers, only the text ...

When encountering a 404 redirect, CSS and JS files may fail to display

I created a unique error message using .htaccess, incorporating CSS and JS in separate folders. Although it functions properly when accessed directly, integrating these resources into the 404 Error message results in only the HTML text being displayed with ...

Tips for creating multiple toasts with Bootstrap 4

I am looking to generate multiple toast notifications without knowing the exact number in advance. Many examples I have come across show hardcoded HTML sections. For instance, the code for displaying 2 notifications is pre-defined as shown [here][1]. Whil ...

Tips for using JavaScript to style an array items individually

I have currently placed the entire array within a single div, but I would like to be able to display each element of the array separately so that I can style "date", "title", and "text" individually. This is my JSON structure: [ { "date": "Example ...

Change the appearance of the page when it is being displayed within an iframe using CSS

How can I display a webpage differently using CSS if it is within an iframe? I would like to use jQuery or JavaScript to switch to a different stylesheet specifically when the site is being displayed within an iframe. Any suggestions on how to achieve th ...