Make Unordered list rensponsive with Flex box

Make Unordered list rensponsive with Flex box



I have app in which I'm using a flex box to display 8 list items that will dynamically resize with my page. How do I force it to split the items into two rows? (4 per row)?



Here is jsfiddle : https://jsfiddle.net/Mwanitete/ge36dcf8/15/




.parent
display: flex;
flex-wrap: wrap;

.child
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style: none;
flex: 1 0 20%;
margin: 5px;
height: 100px;


<div class="parent">
<ul class="child">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>
</div>





I'm not sure what result you are looking for. The point of flexbox is that it can size and wrap elements dynamically. If you just wanted to have two rows with 4 elements each, you don't need it, just set display: inline-block; width: 25% on the li elements (see also stackoverflow.com/questions/29546550/… )
– matejcik
Aug 23 at 7:39


display: inline-block; width: 25%


li





@matejcik I need to use flexbox , thanks
– user9964622
Aug 23 at 12:41




3 Answers
3



have a look at this (almost) exhaustive tutorial to be able to use the full power of flexbox. I got this result:




.parent
font-family: Arial, sans-serif;
font-size: 12px;


.child
display: flex;
flex-wrap: wrap;
list-style-type: none;
margin: 5px;
padding: 0;
height: 100px;


.child li
width: 23%;
height: 49px;
margin: 1px 1%;
text-align: center;
background: #069;
color: #fff;
display: flex;
align-items: center;
justify-content: center;


<div class="parent">
<ul class="child">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>
</div>



Is it (similar to) what you want?





Perfect solution , thanks bro
– user9964622
Aug 23 at 12:45



Reduce the max-width of the div.parent based on the media query
Ex :


@media(min-width: 1100px)
.parent
max-width: 500px;



@media(max-width: 1099px)
.parent
max-width: 250px;




Note: this is just an example, you should change the max-width based on the ul li content





not this is not prooper solution though
– user9964622
Aug 23 at 12:44



I had a similar problem some time ago and was able to solve it with this code. I hope it'll help you.




*
box-sizing: border-box;


.parent
display: flex;
flex-wrap: wrap;


.child
display: flex;
flex-direction: row;
flex-wrap: wrap;
height: 100px;
padding: 0;
margin: 0 auto;


.child li
padding: 10px 20px;
background: #111;
color: #fff;
width: 25%;
text-align: center;
border: 5px solid #fff;
list-style: none;


<div class="parent">
<ul class="child">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>
</div>





hii did you test your code? Its not working , try it yourself , here is fiddle jsfiddle.net/Mwanitete/ge36dcf8/118
– user9964622
Aug 23 at 12:44





I have updated new code. Easier now ;)
– Nacorga
Aug 23 at 13:26







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