Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use CSS to display only three items on a mobile device

If I have a screen that will display 6 items in the computer version, but below the mobile device (414px), only three will be displayed.

Is there a way to achieve this effect through css if the HTML structure is not changed?

.list {
  width: 300px;
}
.list .item {
  width: 100%;
  text-align: center;
  padding: 16px;
  background-color: #fed71a;
}
<ul class="list">
   <li class="item">about1</li>
   <li class="item">about1</li>
   <li class="item">about1</li>
   <li class="item">about1</li>
   <li class="item">about1</li>
   <li class="item">about1</li>
</ul>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here you go.

.list {
  width: 300px;
}

.list .item {
  width: 100%;
  text-align: center;
  padding: 16px;
  background-color: #fed71a;
  list-style: none;
  margin-bottom: 1px;
}

@media (max-width: 414px) {
  .item:nth-child(4),
  .item:nth-child(5),
  .item:nth-child(6) {
    display: none;
  }
}
<ul class="list">
  <li class="item">about1</li>
  <li class="item">about1</li>
  <li class="item">about1</li>
  <li class="item">about1</li>
  <li class="item">about1</li>
  <li class="item">about1</li>
</ul>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading