Creating a custom breakpoint in Bootstrap for adding unique CSS styles

Consider this scenario

<div class="col-md-my">
</div>
.xx {
   color: black;
}

.yy {
   color: red;
}

Similar to how Bootstrap adjusts width at different breakpoints.

Create a new class called col-md-my

When the width exceeds the md breakpoint, the CSS will apply the class xx

When the width is below the md breakpoint, the CSS will apply the class yy

xx and yy are custom CSS classes.

How can this be achieved using Bootstrap variables and functions?

Answer №1

Details:

Content within this query (anything prior to 576px):

@media (max-width: 575.98px) { 

  .custom-txt-color {color: #000000;}

}

..will be displayed in black (#000000)



Upon reaching 576px:

@media (min-width: 576px) and (max-width: 767.98px) { 

  .custom-txt-color {color: #666000;}

}

..it will change to dark green (#666000)



In the absence of a max-width, it remains as follows:

@media (max-width: 575.98px) { 

  .custom-txt-color {color: #000000;}

}

.....text is black initially, then transforms to:

@media (min-width: 576px) { 

  .custom-txt-color {color: #666000;}

}

.....as it becomes dark green and retains that color due to no specified max width.

An efficient tool for testing screen sizes<<<<

Handy breakpoint code snippet: (sourced from Bootstrap 4.6 directly):

/* Extra small devices  (portrait phones, less than 576px) */
@media (max-width: 575.98px) { ... }

/* Small devices  (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) { ... }

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) { ... }

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) { ... }

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) { ... }

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

Enhancing an element by incorporating animation into its active state

For my web assignment, I have received specific instructions regarding a section of the webpage involving five dice: There are five dice in play. When the webpage loads, a three-dimensional image of each dice must be displayed. Upon clicking a dice, it ...

Ensure that the select boxes are aligned in a horizontal manner

I am currently attempting to adjust the alignment of select boxes to reduce the staggered appearance. While not all need to be perfectly aligned, it would be ideal to have those that are close enough in alignment. I prefer using HTML to accomplish this tas ...

Unable to consistently select a radio button via code across different browsers

Is there a way to automatically select a radio button based on the URL path? $(document).ready(function () { function checkRadioBasedOnUrl() { var urlPath = window.location.pathname.split("/"); console.log(urlPath); // ["", "tradeshow ...

Activate the button when the password is correct

Check out my code snippet: $("#reg_confirm_pass").blur(function(){ var user_pass= $("#reg_pass").val(); var user_pass2=$("#reg_confirm_pass").val(); var enter = $("#enter").val(); if(user_pass.length == 0){ alert("please fill password ...

Ways to ensure text fits nicely within a container: HTML & CSS

Below is a code snippet: @import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans'); .square { max-width: 460px; background: white; border-radius: 4px; box-shadow: 0px 5px 20px #D9DBDF; -webkit-transition: all 0. ...

Problem with custom validation in Bootstrap 5

Utilizing bootstrap 5 for form validation, I have encountered an issue with applying the 'is-invalid/is-valid' class to the date field 'dob' within a custom date validation method called validate_dob(). I attempted performing the date ...

What is the reason that a <button> tag is unable to include a <div> element within it?

While developing our company website, we encountered a challenge with a JavaScript library failing to replace a certain element. In an attempt to troubleshoot, we ran our HTML code through the W3C validator and discovered that nesting a <div> tag wit ...

What could be causing my Time Picker MUI to malfunction in my React project?

I am currently working on a React and Rails project where I am attempting to style my React components. However, I have encountered an issue with the MUI component Time and Date picker. Whenever I try to implement the time picker, I get a strange error reg ...

Establish a variable in XSL to define the tabIndex

My XSL code has been designed to read an XML file and generate input elements of type text for each child node. The XML file structure is as follows: For node c, two input boxes are created in the format: Label(com 1) :input box--------------------- Label ...

Find and conceal the object within the list that includes the term "Ice"

The teacher's assignment is to create a radio button filter that hides items with the word "Ice" in them, such as "Ice Cream" and "Iced Tea." Here is the current code I have been working on: <!DOCTYPE html> <html> <head> <me ...

The jQuery scrollLeft function seems to be stuck and not working correctly

I have a container div with a ul inside of it set up like this CodePen: http://codepen.io/example/123 Why won't the scroll feature work? HTML: <div id="container"> <ul class="list"> <li>apple</li> <li>orange& ...

The application of border-radius to a solitary side border forms a unique "crescent moon" shape rather than a traditional semi-circle

Is there a way to transform this shape into a regular semicircle, avoiding the appearance of a moon, and change the image into a circle rather than an ellipsis? http://jsfiddle.net/226tq1rb/1/ .image{ width:20%; border-radius:500%; border-rig ...

What is the best way to attach multiple files in PHP using mail.php and mime.php from Pear library?

I am having trouble attaching multiple files. When I try to attach more than one file, only one file gets sent in the email even though I attached multiple files. if(isset($_POST['upload'])){ include('config.php'); include_once ...

Bootstrap 4 row featuring bottom-aligned buttons on both the left and right sides of the container

There is a row of buttons with two aligned on the left and one on the right: html { position: relative; min-height: 100%; } body { /* Margin bottom by footer height */ margin-bottom: 60px; } .footer { position: absolute; bottom: 0; w ...

What is the best way to position the top line next to the border?

I've been attempting to create a falling line effect on the left side of the box's border, but I can't seem to figure out what's causing the issue. Below is the code snippet: @import url('https://fonts.googleapis.com/css ...

Styling elements with CSS to display inline blocks next to each other while taking up the full

I am facing a challenge with two text blocks of varying lengths. The left block contains short text while the right block may have lengthy content. Both blocks need to be displayed side by side, occupying 100% of the parent's width exactly. For a sim ...

Adjust the sidebar size in Bootstrap 5 to align perfectly with the navbar brand

https://i.stack.imgur.com/Ra0c7.png I'm trying to ensure that the width of the sidebar on this page aligns consistently with the end of the logo in the top right. However, using variations of col-xxl-1 etc. is causing inconsistent sizes at different ...

Effortless 'rotational' script

I am currently developing a HTML5 Canvas game with the help of JavaScript. My aim is to create an object that smoothly transitions to a specific direction. The direction is being stored as a variable and calculated in radians. Here's how the code op ...

Managing post and session data during PHP form submission

I've encountered an issue with my code structure. What I aim to achieve is: To validate if post values exist, then execute the query and show the results. If post values are not present, check for a session value. If session is available, manipulate ...

extracting information with beautifulsoup

Currently, I am diving into BS4 to enhance my skills and expertise. My goal is to scrape various tables, lists, and other elements from well-known websites in order to grasp the syntax. However, I am encountering difficulties when it comes to formatting a ...