1

I am trying to use different CSS Stylesheets for different layouts (as you have already guessed from the title) but unfortunately nothing is working.

I tried loading the CSS file

 <link rel="stylesheet" href="css/medium-main.css" type="text/css" media="screen and (max-width: 800px)" />

in the meta tag and I also tried using

@media (min-width: 401px) and (max-width: 800px) {
.page{max-width:730px; margin:0 auto; display: block; height:850px;  float:left; }
  }

in the main css file but no changes occur.

This is how my header looks like:

    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/image-slides.css" type="text/css">
    <link rel="stylesheet" href="css/jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="css/main.css" type="text/css" />
    <link rel="stylesheet" href="css/medium-main.css" type="text/css" media="screen and (max-width: 800px)" />

The CSS property that I am trying to change is a simple's div's width and so when I resize the browser nothing happens.

What is wrong with my code?

9
  • 4
    Can you reproduce this with jsfiddle.com or jsbin.com? Commented Aug 27, 2013 at 15:58
  • what browser are you trying this on? also when you inspect the page div, is your styles getting overridden or does it not appear at all Commented Aug 27, 2013 at 16:01
  • Is literally nothing working? cause you may have mistyped the path of the css file somewhere. Also is the bootstrap's css media queries interfering with your media query? Commented Aug 27, 2013 at 16:01
  • @Huangism this is happeing in firefox Commented Aug 27, 2013 at 16:07
  • 1
    @ak_47 It works just fine. Commented Aug 27, 2013 at 16:11

5 Answers 5

10

Is your HTML properly set as such:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Title</title>
</head>
<body>
    //stuff
</body>
</html>

Use:

@media screen and (min-width: 401px) and (max-width: 800px) { … }

Instead of:

@media (min-width: 401px) and (max-width: 800px) { … }
Sign up to request clarification or add additional context in comments.

1 Comment

It's embarrassing how many times I've had to Google this only to remember I'm missing my <meta name="viewport" ...> tag...
5

you can simply try the code like following to make your site responsive to make changes on phone view as well on resizing , I don't think where are exactly making bug in your code , but the given code works for me well :

<link rel='stylesheet' media='screen and (max-width: 700px)' href='stylesheets/narrow.css' />
<link rel='stylesheet' media='screen and (min-width: 701px) and (max-width: 900px)' href='stylesheets/medium.css' />
<link rel='stylesheet' media='screen and (min-width: 901px)' href='stylesheets/wide.css' />

Comments

5

I think that is the way of ordering code.

Original CSS code should be placed first, then other screen with @media ordered by size:

...original CSS code...

@media(max-width:300px) {...}  

@media(max-width:533px) {...}  

@media(max-width:640px) {...}  

Comments

0

try this

@media all  and (min-width: 401px) and (max-width: 800px) {
    /*your code here*/
}

Comments

-1
<meta name="viewport" content="width=device-width">

Here is an example. It is responsive design.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.