In Bootstrap 4, what is the opposite of the .flex-fill class?

Referencing the documentation found here: https://getbootstrap.com/docs/4.1/utilities/flex/#fill

I am looking to have a flex element only fill on devices smaller than sm (matching my column breakpoint in the example).

Therefore, I thought of using something like .flex-fill .flex-sm-nofill

However, there is no such thing as flex-nofill!

It seems like I might be missing something obvious here, but how can I address this issue using just vanilla Bootstrap classes?

Although it wouldn't be difficult to create a new -nofill class, I was curious if there is already an existing solution that I may have overlooked.

In this particular scenario, I aim to have the buttons within following code example fill:

<div class="row justify-content-between p-3">
  <div class="col-12 col-sm-8 col-xl-6 pb-2">
    <select class="custom-select" id="layer_select">
        <option data-dismiss="modal" value="0">Option1</option></select>
  </div>
  <div class="col-12 col-sm-3">
    <div class="d-flex justify-content-between justify-content-sm-end">
      <button class="btn btn-outline-secondary mr-2 flex-fill flex-sm-nofill"><i class="material-icons">file_download</i></button>
      <button class="btn btn-outline-secondary flex-fill flex-sm-nofill"><i class="material-icons">filter_list</i></button>
    </div>
  </div>
</div>

Fiddle (Resize width to observe effect): https://jsfiddle.net/xpvt214o/155315/

The objective is to maintain fixed width for the buttons when they are positioned alongside the select element.

Answer №1

flex-fill is responsible for setting flex: 1 1 auto.
If you want to modify this behavior specifically for the sm breakpoint, you can utilize flex-sm-grow-0.
This will result in flex: 0 1 auto.

For more details, refer to Grow and Shrink.

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/materialicons/v36/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -moz-font-feature-settings: 'liga';
  -moz-osx-font-smoothing: grayscale;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

<div class="row justify-content-between p-3">
  <div class="col-12 col-sm-8 col-xl-6 pb-2">
    <select class="custom-select" id="layer_select">
    <option data-dismiss="modal" value="0">Option1</option></select>
  </div>
  <div class="col-12 col-sm-3">
    <div class="d-flex justify-content-between justify-content-sm-end">
      <button class="btn btn-outline-secondary mr-2 btn-icon flex-fill flex-sm-grow-0"><i class="material-icons">file_download</i></button>
      <button class="btn btn-outline-secondary btn-icon flex-fill flex-sm-grow-0"><i class="material-icons">filter_list</i></button>
    </div>
  </div>
</div>

Answer №2

If you are using Bootstrap 5, there are responsive breakpoints available for flex-fill.

"Responsive variations also exist for flex-fill."

.flex-fill .flex-sm-fill .flex-md-fill .flex-lg-fill .flex-xl-fill .flex-xxl-fill"

For more information, you can visit: https://getbootstrap.com/docs/5.0/utilities/flex/#fill

In your specific case, using .flex-md-fill will do the trick.

<div class="row justify-content-between p-3">
  <div class="col-12 col-sm-8 col-xl-6 pb-2">
    <select class="custom-select" id="layer_select">
        <option data-dismiss="modal" value="0">Option1</option></select>
  </div>
  <div class="col-12 col-sm-3">
    <div class="d-flex justify-content-between justify-content-sm-end">
      <button class="btn btn-outline-secondary mr-2 flex-md-fill"><i class="material-icons">file_download</i></button>
      <button class="btn btn-outline-secondary flex-md-fill"><i class="material-icons">filter_list</i></button>
    </div>
  </div>
</div>

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

Steps to incorporate a JavaScript component for the HTML Header (navbar) across a website containing over 100 webpages

Managing a website with 200+ webpages and a Navigation Bar (Header) can be a challenge. How do I automate this process to avoid updating the header in each of the 200+ webpages using JavaScript? What's the most effective approach? I tried implementin ...

How can I create a table without a bottom border?

click here for image instructions on creating a table using CSS I'm struggling to achieve the desired result The goal is to remove borders at the end of the table I can't seem to figure it out I can't seem to figure it out Removing borders ...

Navigating Divs Using jQuery

I am working with a class that has multiple divs, each with a unique id attached to it. I am using jQuery to dynamically cycle through these divs. This is a snippet of my HTML code: <div id ="result">RESULT GOES HERE</div> ...

Creating a hyperlink with the link_to method in Ruby on Rails

