How do I change the CSS for a specific element on a web page?
This tutorial will use Firefox and focus on how to troubleshoot/test your CSS. Firebug, a once popular debugging extension for Firefox, is no longer being actively developed or maintained. The Firebug developer now recommends using the built-in Firefox developer tools, of which the CSS inspector is a component. Mozilla offers a developer version of Firefox that contains the latest and greatest tool set. Chrome offers its latest features in Chrome Canary. Be forewarned though, both Firefox Developer Edition and Chrome Canary are bleeding edge browsers with experimental features. Both are considered unstable and may be subject to crashing.
Inspect Tool is a Right Click Away
- To get started, hover over an element you want to inspect and right click on it.
- Click Inspect Element
We'll be examining one of the links in this article. The image below shows the result of hovering over the Chrome DevTools link, using right click, and selecting inspect element. The large numbers in the image have been added for clarity.
Wow! That's a lot to absorb. What are we looking at exactly?
- Live page in the browser
- HTML source code window
- CSS window
Windows 1, 2, and 3 allow you to scroll them independently. Windows 2 and 3 are linked so that when you click on an element in the HTML source code window, the CSS applied to that element will display in the CSS window.
In the browser window, the Chrome DevTools link is blue. When you hover over it, it turns black. Look at the CSS on the right, the blue color is applied from a class called .parallax-pro-blue a. This class can be found in my child theme's style.css file at line 2157. In Firefox, the active class is highlighted in blue and the file name and line number at which the class can be found can be seen to the right of the class. Classes that impact hover or other momentary changes, may not be readily visible in the CSS window. For those classes, you have to edit the style sheet to find them.
A really neat feature of the CSS inspection tool is that you can perform non-destructive testing to try different CSS directives for any element on a page. The CSS inspection tool is also an editor. By non-destructive, I mean it doesn't permanently change anything in your style sheet. It only changes things for your current browser session. You can experiment with padding, margins, colors, or any CSS directive you'd like. If you make a mistake or don't like the results, simply refresh the page in the browser and everything returns back to normal. Once you've tweaked the CSS exactly as you want it, copy your changes to the style sheet in your code editor and save it.