0

I got some divs with a fixed width and height and they should push to left to all size of screen

What I want to achive is that based on resoulotion I want to show/hide some of them.

Fiddle

For example:

  • 1024px - show 3 elements
  • 1400px - show 5 elements

What is the best way to do this?

Here's my CSS:

.square{
  width:200px;
  height:200px;
  background:salmon;
  margin:5px;
  float:right;
}

.container{
  position:relative;
}

.wrapper-div{
  position: absolute;
  width: 1000px;
  transform: translateX(-50%);
  left: 50%; 
}
AlbertoFdzM
  • 1,023
  • 11
  • 24
Sadeghbayan
  • 1,163
  • 2
  • 18
  • 38

2 Answers2

1

Yes this could be done easily with @media-queries.

A simple example of media queries are:

In the head of your html page you do:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

And the divs with the content:

<div class="square">

</div>

The css will look like this:

 @media (max-width:1024px) and (min-width:0px) {
    .square{
         your css width and etc..
    }
}​

  @media (max-width:1400px) and (min-width:1025px) {
    .square{
         your css width and etc..
    }
}​

More about it HERE

Ananthakumar
  • 323
  • 1
  • 14
0

You should combine the media queries with :nth-child() to handle that

CSS example code:

.square {
  /* Your square css */
}

@media (max-width: 1024px) {
  /* left displayed only the first 3th blocks */
  .square:nth-child(n+4) {
    display: none;
    visibility: hidden;
  }
}​

@media (min-width: 1400px) {
  /* left displayed only the first 5th blocks */
  .square:nth-child(n+6) {
    display: none;
    visibility: hidden;
  }
}​
AlbertoFdzM
  • 1,023
  • 11
  • 24