logo
down
shadow

flexbox prevent wrapping of rows


flexbox prevent wrapping of rows

By : Daniela Brandão
Date : November 21 2020, 03:00 PM
will help you If you have 2 or maximum 3 rows, you can use pseudo :before and/or :after to force new lines. flex:1; should evenly dispatch the children on each rows. You can also use a min-width to easily add a transition.
This technic allows you to draw 3 rows without extra markup. to draw more rows, use a new container or insert elements to break the lines the same way the pseudo does.
code :
section {
display:flex;
flex-wrap:wrap;
}
div {
  flex:1;
  min-width:calc(16.66% - 2px);
  transition:0.5s; 
  margin:auto;
  height: 40px;
  background-color: #f00;
  margin: 1px;
  -webkit-transition: 0.15s;
  transition: width 0.15s;
  order:0;
}
div:nth-child(4)~div {/* every div starting from the fith */
  order:2;
}
section:before{
  content:'';
  width:100%; /* fill a whole row */
  order:1;/* comes before the fith div*/ 
}
div:focus {/* css demo purpose instead js onclick event */
  min-width:calc(50% - 2px);
  transition:0.5s; 
  background-color:yellow
}



div {display:flex;align-items:center;justify-content:center;}
section {counter-reset: div}
section div:before {counter-increment:div;content:'DIV N°: 'counter(div);}
<section>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
</section>
section {
display:flex;
flex-wrap:wrap;
}
div {
  flex:1;
  min-width:calc(16.66% - 2px);
  transition:0.5s; 
  margin:auto;
  height: 40px;
  background-color: #f00;
  margin: 1px;
  -webkit-transition: 0.15s;
  transition: width 0.15s;
  order:0;
}
div:nth-child(4)~div {
  order:2;
}
div:nth-child(8)~div {
  order:4;
}
section:before,
section:after{
  content:'';
  width:100%;
  order:1;
}
section:after {
  order:3;
}
div:focus {
  min-width:calc(50% - 2px);
  transition:0.5s; 
  background-color:yellow
}

div {display:flex;align-items:center;justify-content:center;}
section {counter-reset: div}
section div:before {counter-increment:div;content:'DIV N°: 'counter(div);}
<section>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
  <div tabindex="0"></div>
</section>


Share : facebook icon twitter icon
prevent wrapping lines in flexbox child element

prevent wrapping lines in flexbox child element


By : Alexandros776
Date : March 29 2020, 07:55 AM
like below fixes the issue How do I prevent line wrapping of a flexbox element? Is it even possible? , The property you are looking for is flex-shrink, not flex-basis.
code :
.no-wrap{
  flex-shrink: 0;
}
.no-wrap{
  flex: 0 0 auto; 
}
Flexbox challenge: how to get row wrapping with children identical and uniform margins in full rows

Flexbox challenge: how to get row wrapping with children identical and uniform margins in full rows


By : Roberto Capriles Smi
Date : March 29 2020, 07:55 AM
will be helpful for those in need With help of @michaPau and by using sass I am able to get everything I asked for. I added this bit of code to my "version 2" as he/she suggested and it works.
code :
/* this is the additional code that gets it to work: thanks to @michaPau */

li    
  display: flex
  justify-content: center 
  align-items: center

/*  --- end of michaPau's code --- */
<ul>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      I am taller then the other children on this row        </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
  <li>
    <div class="content">
      hi there
    </div>
  </li>
<!-- language: lang-css -->


=flex-wrap-fix($flex-basis, $max-viewport-width)
  flex-grow: 1
  flex-basis: $flex-basis
  max-width: 100%

  $multiplier: 1
  $current-width: 0px

  @while $current-width < $max-viewport-width
    $current-width: $current-width + $flex-basis
    $multiplier: $multiplier + 1

    @media (min-width: $flex-basis * $multiplier)
      max-width: percentage(1 / $multiplier)

ul
  display: flex
  flex-wrap: wrap
  justify-content: center

li
  // I want the width to be between the following two sizes
  min-width: 40px
  text-align: center
  //max-width: 100px
  // this keeps all the elements the same size
  // **as long as they are on the same row**
  // but I want them to all the same width everywhere
  //flex: 1 0 0

  +flex-wrap-fix(100px, 2000px)

// demo styles

ul, li
  margin: 0
  padding: 0
  list-style: none

ul
  background-color: tomato

li  
  .content 
    margin: .5em
    background-color: darkgreen

/* this is the extra new code thanks to @michaPau */

li    
  display: flex
  justify-content: center 
  align-items: center

/*  ---end of michaPau's code --- */

  // the image may have variable width, I want it to take the entire space calculated by flexbox
  img
    width: 100%
    opacity: .5

  figure, img
    margin: 0
    padding: 0
Prevent wrapping in CSS Flexbox

Prevent wrapping in CSS Flexbox


By : baimo
Date : March 29 2020, 07:55 AM
this one helps. When it comes to Flexbox, you need to set min-width: 0 or overflow: hidden to every level, down from the child of the element with the width constraint, to the one having ellipsis.
So in this case, from the sidebar's child, and the reason is that a flex item's min-width defaults to auto, which mean it can't be smaller than its content.
code :
const resizeHandle = document.getElementsByClassName("vertical-resize")[0];
const navbar = document.getElementById('sidebar');

function resizeNavbar(e) {
  let size = (e.pageX + 5);

  navbar.style.width = (e.pageX + 5) + "px";
}

