简体   繁体   中英

Make the List to be responsive design

Goal:
Make the list (ul and its li) to be responsive design in relation to the screen's width.

Problem:
I don't know how to solve it.

Info:
*You need to take account to amount of li in each ul list. Different responsive design depends on the width of the ul.
*Each ul can be random from 1 to 10 li or more.

JSBin:
https://jsbin.com/xibalahave/edit?html,css,output

Thank you!


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div class="aaa">
    <ul class="listlist">
      <li>1Test 1</li>
      <li>1Test 2</li>
      <li>1Test 3</li>
    </ul>
  </div>
  <br />
  <div class="aaa">
    <ul class="listlist">
      <li>1Test 1</li>
      <li>1Test 2</li>
      <li>1Test 3</li>
      <li>1Test 4</li>      
    </ul>
  </div>  
  <br />
  <div class="aaa">
    <ul class="listlist">
      <li>1Test 1</li>
      <li>1Test 2</li>
    </ul>
  </div> 
  
</body>
</html>

.aaa ul.listlist{
    margin: 10px 0 16px;
    padding: 0;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
}

.aaa ul.listlist li {
  font-size: 1.125rem;
  display: block;  
  margin-right: 24px;
  line-height: 22px;
  border-radius: 12px 12px 12px 12px;  
  padding: 8px 24px;
  background-color: #00FFFF;
  white-space: nowrap;
}

You can simply add a "flexwrap: wrap;" to the container of the "li", it will allow the child-elements (here, li), to go to another line. I invite you to learn about the flexbox and all theirs properties, this is very helpful for the responsive design ! https://css-tricks.com/snippets/css/a-guide-to-flexbox/

.listlist{
  display: flex;
  flex-wrap: wrap;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM