10/08/04

Comments 24

Tweaking Firefox with CSS

I’ve only recently discovered the power of Mozilla’s ‘user content’ files that reside in the profile directory. I’d created a user.js file to add preferences for things like pipelining, but I’d never looked into the others – ‘userChrome.css’ (for tweaking the interface), and ‘userContent.css’ (for tweaking the web page display).

Here are the tweaks and customisation that I’ve done to my copy of Firefox to give you an idea. First of all, make life easy for yourself and install Chris Neale’s ChromEdit extension. This allows you to edit the user files from within Firefox. Once you’ve restarted, ‘Edit User Files’ will appear under the Tools menu.

userChrome.css

Firefox is a an XUL application which means that the display of the interface is controlled by the same CSS we all know and love. The only real hard part is finding the name for each element – something that DOM Inspector tool is good at revealing.

Copy and paste this first example into userChrome.css, and the changes will take effect when Firefox is restarted.

download {
 border-bottom: 0px !important;
}

This removes the dashed line beneath each item in the Download Manager. By giving the rule priority – !important; – we can make sure that this overrides rules in the default theme. This one prevents the ‘throbber’ (spinny thing on the OS X toolbar) from displaying, something thats hard to get rid of:

#throbber-box {
    display: none !important;
 }

This also makes it easy to make small interface tweaks without having to create a special theme. In order to know what rules to overide, you might find it easier to find the classic.jar file inside Firefox>Contents>MacOS>Chrome and unzip it. This is where all the pinstripe theme CSS is kept.

Here, I’ve changed the appearance of the tabs slightly with new images to make the corners less rounded.

New Tabs

tab[selected="true"] > .tab-image-right {
    background: url(activetab-right.png) no-repeat !important;
}
tab[selected="true"] > .tab-image-left {
    background: url(activetab-left.png) no-repeat !important;
}
tab[selected="true"] > .tab-image-middle {
    background: url(activetab-middle.png) repeat-x !important;
}

Place the images into your Firefox profile directory:
(users> you> Library> Application Support> Firefox> Profiles> yourprofilenumber> chrome>).

userContent.css

With this file, we’re going to try and improve Firefox OS X’s form widgets. If you’re unfamiliar with the term ‘widgets’, it refers to the various form elements – input, textarea, select etc. These aren’t native in the OS X version, and they may never be, but here are some rules that you can drop into the userContent.css file to improve the form buttons a little:

input[type="button"],
input[type="submit"] {
    font-size: 12px !important;
    font-family: 'Lucida Grande' !important;
    background: #eee !important;
    -moz-border-radius: 18px !important;
    padding: 1px 6px !important;
    border: 1px solid #ccc !important;
    border-bottom: 2px solid #999 !important;
}

Here’s the result:

Input butttons

Unfortunately, the aliasing on a Mac is a bit ropey, so keeping the border quite light helps to hide this a little bit. Its something that I’m sure someone can take further, but at least its an improvement on the older PC style widgets. (Anyone know of a way of applying a background image to an ?!).

I’ve also had a go at form fields, but there is less you can do with these. If you use these rules then at least they don’t have that harsh appearance:

textfields

input[type="text"],
textarea {
    font-size: 12px !important;
    padding: 1px 3px !important;
    font-family: 'Lucida Grande' !important;
    border: 1px solid #999 !important;
    border-bottom: 1px solid #ddd !important;
    border-left: 2px solid #c3c3c3 !important;
    border-right: 2px solid #c3c3c3 !important;
    border-top: 2px solid #989898 !important;
}

Technorati TagsTags: , , ,

Comments | RSS

#1

Krzysztof said 1490 days ago:

my favourite in the userContent.css:
iframe[name=”google_ads_frame”] {display: none !important;}
#2

Greg K Nicholson said 1490 days ago:

“This one prevents the ‘throbber’ (spinny thing on the OS X toolbar) from displaying, something thats hard to get rid of:”

On OS X can you not open the Customise Toolbars dialogue and just drag the throbber off the toolbar? I can on Windows.
#3

Neil said 1490 days ago:

Very awesome – thanks for spending the time to work out these changes. Do you have the image files available that you used to tweak the tabs appearance?

Neil
#4

Paul D said 1490 days ago:

Is that what Firefox buttons look like in OS X? Pretty ugly, so I think I’ll be sticking to Safari and Camino for the time being.
#5

Philippe said 1490 days ago:

input[type="text"] {background:url(../path/to/img/img.png) repeat-x 100% 100%}

userChrome.css and userContents.css are awesome. Making the text in the statusbar bigger and readable for me:
@.statusbarpanel-text {
font-size:13px !important;
}@
#6

Philippe said 1490 days ago:

Textile having a problem ? The text between @ should be displayed as code.
#7

Minh Nguyá»…n said 1490 days ago:

So if you set buttons to have moz-appearance: button, will they still look PC-like? Or will they have the Aqua look?
#8

Mary said 1490 days ago:

Re: (Anyone know of a way of applying a background image to an input?!).

“Fun with forms – customized input elements”
http://picment.com/articles/css/funwithforms/
#9

Jon Hicks said 1490 days ago:

Krzysztof – Thats genius! Thanks!

Greg – Its supposed to be removable that way, but it seems that there is a bug in the OS X version.

Paul D – Thats what they look like after tweaking. They looked worse before! (Think Netscape 4 on Windows).

Neil – Tabs images are available from here.

Minh – thats what they are currently specified as, and you just get the standard buttons. Here’s why

Phillipe & Mary – thanks for that! Maybe we can improve on these after all!
#10