function removeEvents() {
  document.removeEventListener('mousemove', resizeNavbar);
  document.removeEventListener('mouseup', resizeNavbar);
}

resizeHandle.addEventListener('mousedown', () => {
  document.addEventListener('mousemove', resizeNavbar);
  document.addEventListener('mouseup', removeEvents);
});
* {
  user-select: none;
  color: #dadada;
}

.flex-ellipsis {
  min-width: 0;                          /*  added  */
  /* or overflow: hidden; */
}

p,
h6 {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.rounded-circle {
  border-radius: 50% !important;
}

.no-margin {
  margin: 0 !important;
}

.column {
  flex-basis: 0;
  max-width: 100%;
  flex-grow: 1;
  background: #4a4a4a;
}

.column-1 {
  flex: 0 0 8.33333%;
  max-width: 8.33333%;
}

.row {
  display: flex;
  flex-wrap: nowrap; /*Even though no-wrap it still wraps as shown in picture.*/
  /*margin: 0 -1rem;*/
}

.custom {
  margin: auto;
  padding: 10px 0px;
  flex-wrap: nowrap;
}

.vertical-resize {
  position: relative;
  right: 0;
  top: 0;
  cursor: col-resize;
  width: 5px;
  background: aquamarine;
  height: 100vh;
}
<div class="row">
  <div id="sidebar" style="width: 570px;">
    <div class="align-items-center row custom flex-ellipsis" id="sidebar">
      <div style="max-width: 2.5rem;" class="column-1">
        <img class="rounded-circle" style="max-width: 28px; min-width: 28px;" alt="Avatar" src="https://d30y9cdsu7xlg0.cloudfront.net/png/138926-200.png">
      </div>
      <div class="column flex-ellipsis">
        <div class="row">
          <div class="column">
            <p class="no-margin">Ahmed Tarek</p>
          </div>
        </div>
        <div class="row flex-ellipsis">
          <div class="column flex-ellipsis">
            <h6 style="font-size: 11px;" class="no-margin">01 January, 0001</h6>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="vertical-resize"></div>
  <div class="column">

  </div>
</div>
Shrink images to fit in flexbox with wrapping rows

Shrink images to fit in flexbox with wrapping rows


By : Ronald
Date : March 29 2020, 07:55 AM
Any of those help
If I set flex-flow to row wrap and flex to 1 1 auto, the images are too big.
Flexbox wrapping nested rows without media query

Flexbox wrapping nested rows without media query


By : le piette
Date : March 29 2020, 07:55 AM
Any of those help You need to tell the children-elements of .grid .grid to flow in a row:
Related Posts Related Posts :
  • Can anyone see where I'm going wrong with this srcset?
  • Why is this SVG so blurry?
  • Dynamic multiple charts in chart.js with dynamic data inside them
  • How to set equal amount of spacing from the font awesome icon or text using css
  • Empty input shown as brackets when using RenderControl ASP.NET VB HTML
  • Bootstrap - section and div positioning
  • Easy HTML button "border"
  • Jumping background
  • align icon on top of text inside button tag
  • Working with local language in HTML
  • Mobile responsive design--> Img-responsive not working
  • Display a fix number of row item depending on screen size using bootstrap
  • EditorConfig for VS Code not working
  • Make second image 50% smaller than first with CSS
  • CSS Align logo same height as text
  • How can I write this layout with flexbox?
  • Truncating an individual block of text within a list item
  • Making Wordpress Site 100% Browser Width
  • Move links within a navbar
  • Float div left and button right
  • Vertically and horizontally centering two items within a parent div that is part of a flex-row
  • Why images and text with links keep moving on hover
  • How do I make different buttons in css?
  • Input border effecting the position of span why?
  • bootstrap.min.css X in top right corner
  • Why can browsers infer certain omitted HTML elements, but not all omitted elements required to form valid markup?
  • Strange behaviour involving Closure commands and "text-align:justify"
  • Using html, css to create a google search page look alike
  • Get button to hover over image
  • How to use CSS to give a circle a "partial border"
  • Float left vs float right - why does the order change?
  • css vertical align not working correctly
  • Bootstrap 4 grid issue
  • Eliminate margin when commenting
  • CSS Properties rules are not working in HTML file
  • Position footer div at bottom inside table-cell with 100% width
  • How to align one element to bottom and other one to top in bootstrap 4
  • Using Bootstrap, how do I center my navigation bar?
  • VBA Excel Content into HTML (create an HTML file from Excel)
  • minimum height of div and contents at least 100%
  • Absolute position div goes out of window when opening console
  • Make my background-image in the middle
  • Bootstrap col-sm-6 icons alignment
  • Nav bar won't stay in header when made smaller. How can I achieve this?
  • How to right align a hyperlink in a <div>?
  • Links with tables doesn't quite work
  • How to make <tr>'s height of position:fixed column follow its content's height?
  • Is an empty meta refresh tag ignored or equivalent to 0?
  • CSS How can I make this height responsive?
  • DIV moves when it has children elements
  • How to set first table column as bold (CSS)
  • Bootstrap Fieldset Legend is getting Covered by Panel Panel-default completely
  • Blogspot remove black line above posts
  • Usage of picture tag for svg types
  • Angular 4 toggle fontawesome button inside ngFor
  • CSS code not working on one single page
  • Place footer on bottom page while printing
  • Google maps API doesn't change language
  • Fade out previous :target after :target changed
  • Display flex, make image same height with another columns
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org