Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter CSS Media Queries in Chrome Developer Tools

Pressing F12 I can instantly change CSS of elements in Chrome. However, I can not input @media screen and (max-width) similar to here:

http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

When I press enter it simply disappears. What can I do to dynamically add and remove media queries?

enter image description here

like image 384
user1506145 Avatar asked Jan 21 '15 14:01

user1506145


People also ask

How do I add CSS to Chrome dev tools?

Go to element panel ( Ctrl + Shift + p and type show element panel). Scroll to the head element right click on the element and choose Edit as HTML, go to the bottom of that element ( Ctrl + End ), add your <style></style> element there add your style in that element, and hit Ctrl + Enter .

Where do you put CSS media queries?

Important: Always put your media queries at the end of your CSS file.

How do I add a media query to a chrome page?

On Chrome, you will need to edit the inspector stylesheet directly in order to include your media queries. You can reach it by going to the Sources panel and choosing inspector-stylesheet. Since this involves writing CSS, you will need to select the element.

How do I view an element's CSS in DevTools?

See View an element's CSS for a tutorial. In your viewport, right-click the element and select Inspect. In DevTools, click Select an element or press Command + Shift + C (Mac) or Control + Shift + C (Windows, Linux), and then click the element in the viewport.

How do I add media queries to the Inspector?

On Chrome, you will need to edit the inspector stylesheet directly in order to include your media queries. You can reach it by going to the Sources panel and choosing inspector-stylesheet.

How can I view the source code of a media query?

You can also right-click over a selected media query and see it directly on the source code. If you want to see all media queries in action at the same time I'll recommend you take a look at Responsively. It's an amazing and open source project that will make your job easier as a developer. That’s All Folks! Hey Camilo!


3 Answers

When you edit the styles for a specific element in the inspector, it is as though you were editing the element's inline style attribute: you can only place property declarations such as color: red in your example. This is even reflected in the DOM visualization itself as you edit an element's styles. Media queries don't belong in inline styles, they belong in @media rules which appear only in a proper stylesheet.

On Chrome, you will need to edit the inspector stylesheet directly in order to include your media queries. You can reach it by going to the Sources panel and choosing inspector-stylesheet.

Since this involves writing CSS, you will need to select the element. You can (usually) get a unique CSS selector for the element you choose by right-clicking it in the Elements panel and choosing Copy CSS path.

Then just write your CSS:

@media screen and (max-width: 300px) {
    /* selector for your element */ { color: red; }
}
like image 179
BoltClock Avatar answered Oct 19 '22 00:10

BoltClock


You can use New Style Rule. Click on Plus symbol (+) besides .cls.

enter image description here

and then, you'll see it generates new class. Now click on inspector-stylesheet.

enter image description here

You will be redirect to Sources Tab with almost blank stylesheet. Now, you can put Media Queries in there.

enter image description here

like image 35
Daryl Malibiran Avatar answered Oct 19 '22 00:10

Daryl Malibiran


You can always add the CSS within style tags in the head section. Just edit the HTML by right-clicking on the html and select "Edit as HTML". For example,

<style>
    @media screen and (min-width: 0px) and (max-width: 400px) {
        body {
            background-color: red;
        }
    }
    @media screen and (min-width: 401px) and (max-width: 599px) {
        body {
            background-color: green;
        }
    }
    @media screen and (min-width: 600px) {
        body {
            background-color: blue;
        }
    }
</style>
like image 8
Choonkies Avatar answered Oct 18 '22 22:10

Choonkies