0

I have website that with several divs. One of those divs need to be a specific with but this can variabate between 2 width. Is it possible some how to get it to only allow 2 width?

Examaple:

With resolution of page >= 700px  div width = 500px   
when page resolution < 700px  div width = 200px
joey
  • 469
  • 1
  • 6
  • 22
  • 1
    Use CSS media queries – Zword Jan 02 '15 at 10:38
  • possible duplicate of [Media Queries: How to target desktop, tablet and mobile?](http://stackoverflow.com/questions/6370690/media-queries-how-to-target-desktop-tablet-and-mobile) – Zword Jan 02 '15 at 10:42

2 Answers2

2

Use css media query like @media only screen and (max-width: 300px)

when you add

@media screen and (max-width: 300px) {
        body {
            background-color: lightblue;
        }

When you add like this when width is 300px it will automatically change to rule you added

A simple example

   <!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: lightgreen;
}

@media screen and (max-width: 300px) {
    body {
        background-color: lightblue;
    }
}
</style>
</head>
<body>

<p>Resize the browserwindow. When the width of this document is less than 300 pixels, the background-color is "lightblue", otherwise it is "lightgreen".</p>

</body>
</html>

Answer

@media screen and (max-width: 700px  ) {
            div{
                width: 500px;
            }

@media screen and (min-width: 700px  ) {
            div{
                width: 200px;
            }
sanoj lawrence
  • 951
  • 5
  • 29
  • 69
1

Use media queries:

@media only screen and (min-width: 700px) {
    .my-div {
        width: 500px;
    }
}
jeremyb
  • 470
  • 4
  • 12