Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flex-wrap: wrap not working on mobile iOS

I have this that works fine on my laptop, but not on mobile iOS.

* {
  /* normalize */
  padding: 0;
  margin: 0;
  border: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-transform: inherit;
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
  background: 0 0;
  min-height: 0;
  user-select: none;
  box-sizing: border-box;
  position: relative;
}

#a {
  display: flex;
  max-width: 100vw;
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh)*100);
}

#b {
  display: flex;
  height: 100%;
  flex: 1;
  flex-direction: column;
  padding: 50px;
}

#c {
  flex-wrap: wrap;
  flex-direction: row;
  max-width: 100%;
  display: flex;
  list-style: none;
}

li {
  flex: 1;
  width: 100%;
  display: flex;
  padding: 10px;
  border: 3px solid red;
  flex-direction: column;
}
<div id="a">
  <div id="b">
    <ul id="c">
      <li>foo</li>
      <li>hello</li>
      <li>world</li>
      <li>bar</li>
      <li>food</li>
      <li>hi</li>
      <li>morning</li>
      <li>something</li>
      <li>beverage</li>
      <li>snack</li>
      <li>drink</li>
      <li>other</li>
      <li>world</li>
      <li>bar</li>
      <li>food</li>
      <li>hi</li>
      <li>morning</li>
      <li>something</li>
      <li>beverage</li>
      <li>snack</li>
      <li>drink</li>
      <li>other</li>
    </ul>
  </div>
</div>

However, on mobile it as a few rows, but mostly it overflows to the right. Like it will have 2 or 3 rows but then 15 or 20 items per row (when only 2 or 3 fit on screen). I haven't been able to get it working since I don't have a good system to debug on mobile.

like image 586
Lance Avatar asked Jun 10 '19 02:06

Lance


People also ask

What is the difference between flex-wrap and nowrap?

The flex-wrap property accepts 3 different values: 1 nowrap ( default ): single-line which may cause the container to overflow 2 wrap: multi-lines, direction is defined by flex-direction 3 wrap-reverse: multi-lines, opposite to direction defined by flex-direction

What does-WebKit-flex-wrap mean in Safari?

.page-id-57 .row { display: -webkit-flex; /* Safari */ -webkit-flex-wrap: wrap; /* Safari 6.1+ */ display: flex; flex-wrap: wrap; } It’s the before and after pseudo elements that are adding to the width in Safari and making the 50% item only big enough for one item per row.

What is the difference between flex wrap and wrap reverse?

The flex-wrap property accepts 3 different values: nowrap (default): single-line which may cause the container to overflow. wrap: multi-lines, direction is defined by flex-direction. wrap-reverse: multi-lines, opposite to direction defined by flex-direction.

What is the flex-wrap property in CSS?

Special welcome offer: get $100 of free credit . The flex-wrap property is a sub-property of the Flexible Box Layout module. It defines whether the flex items are forced in a single line or can be flowed into multiple lines. If set to multiple lines, it also defines the cross-axis which determines the direction new lines are stacked in.


1 Answers

Update the style on li . Change flex: 1; to flex: 1 0 auto; and remove width: 100%

li {
  flex: 1 0 auto;
  /* width: 100%; */
  display: flex;
  padding: 10px;
  border: 3px solid red;
  flex-direction: column;
}

* {
  /* normalize */
  padding: 0;
  margin: 0;
  border: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-transform: inherit;
  font-family: inherit;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
  background: 0 0;
  min-height: 0;
  user-select: none;
  box-sizing: border-box;
  position: relative;
}

#a {
  display: flex;
  max-width: 100vw;
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh)*100);
}

#b {
  display: flex;
  height: 100%;
  flex: 1;
  flex-direction: column;
  padding: 50px;
}

#c {
  flex-wrap: wrap;
  flex-direction: row;
  max-width: 100%;
  display: flex;
  list-style: none;
}

li {
  flex: 1 0 auto;
  /* width: 100%; */
  display: flex;
  padding: 10px;
  border: 3px solid red;
  flex-direction: column;
}
<div id="a">
  <div id="b">
    <ul id="c">
      <li>foo</li>
      <li>hello</li>
      <li>world</li>
      <li>bar</li>
      <li>food</li>
      <li>hi</li>
      <li>morning</li>
      <li>something</li>
      <li>beverage</li>
      <li>snack</li>
      <li>drink</li>
      <li>other</li>
      <li>world</li>
      <li>bar</li>
      <li>food</li>
      <li>hi</li>
      <li>morning</li>
      <li>something</li>
      <li>beverage</li>
      <li>snack</li>
      <li>drink</li>
      <li>other</li>
    </ul>
  </div>
</div>

See updated fiddle

I tested it in iphone 6, IOS 10.3

like image 186
Nandita Sharma Avatar answered Nov 14 '22 23:11

Nandita Sharma