Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide. This can be used to target specific devices with known widths.
Max-width : max -width means less than or equal to the width specified in that media query. So, in above example element which has “#ButtonWrapper” as the Id, will get width of 70% to all the screens widths which are less than or equal to 1024px.
The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.
@media screen and (max-width:632px) This one is saying for a device with a screen and a window with max-width of 632px apply the style. This is almost identical to the above except you are specifying screen as opposed to the other available media types the most common other one being print .
That’s a media query. It prevents the CSS inside it from being run unless the browser passes the tests it contains.
The tests in this media query are:
@media screen
— The browser identifies itself as being in the “screen” category. This roughly means the browser considers itself desktop-class — as opposed to e.g. an older mobile phone browser (note that the iPhone, and other smartphone browsers, do identify themselves as being in the screen category), or a screenreader — and that it’s displaying the page on-screen, rather than printing it.
max-width: 1024px
— the width of the browser window (including the scroll bar) is 1024 pixels or less. (CSS pixels, not device pixels.)
That second test suggests this is intended to limit the CSS to the iPad, iPhone, and similar devices (because some older browsers don’t support max-width
in media queries, and a lot of desktop browsers are run wider than 1024 pixels).
However, it will also apply to desktop browser windows less than 1024 pixels wide, in browsers that support the max-width
media query.
Here’s the Media Queries spec, it’s pretty readable:
It's limiting the styles defined there to the screen (e.g. not print or some other media) and is further limiting the scope to viewports which are 1024px or less in width.
http://www.css3.info/preview/media-queries/
It says: When the page render on the screen at a resolution of max 1024 pixels in width then apply the rule that follow.
As you may already know in fact you can target some CSS to a media type that can be one of handheld, screen, printer and so on.
Have a look here for details..
In my case I wanted to center my logo on a website when the browser has 800px
or less, then I did this by using the @media
tag:
@media screen and (max-width: 800px) {
#logo {
float: none;
margin: 0;
text-align: center;
display: block;
width: auto;
}
}
It worked for me, hope somebody find this solution useful. :) For more information see this.
That's Media Queries. It allows you to apply part of CSS rules only to the specific devices on specific configuration.
It means if the screen size is 1024 then only apply below CSS rules.
If your media query condition is true then your CSS with that condition will work. That means CSS within your media query's condition pixel size will effect, or else if the condition will fail that mean if the device's width is greater than 1024px than your CSS will not work.Because your media query condition false.
max-width
is your max CSS limit till that width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With