Struggling to integrate a web address link into a button using Bootstrap on Rails. I want the link to open in a new tab. Current code: <%= link_to "Learn more about the Royal Lancers»", "#", class: "btn btn-primary btn-lg" %> Trying to link the b ...

Looking to swap out innerHTML in a div multiple times with javascript?

When dealing with a div element that appears multiple times in your HTML: <div class="myclass">abc</div> <div class="myclass">abc def</div> ... How can I replace "abc" for all occurrences, rather than just the first one? (I' ...

Trouble with CSS in a WordPress theme utilizing a two-column layout

After setting up my wordpress blog (http://raptor.hk), I encountered an issue with aligning the right sidebar correctly. It seems like I have overlooked something in the CSS code. The div responsible for the sidebar has been assigned the name "rightbar". I ...

Utilizing query and Angular JS for dynamic animation

Currently, I'm developing a Hybrid iPad application that utilizes AngularJS and PhoneGap. I've encountered an issue with animations. I need to animate a div from left to right and make it toggleable. By default, the div should be hidden. Could ...

What is the best way to add several icons at once?

Is there a way to insert multiple star icons directly below the review text? I attempted to use pseudo elements to add the icons, but I could only insert one icon when I actually need to include multiple icons. Here is what I have tried so far: .review:: ...

What steps are involved in integrating a new platform into a LibGdx project?

After using the LibGdx project creator tool to generate my project, I chose Android and Desktop projects but omitted html. Is there a way for me to integrate html support into my LibGdx game at a later stage? ...

What could be the reason for having two HTML nodes within a one-node HTML document?

My goal is to use DOMdocument to retrieve a list of HTML nodes in order to create a visually appealing CSS3 tree visualization on a web page. However, I've encountered an issue with the code snippet below: // Compressed, testing HTML $text = '&l ...

Is there a way to display a specific item in the breadcrumbs with a unique color that contrasts with the other items?

I have created a breadcrumb using CSS and HTML, but I want to add a unique style to one of the items in the list without using hover effects. I attempted to apply a different class with a background color but it didn't work as expected. Does anyone h ...

Tips for connecting JavaScript to HTML documents

I am currently developing a browser-based video editing tool. In order to optimize functionality, I am looking to have users download a ~70mb JavaScript file and save it on their device for easy access. How can I effectively link this file when my website ...

Enter the [color] HTML5 code and check for compatibility with all the latest web browsers

I am interested in implementing a color picker functionality using the input[color] element in HTML5. I would like to confirm if this method is compatible with all modern browsers. Additionally, I am curious if there are alternative ways to achieve this, ...

The compatibility issue between Angular version 18.2.0 and bootstrap 5.3.3 is causing functionality errors

My Angular project is using version 18.2.0 and Bootstrap was installed with the command: npm install bootstrap I have updated the "styles array" and "scripts array" in angular.json. In app.component.html, I added a simple button. The application was lau ...

Toggle the visibility of content with jQuery or Ajax

As I work on designing a webpage at this link, I am facing an issue with the projects tab due to my lack of experience in proper protocol. The plan is to have a side menu where users can select different content options (CAD, FEA, MATLAB, etc.), which wi ...

Using jQuery, you can easily apply a new class to a div when it is

I'm currently facing an issue with adding a class of "active" to a div upon clicking it using jQuery. My goal is to apply the css class of active in order to give the button a distinct color (or the hover effect.) Unfortunately, I have been unsuccess ...

What is the optimal offset to enhance the drag effect?

I have been working on making a draggable cloud, but I am facing an issue where the cloud always clips from the center to the mouse position. Here is the current setup: $(document).ready(function () { // code for cloud setup }); #background-canvas ...

CSS z-index property not functioning properly for Flowplayer on Firefox browser

I am attempting to create a layered div using z-index, with one of the layers containing a flowplayer. Once the layer is properly created, I plan to update the div's z-index value based on the logic of the program. The following code functions correct ...

Eliminate the need for background video buffering

I have a piece of code that I'm using to remove all the created players for my video elements. The code works fine, but I'm facing an issue where the video keeps buffering in the background after it's changed via an ajax call success. Can yo ...

labels placed beneath evenly spaced radio buttons arranged horizontally

When creating a user form, I am in need of multiple likert items to gauge opinions accurately. My project requires the use of the oTree library, which is closely integrated with django. It is essential that any solution implemented aligns with oTree as muc ...