Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set CSS3 flex-basis property using Bootstrap Flex?

Tags:

html

css

flexbox

Using CSS3 I can individually set the flex properties like so

.someclass {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: auto;   
}

Using Bootstrap (version >= 4.1) flex it seems I can only set flex-grow-X and flex-shrink-X, like so

<div class="someclass flex-grow-1 flex-shrink-1">...</div>

Is there are way to set the flex-basis using bootstrap 4.1?

like image 946
robor Avatar asked May 17 '19 12:05

robor


People also ask

Can you use Flex with bootstrap?

Flexbox. The biggest difference between Bootstrap 3 and Bootstrap 4 is that Bootstrap 4 now uses flexbox, instead of floats, to handle the layout. The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning.

When using flexbox layout the flex property does what?

Flexbox is a one-dimensional layout method for arranging items in rows or columns. Items flex (expand) to fill additional space or shrink to fit into smaller spaces.

How do you set a flex position in CSS?

Flex Start positions element at the start of the page. Flex End sets the element to the end of the page. Space Around arranges the items evenly but with spaces between them. The spaces will be equal among all the elements inside a flex-box container, but not outside them.

How does flex-basis work in CSS?

The flex-basis property is a sub-property of the Flexible Box Layout module. It specifies the initial size of the flex item, before any available space is distributed according to the flex factors. When omitted from the flex shorthand, its specified value is the length zero.


1 Answers

Looking at the source code of Bootstrap v4.1, there are no utility classes included that specifically target the flex-basis value.

Searching through the file, there are only 12 occurances of the word flex-basis:

  • 5 times to set flex-basis to 0 for some of the col-* classes (e.g. line 625).
  • 7 times for styling specific navbar related classes (e.g. line 4268).

This also seem to remain the case in the latest versions of Bootstrap at the time of this writing:

  • Bootstrap v4.5.3
  • Bootstrap v5.0.0-alpha3
like image 171
Matt Avatar answered Oct 02 '22 13:10

Matt