Mike Stenhouse said 1490 days ago:

I’d looked at these files but it hadn’t actually occurred to me to do anything with them… Thanks for this up Jon!

Another thing that occurred to me when I was browsing through my Mozilla install a little white back was that EVERYTHING seems to be styled with CSS. The two files that stick out are html.css that defines the default behaviour for every HTML element – this is a proper next-level application for CSS as a technology, and viewsource.css that controls the colour highlighting in ‘View Source’ – could make your life as a developer easier… What a great program!
#11

Krzysztof said 1490 days ago:

More Tips & Tricks on the Firefox Help website.

Scrollbar tweaks and Firefox Dust articles from cheeaunblog are also very nice.
#12

Chris said 1490 days ago:

Weird.

I added the tab code, changed the locations and obviously downloaded the images. But Firefox 0.9.3 on Win 2k pro doesn’t pick up the changes!

Anyone else having problems with that?
#13

Jon Hicks said 1490 days ago:

Chris, the replacement code here is based on the OS X pinstripe theme, so may not work on Windows.
#14

Paul Griffin said 1490 days ago:

Oh man, good stuff. You can apply :focus rules to the button code above if you want to make them look like they are actually pressed when you click on them:

input[type=”button”]:focus,
input[type=”submit”]:focus {
border-top: 2px solid #999 !important;
border-bottom: 1px solid #ccc !important;
}

Also fun, keep track of what form element you’re on:

input[type=”text”],
textarea {
background:#ddd !important;
}
input[type=”text”]:focus,
textarea:focus {
background:#fff !important;
}
#15

Jon Hicks said 1490 days ago:

Great. I’ve now managed to get the textfields and buttons looking very OSX with background images. I’ll update the post when I get a chance!
#16

Brian Warren said 1490 days ago:

In my latest downloads of Firefox, the default theme isn’t pinstripe. Where can I find that?
#17

Rob Cameron said 1490 days ago:

“The only real hard part is finding the name for each element – something that DOM Inspector tool is good at revealing.”

How do you get the DOM Inspector to show you this stuff?
#18

Laurens Holst said 1490 days ago:

About -moz-border-radius: “Unfortunately, the aliasing on a Mac is a bit ropey,”...

That’s the case on Windows as well. Border-radius is a new CSS3 style property, and to me it seems to work just fine except for the anti-aliasing… I guess that’s why they’re still keeping it in their private moz ‘namespace’ instead of renaming it to the CSS3 name, like they did with -moz-opacity in Firefox 0.9/Moz 1.7… (or maybe it has to do with the css3-border spec still being in working draft status… more likely actually :))

~Grauw

~Grauw
#19

Jon Hicks said 1490 days ago:

Rob – open up the Dom inspector, and then on the main menu go to File>Inspect a window> and choose the window you want to look at. This works for the main browser window, as well as Downloads, Extensions etc. You can the the view the DOM tree of each of the windows.

Grauw – Interesting, I thought it was better on my PC. I think the -moz name it’s because its still at draft status.
#20

Seamus said 1488 days ago:

I am trying to remember this hack used on a laptop I used to use. Since space was a much needed thing on the screen, I wanted only the refresh button to show or the stop button to show. I first placed the stop button right after the refresh button.

@
toolbarbutton#stop-button[disabled=true],
toolbarbutton#reload-button[disabled=true]
{
display: none;
}

@
#21

mmmbeer said 1487 days ago:

Let’s not for the the all important:

/* just plain annoying things */
marquee { display: none !important; }
blink { text-decoration: none !important; }

/* add an e-mail icon to mailto: links */
a[href^=”mailto:”] { background: url(mail.gif) no-repeat top left !important; padding-left: 20px !important; }

/* always have an underline */
a:hover { text-decoration: underline !important; }
#22

Lem.dk said 1484 days ago:

/* add an e-mail icon to mailto: links */
a[href^=”mailto:”] { background: url(mail.gif) no-repeat top left !important; padding-left: 20px !important; }

OMG, thats great, since I just hate pressing a link, just to find out its a mail link.

It would be better if webdevolepers just did it them self by default :)

Thanks for the great article, Im just gonna go mess a little around with Firefox now :D
#23

Chris Biagini said 1480 days ago:

I’ve been trying myself to hack at this, specifically for buttons. `-moz-appearance: button` would be ideal, but it doesn’t seem to work… Setting the background of a button to a screen grab of an Aqua button sort of works, but `-moz-border-radius` is so ugly that it kills the effect. By the way, you don’t need the full path to the image file if it’s in the same directory as userContent.css.

It would be nice if the default theme were a little more inspired than an outset border…What gets me is that faked Aqua buttons are used elsewhere, so FF is certainly capable of displaying them. There must be some reason that they’re not used in page content.
#24

Chris Biagini said 1480 days ago:

Bah, I apologize—I just saw the reason for non-native widgets that Jon posted.

I’m not sure if I’m sold yet, though. Safari loses the ability to display styled buttons, but I’m sure there’s a compromise somewhere. Perhaps it’s a simple as displaying a native button unless the designer specifies certain properties for it. Safari even applies some properties (like font size) to native widgets.

And also, that document doesn’t address why buttons look non-native. The UI of Firefox itself isn’t using real, native buttons, but they look pretty darn close.

Elsewhere

The Rissington Podcast - weekly shenanigans with Jon Oxton

Hicksmade - unique handmade goods by Leigh Hicks width=

love

Brit Pack: A proud member I love Omniweb Coda Segment Publishing I buy my type from Veer The Forgiveness Project