![]() |
|
![]() |
|||||||||||||||||||||||||||||||
Customize Your Web, StylishlyTable of Contents
Are You Prepared?StylishStylish is a Mozilla Firefox extension which allows easy installation, management and authoring of userstyles. UserstylesUserstyles are Cascading Style Sheet (CSS) rules which change the appearance of webpages in your web browser. Userstyles can be written and used in most modern web browsers, including Google Chrome (Chromium), Firefox, Safari, Internet Explorer (IE), Opera, and anything based upon Mozilla.
Is Stylish Installed?Stylish doesn't appear to be installed, but this text will always be shown unless JavaScript is enabled, and you follow these instructions: Firefox
OthersIn a Mozilla based web browser where Stylish has been installed, you may attempt the Firefox instructions given above. Otherwise, simply continue reading the document to learn about userstyles. Prerequisite Knowledge Top of this page.Authoring userstyles, with or without the Stylish Firefox extension, is not particularly easy. Doing so without knowledge of the web design concepts involved will be incredibly difficult. This tutorial does not assume you are fully studied in all of the web design technologies. If you become confused while learning to userstyle with Stylish Firefox extension, refer to this section of the tutorial to find the definitive texts in these subjects.
Suggested Tools Top of this page.
Mozilla's CSS Defaults Top of this page.You will learn how Firefox renders GUI (they call it, "chrome") and pages, by studying the prerequisite knowledge. A key clue is how markup languages are given their default behaviors. Some of the behavior is hard-coded into the software, since it is efficient to do that for some things. There is, however, a set of CSS files which define style defaults.
CSS Basics Top of this page.Cascading Stylesheets are given their name due to the ways they behave. A stylesheet defines the way in which some other document (an HTML file, in our case) should be rendered for display. In userstyles, we are using CSS to modify existing styles. This fact can immediately show you what is meant by, "cascading". Add to this understanding, the facts that web sites may define style inside the HTML document and inside the HTML tags, and in multiple separate stylesheets (as .css files). Also, remember that the web browser may use CSS to define the default size, shape, appearance, and behavior of HTML tags. In this way, you may see that rules are needed to decide the effect of two or more styles targeting the same element of an HTML document. Sometimes it is inefficient to replace a previously defined style with an entirely separate new one. For that, CSS allows the style rules to stack upon each other in ways which may cause them to combine with or negate each other. This stacking behavior is influenced by the order in which CSS rules are read by the web browser, the complexity of the selector used to target the affected element(s), and other factors which you will discover in due time. When written outside of the selected HTML tag, a CSS rule is formatted as is illustrated in the following diagram. When written inside of an HTML tag, the entire CSS rule is written on one line, the selector is omitted because the tag is already selected by the author, and the open/close curly brackets are replaced by the style="" attribute of the HTML tag.
Example Style explains what each piece of a CSS rule is meant to do, and how to use them in Stylish userstyles. Example Style Top of this page.
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("userstyles.org"),
url("http://blog.userstyles.org"),
url-prefix("http://userstyles.org/forum")
{
body
{
background: #999999 !important;
color: #000000 !important;
}
}
Whitespace is not consistent in most CSS or HTML code. The software which reads it is supposed to ignore whitespace. This is so that human writers of markup and style can use whitespace as their eyes demand, for legibility. Most important are the { brackets }, ( parenthesis ), "double-quotes", and semi-colons; they are telling the parser where each statement is, and how to understand it. Namespace@namespace url(http://www.w3.org/1999/xhtml); Part of: Example Style
You can see in section 6.1.1 of the CSS 3 Specification, that namespaces are used with selectors to explain different selector types, and to preserve the differences while mixing types in a single document. This is done so that we can do things like using XML inside of an HTML document, and then tell CSS how to style the XML differently than the HTML.
You can see this principle being used inside of Firefox, in
xul.css.
There are namespace declarations, such as: There is no 'xul' prefix between '@namespace' and 'url()', so any selector without a namespace prefix will be in the XUL namespace. To define a selector as being in HTML or XBL namespace, you need only prefix the selector correctly. @-moz-document
@-moz-document domain("userstyles.org"),
url("http://blog.userstyles.org"),
url-prefix("http://userstyles.org/forum")
Part of: Example Style
@-moz-document is a Mozilla Extension at-rule, used primarily in userstyles, which controls where a set of CSS rules are allowed to take effect. It takes a single parameter, which lets you select domains or subdomains. In CSS 3, there is still no way to do wildcard or negation on these. There can be multiple entries in the list, comma separated.
{
Part of: Example Style
Opens the document style. Selectors Top of this page.body Part of: Example Style
"body", is the node selector for applying this rule set. In this case, the <body> HTML tag is selected. Remember selector namespacing when choosing selectors in a document which may have multiple namespaces, and be sure you know which default namespace you are working in. Typically, in userstyles, we are working only in HTML and XUL namespaces. However, we do have to declare which one we are using; at the top of every userstyle sheet. For IDs, use #someid, for Classes, use .someclass.[class="someid"]or [id="someid"] Will be useful to remember, when someone (Google GMail) has used RFC Invalid ID and Class naming. Example tag: <input id="before-screenshot-none" name="before screenshot" type="radio" value=""></input> See it in DOM, in this screenshot, on the rightside. You could select such a node (tag) like this: input[id="before-screenshot-none"] Has to be an input with an id of before-screenshot-none. [id="before-screenshot-none"] Any with that id. #before-screenshot-none Same as [id="before-screenshot-none"] in meaning, but if they appeared together, applied to the same page (even if in separate files), CSS considers #before-screenshot-none to be more important, so uses it. That's called precedence. [id] Anything with an id. input Any inputs. [id$="screenshot-none"] Any id that ends with screenshot-none. [id$="before"] Any id that starts with before. [id*="screenshot"] Any id that contains screenshot. #before-screenshot-none[type] Needs that id, and any type attribute. On the left side of the screenshot, a bit below the input, there's a tr with a th and td. The th and td are direct descentdants (child nodes) of the tr. You can use tr > td to select any td with a tr direct parent, or tr span to select any span children with a tr parent. tr span label That would select any labels that have a tr then span parent. tr>span > label This wouldnt select the label in the screenshot since i didnt include the td. th + td To select adjacent siblings. To use adjacent siblings correctly, you must pay attention to the nesting order of the tags. In CSS, adjacent means "directly above or below this tag, at the same nesting depth." So, table rows are not adjacent to their children table cells. Table rows, <tr>, are adjacent to other table rows. Then there's pseudo-classes, such as in: th:first-child+td which selects a td if there's a th just above it that is the first child node of its parent (In the screenshot, "#text" is not a node/tag, it is showing that there is text content in the node, relative to where DOMi is printing the "#text" place-holder). :before :after :only-child If you notice on a webpage html is the parent for body and head. :only-child wont select either of them since body and head are siblings of each other. :first-line :first-letter :empty Doesnt have any children or content. :hover Mouseover. :active Clicked, then released (or dragged). :focus Accepting input, the keyboard cursor is inside it. :-moz-any-link Any links (-moz prefix is often used in Mozilla Extentions of CSS). :link An anchor tag, which has an "href", Hyper-Reference, property. :visited Visited links. * Everything. [id]:not(input) Anything with an id but not inputs. This is a special pseudo-class, called negation. :not(.someclass) :not([type="blah"]) :not(:first-child) a[href^="javascript:"]:not([href^="javascript:if\(confirm\(\"You"]):after The \ back-slashes escape the characters after them, because they are part of the content of the selector, instead of part of the selector syntax, CSS needs to be told that in this way. As is usual with back-slash escaping, two of them, "\\", will mean one actual \. Selector Specificity Top of this page.Selector specificity is a numeric ranking of the selector used to target an entity, so that more specific selectors take precedence over less specific ones. This can be used in userstyles when you want to make minor modifications to an existing userstyle, without replicating the entire CSS in yours. In such a case, you are creating an, "addon userstyle", where your new userstyle is an, "addon", to the original, meaning that both userstyles must be loaded in a browser to produce the desired effect. The addon userstyle must use more specific selectors than the original, so that the addon rules apply on top of the originals rather than some other way. For instance, if the style you wish to modify looks like this:
@-moz-document url("") {
body {
background: #FFF !important;
color: #000 !important;
}
.someclass {
color: #F00 !important;
font-style: bold !important;
}
.someotherclass { color: #113377 !important; }
}
Then presume we want an addon style to change only body, to give it a black background and white text, but we want to keep any other rules of the original userstyle. We would do so like this:
@-moz-document url("") {
html > body {
background: #000 !important;
color: #FFF !important;
}
}
This works because in HTML namespace, a body node is always the child of the html node. Similarly, we can change any other piece of the already existing userstyle, such as the .someclass rule, by prefixing a selector with body, like this:
@-moz-document url("") {
body .someclass { color: #00F !important; }
}
This works if the original userstyle was written like our example, using only .someclass, and not some more specific selector, because in HTML namespace, every node of the document is a descendant of the body node. Creating addon userstyles may put you in a situation of needing to override a selector which already uses the specificity principle, such as in:
@-moz-document url("") {
html > body { background-color: #ccc !important; }
}
To affect a selector such as this, you may need to use the :root psuedo-selector, like this:
@-moz-document url("") {
html:root > body { background-color: #000 !important; }
}
This works because while the html node does not have any ancestors for you to select, it is the root node in HTML namespace, and the :root psuedo-selector is used to add specificity in this case. Here are some other ways you might increase specificity of your selectors:
.message
div.message // assuming the original html code was <div class="message"> body .message body div.message html body .message html body div.message html body:not([imaginary_tag_attribute]) div.message // a body node does not have imaginary_tag_attribute="" In any userstyle, you must match or exceed the specificity of the original CSS. Existing properties must be overwritten or negated, if you don't want them involved in the result, and the selector ancestry syntax ( spaces, > or + ) must usually match or beat the original. While writing an addon userstyle, with the original userstyle also loaded, Stylish's userstyle load order may trick you, making you think you've gotten the selector specificity right. Stylish reads loaded userstyles from top to bottom, in order of the time they were loaded, so new styles have natural priority over older ones. This is the same principle as load order of .css files when writing web pages.
{
Part of: Example Style
The selector is finished, we now begin to list the property values which form the actual styles applied to the given selector(s). Properties Top of this page.
background: #999999 !important;
color: #000000 !important;
Part of: Example Style
This is a simple rule with two property declarations, changing the background color to grey and the text color to black. "#999999" and "#000000" are hexadecimal color values. "!important", forces a property to be chosen instead of a previous one of matching specificity. !important properties override non-!important ones, and is key in userstyling. Every property you write should end with "!important;". background is a shorthand property which can combine all of the separate background-* property values.
background-image: url("http://website.com/picture.png") !important;
background-color: #000000 !important;
The above example, is equivalent to the following one:
background: #000000 url("http://website.com/picture.png") !important;
You can embed image data into a CSS file using data URI. In the Stylish userstyle editor, to insert a data URI, write out the rest of the property declaration, like this:
background-image: url() !important;
Place the keyboard cursor between the parenthesis, then at the top-left of the Stylish editor, click: Insert, Data URI. Select the file, and you're done. Stylish 0.5 userstyle editor would scroll to the top of the textarea when inserting a data URI, which is why you should write the rest of the property first. The result will look similar to this:
background-image: url(data:image/png;base64,iVBORw0Jggg==) !important;
You can use the chrome:// URI in property values, such as in:
background: rgb(255,255,255) url("chrome://branding/content/about.png") top right no-repeat !important;
You may choose to write your color values as RGB decimals, hexadecimals, or english names. } Part of: Example Style
Ends the properties list. } Part of: Example Style
Closes the document style. Local Resources (files) in Firefox's Paths Top of this page.chrome://You can use Chrome List to find image resources you see in FireFox or extensions. chrome://path/ These paths are somewhat relative to the user profile directory, but the "chrome" URI (Universal Resource Identifier) scheme is used because many of these files are being pulled directly from ZIP archives. resource://resource://gre/path/ These paths are relative to the program directory. These paths are supposed to be restricted to local JavaScript space, with limited accessibility. The bug advisory suggests that, as always, such ideals are not guarantees. You can add files to these paths, but should limit those files to the same sort that are found there already. Namely, images and such. file:///file:///C:/path/to/file These are exactly what they look like. The extra / is required, so take note of it. How NOT To Style Top of this page.about:blankMany Stylish userstyle authors seem to think that about:blank is only used for new/empty tabs. The assumption is false. About:blank is used in many places where an HTML DOM is needed, or where a place-holder is needed before a document loads (it is in all new tabs before the document loads).
About:blank is used by Web Developer Toolbar, "View Style Information".
About:blank is used by NoScript, as a place holder for embedded objects.
About:blank is on this page: You should not put content on about:blank, with Greasemonkey, or place images on about:blank because it looks cool in new tabs. About:blank can appear anywhere, and it is not meant for that behavior. Doing these things can break or severely slow down anything built to use about:blank. Frequently Asked Questions Top of this page.These are answers to questions often asked about userstyling with Stylish. CSS Color Values Top of this page.Where a color value is needed, you can use words: black, lightblue, or any other CSS color name. RGB: rgb(123,213,43)
hexadecimal: #FFFFFF
Positioning Is Confusing Top of this page.position Tell an element to behave as static, relative, absolute, or fixed. top Distance from this edge of the parent node, to this edge of this node. bottom '' left '' right ''
position: fixed !important;
top: 10% !important;
right: 10ex !important;
bottom: 5em !important;
left: 50px !important;
Fixed means, "fixed on screen". Absolute means "position within the parent node". To force positioning to the bottom of a page, you often must use the size and positioning of other nodes above the target node, to force it to be pushed down. A parent of an absolute positioned node, might stretch to let its child get attached to the given edge. That stretching, however, may change the floating, wrapping, padding, or positioning of the target node's siblings. This could mean that position:absolute;bottom:0; will end up being the bottom of the window at some stage of the page being drawn, and not the bottom of the page when it is finished drawing. Read W3's explaination of positioning, with visual examples. If a node is already set to "top", and you want it at the "bottom" use this to turn off "top":
top:auto;
bottom:5pt;
Can I use wildcards in @-moz-document?: Top of this page.
Make my style change all pages?: Top of this page.That's called a "global style".
If you write something like this:
body { background-color: black; }
Click the "!important" button, so it becomes this:
body { background-color: black !important; }
Don't use @-moz-document for global styling. Replace an image with a local image?: Top of this page.
Style this thing on that page?: Top of this page.With Web Developer Toolbar: Top of this page.These images are an example of using Web Developer Toolbar and Stylish, together:
With DOM Inspector, Inspect Context, and Web Developer Toolbar: Top of this page.These images are an example of using Web Developer Toolbar, DOM Inspector, Inspect Context, and Stylish, together:
Select one URL and exclude another?: Top of this page.
What HTML tag does that select?: Top of this page.
Try To Userstyle Top of this page.The following <iframe> contains a page which is incredibly ugly and a bit complex. Use it to test the principles of this tutorial as you learn to userstyle. Hint:
@-moz-document url("") {
[style*=".gif"],
.dot1,
.message9
{ display: none !important; }
}
After clicking, "CLICK HERE TO BEGIN", the CSS used in the page which loads in the <iframe> is:
body {
background-color: #000 !important;
color: #fff !important;
}
.message {
color: red !important;
font-style: italic !important;
}
.anotherMessage { color: #6699cc !important; }
.message2 { color: #80FF80 ; background-color: #2B2F2B ; }
.message3 { color: #804000 ; background-color: #80FF80 ; }
.message4 { color: #FD11F7 ; background-color: #408080 ; }
.message5 { color: #FFFF2B ; background-color: #000000 ; }
.message6 { color: #202020 ; background-color: #FFFFFF ; }
.message7 { color: #918E80 ; background-color: #808000 ; }
.message8 { color: #69675C ; background-color: #804040 ; }
.message9 { color: #004000 ; background-color: #004000 ; position: fixed ; top: 0 ; bottom: 0 ; left: 100px ; width: 100px ; overflow: hidden ; }
.dot1 { background-image:url(images/valacar-example-dot1.gif); position:absolute; left:0; top:0; width:100%; height:100%; z-index:500; }
After Stylish Top of this page.
HI Network SearchLoading...
|
Use Coupon Code:
HONESTHOST
$9.94 Savings
(4.95 x 2) - 9.94 =
2 Months Free
+ $100 Free Google AdWords Credit
+ Unlimited Disk Space
+ Unlimited Bandwidth
|
||||||||||||||||||||||||||||||||
![]() |
Copyright © 2010
Copyright & License Privacy Policy Terms of Service Site Uptime |
![]() |
|||||||||||||||||||||||||||||||