tag:blogger.com,1999:blog-76811054003006872522024-03-19T15:18:23.863-07:00CSS3 Examplesjonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.comBlogger267125tag:blogger.com,1999:blog-7681105400300687252.post-38108302489369381032008-07-21T09:35:00.000-07:002008-07-21T09:38:51.734-07:00Keyboard Shortcuts<p>Learning a few quick-key secrets can make you look like a computer expert too, and save you seconds when you need something finished fast. Here are a few tips to help you speed up your computing.<br /></p> <h2><span style="font-size:100%;">Turn back the clock: Ctrl-Z</span></h2> <p>We have all done it; deleted the wrong text, changed the wrong formula in a spreadsheet, or formatted text in Word and messed up a whole document layout.</p> <p>Using the Ctrl-Z quick-key combination will save you time and frustration. This is an excellent time-saver; once you know it, you’ll wonder how you ever survived without it. Simply hit the Control key and Z to undo any mistake you make. This is great for when you cut-and-paste the wrong data into a Microsoft Excel file or accidentally delete a paragraph from a Microsoft Word document. Also repeat the key presses to go back a few stages to a previous version of a document.</p> <p>And just as useful, Control key and Y ‘undoes the undo’, i.e. it puts it back again if you undo one stage too far!</p> <h2><span style="font-size:100%;">From upper case to lower easily: CTRL-SHIFT-A</span></h2> <p>One of the more time-consuming things we often have to do is restyle copy from upper case to lower case, or vice-versa, when preparing a presentation or business proposal.</p> <p>Rather than spend all that time retyping the headline, sentence, paragraph or page, simply highlight the words you want changed and hit your Control key with the Shift button and A – you’ll toggle between upper and lower case copy in an instant.<br /></p> <h2 style="font-weight: bold;"><span style="font-size:100%;">Minimise everything: Windows key-M</span></h2> <p>On a busy day you can often have ten or more windows open on your PC. Accessing your desktop in these circumstances can be a lengthy process as you click away each individual window. But you can actually minimise all windows in the blink of an eye by hitting the Windows key and M together.</p> <h2><span style="font-size:100%;">For when time stands still: Ctrl-Alt-Del</span></h2> <p>It is unfortunately possible for applications on older model PCs to freeze and force you to wait while your PC troubleshoots. For example, Word can sometimes lock up when opening a corrupted document or one in a new format that an older model PC can’t read. This is doubly frustrating if it happens when you are racing to meet a deadline. (Hint - call CSS to get your PC upgraded if this happens often!)</p> <p>The Control/Alt/Delete shortcut is helpful in these situations because it takes you straight to Task Manager, where you can immediately shut down and then re-start applications that are experiencing difficulties.</p> <p>This handy combination also gives you the option of locking your computer, logging off, shutting down, or changing your password.<br /></p> <h2>Magic Text resizer</h2> <p>Finally my favourite, and one which never fails to impress anyone watching - resizing text in Word.</p> <p>When you are laying out a flyer or a brochure, you often need to get text to just the right size to fit in with graphics or text boxes. Highlight the text, and press Control and [ or Control and ] to decrease/increase the point size one at a time. The text will magically grow or shrink as you tap the keys, and makes it dead easy to fit text into a certain space.</p> <p>More shortcuts:</p> <ul><li style="color: rgb(0, 102, 0);">CTRL-C = Copy </li><li style="color: rgb(0, 102, 0);">CTRL-X = Cut </li><li style="color: rgb(0, 102, 0);">CTRL-V = Paste </li><li style="color: rgb(0, 102, 0);">CTRL-A = Highlight all (for instance a whole Word document to change a font size or style) </li><li style="color: rgb(0, 102, 0);">CTRL-ESC = Open Start Menu, use the arrow keys to select an item </li><li style="color: rgb(0, 102, 0);">F1 = Help </li><li style="color: rgb(0, 102, 0);">F2 = Rename an item </li><li style="color: rgb(0, 102, 0);">F3 = Open Find All Files dialog </li><li style="color: rgb(0, 102, 0);">ALT-F4 = Close the current window, or quit the current program </li><li style="color: rgb(0, 102, 0);">SHIFT-F4 = Automatically repeats the previous Find command in Word </li><li style="color: rgb(0, 102, 0);">F5 = Refresh Screen </li><li style="color: rgb(0, 102, 0);">ALT-F6 = Switch between multiple windows in the same program </li><li style="color: rgb(0, 102, 0);">F10 = Activate the menu bar in a program </li><li><span style="color: rgb(0, 102, 0);">SHIFT-DEL = Delete items permanently</span> </li></ul> <p>With these speedy keyboard tips, you will soon be tapping out impressive shortcuts that help you get more done in less time.<br /></p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com1tag:blogger.com,1999:blog-7681105400300687252.post-64253822943101376612008-07-21T09:25:00.001-07:002008-07-21T09:31:06.655-07:00CASCADING STYLE SHEETS TUTORIAL PART 3 OF 3<p>In part 2 of the tutorial we broke down the major sections of HTML on the page and established separation using DIV tags with unique ID's attached to them: </p> <div class="codeSnippet" style="width: 60%;"> <p></p><div id="navigation"> ... </div> <p></p> <p></p><div id="centerDoc"> ... </div> <p></p></div> <p>Using DIV's (to position the major page sections) is the alternate method to what most people use: tables. I would argue one method is not necessarily better than the other. But consider that CSS in the 'official' method to position page elements and tables should only be used to hold tabular data. </p> <p>On the other hand there are simply times when using tables is much easier and CSS just doesn't cut it. </p> <p>That said, our current layout (left or right side navigation) CSS is far easier to use and is an overall better solution. </p> <p>Now that we have that covered, everything gets really easy from here. We've established our main document and the major sections are in place, all we need to do is add our text and images.</p> <p><strong>Breaking down the page: </strong></p> <p>This page is simple, we have just a single heading: </p> <div class="codeSnippet" style="width: 60%;"><h1><span style="font-size:100%;">The Main Heading</span></h1> </div> <p>And a single paragraph: </p> <div class="codeSnippet" style="width: 60%;"> <p></p><p></p> <p>Go to the Web Designers Killer Handbook home page and grab the practice HTML page that we will used as the starting template for this tutorial. You can find it under the heading: 'To create the practice HTML page do the following:'. Follow the instructions there and create your basic HTML page ... and do it now!</p> <p></p> <p></p></div> <p>We define how the paragraphs and the headings will look in our CSS code: </p> <div class="codeSnippet"> <p>p { </p> <p>width: 80%; </p> <p>} </p> <p>h1 { </p> <p>font-family: Georgia, "Times New Roman", Times, serif; </p> <p>font-size: 18px; </p> <p>font-weight: bold; </p> <p>color: #000000; </p> <p>} </p></div> <p>This is pretty much self-explanatory. The only thing that should be mentioned is that we set the width of the </p><p> tags to 80%. This allows us to control all of our text width in one easy to edit spot. </p> <p>The only thing missing from the page is the actual navigation. The best and easiest way to do this, is by using list (</p><li>) tags. That makes sense, since navigational menus are essentially a list of pages. <p></p> <p>We styled the list item tags with this CSS: </p> <div class="codeSnippet"> <p>li { </p> <p>list-style-type: none; </p> <p>line-height: 150%; </p> <p>list-style-image: url(../images/arrowSmall.gif); </p> <p>} </p></div> <p>The above code uses an image as the bullets for the list and makes the space between the listed items 1 and ½ times larger than normal (I like a little more 'breathing room'). You don't have to have an image for the bullets, you could leave it with no images and no bullets by just removing the attribute: </p> <div class="codeSnippet">list-style-image: url(../images/arrowSmall.gif); </div> <p>Or you could use on of the built in bullet options: 'disc', 'circle' and 'square'. </p> <p>Next you should add to the HTML page an unordered list (</p><ul></ul>) in between the navigation DIV's just under the 'main navigation' heading: <p></p> <div class="codeSnippet"> <p></p><h2><span style="font-size:100%;">The Main navigation</span></h2> <p></p> <p></p><ul> <p></p> <p></p><li>Page One</li> <li>Page Two</li> <p></p> <p></p></ul> <p></p></div> <p>To make things easier (for the purpose of the article), change the CSS affecting the list item tags (</p></li><li>) so that we use a built in bullet: <p></p> <div class="codeSnippet"> <p>li { </p> <p>list-style-type: disc; </p> <p>line-height: 150%; </p> <p>} </p></div> <p>Now we have the navigation! </p> <p>That pretty much covers our goals for this tutorial, but we have just scratched the surface of CSS. As you can see, we created a nice looking page, while using very few types of HTML tags. At this time there isn't much text on the page, but we could add to the page easily, building it out to include lots of information and images with practically no HTML work at all!</p> <div class="call-out"> <p><strong>Video Tutorial on CSS for Page Layout:</strong></p> <p>I've created a quick video that talks about page layout in CSS. I talk about some ideas that will make your life a lot easier when it comes to building pages with CSS.</p> <p>CSS for Page Layout</p></div> <p> </p> <p>I hope the CSS tutorial was useful for you all, it may have been a little hard to get your head wrapped around this subject at first, but in time you will see that your efforts will pay off. Please let me know how you felt about this article. </p></li>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-58349272871117596702008-07-21T09:23:00.000-07:002008-07-21T09:30:21.344-07:00CASCADING STYLE SHEETS TUTORIAL PART 2 In Part 1 we created a classic two-column layout with left side navigation using CSS and only a few types of HTML tags.
<br />
<br />Part 1 presented the code for the page and explained what HTML tags we were going to use. Now we will look at the actual HTML code used so far and the CSS.
<br />
<br />Our page so far is really very simple. As you may already know, all the content (text, images, Flash etc) that the user sees when viewing a web page is marked-up/coded with HTML in-between the and tags*.
<br />
<br /><span style="font-weight: bold;">In this case we have this: </span>
<br />
<br />
<br />
<br /><div id="navigation">
<br />
<br /><h2 style="font-weight: normal;"><span style="font-size:85%;">The Main navigation</span></h2> <span style="font-size:85%;">
<br />
<br /></span></div> <span style="font-size:85%;">
<br />
<br /></span><div id="centerDoc"> <span style="font-size:85%;">
<br />
<br /></span><h1><span style="font-size:85%;">The Main Heading</span></h1> <span style="font-size:85%;">
<br />
<br /></span><p> <span style="font-size:85%;">
<br />
<br />Go to the Web Designers Killer Handbook home page and grab the practice HTML page that we will used as the starting template for this tutorial. You can find it under the heading: 'To create the practice HTML page do the following:'.
<br />
<br />Follow the instructions there and create your basic HTML page ... and do it now!
<br />
<br /></span></p> <span style="font-size:85%;">
<br />
<br /></span></div> <span style="font-size:85%;">
<br />
<br />
<br />
<br />In the above code we see that we have 2 main sections demarked by using </span><div><span style="font-size:85%;"> tags. As you learned in part one of this tutorial, </span><div><span style="font-size:85%;"> tags are designed to be used to create a 'division' in the document or in other words create a container. We have created two such containers and given them each of them a unique ID:
<br />
<br /></span><div id="navigation"> <span style="font-size:85%;">
<br />
<br />...
<br />
<br /></span><div id="centerDoc"> <span style="font-size:85%;">
<br />
<br />You will notice that the entire contents of the page are contained in one of these two major page divisions. So the first questions are what are the rules of ID's in HTML pages and why do we use them and assign them to page elements like DIVs?
<br />
<br />1. First of all you can assign ID's to any HTML tag. So I could have assigned an ID to a </span><p><span style="font-size:85%;"> tag as well.
<br />
<br />2. An ID in a page should only be used once. That is to say that no two elements should have the same ID. ID's are meant to uniquely identify a page element. So in the above example we know that there is only one page element with an ID of 'navigation' and only page element with an ID of 'centerDoc'. I like to use ID names that talk to you, it is pretty clear what is going on in each division we created above.
<br />
<br />3. ID's on HTML page elements (tags) are used in CSS. We can target ID's in our CSS code to change the appearance, position and even behavior of that element by referencing the ID of the element.
<br />
<br />Inside the </span></p><div><span style="font-size:85%;"> tags we use header tags (</span><h1 style="font-weight: normal;"><span style="font-size:85%;"> and </span></h1><h2><span style="font-weight: normal;font-size:85%;" >) to set the headers. I speak to what header tags mean in part 1 of this tutorial.
<br />
<br />And finally I have some </span><p style="font-weight: normal;"><span style="font-size:85%;"> tags, and of course I insert the text that makes up this simple page in-between them.
<br />
<br />Now I am going to jump to our CSS file that is attached to the HTML page. We attach the CSS document with this line of code in between the tags:
<br />
<br />
<br />
<br /></span> <link href="myCSS.css" rel="stylesheet" type="text/css"> <span style="font-size:85%;">
<br />
<br />
<br />
<br />Like a normal page link we have an 'href' attribute this time pointing to a CSS document that has all our CSS code that will affect this page since it is linked to it. This is not the only way to associate CSS code to pages (there are a few other ways) but we will leave that to another article. So in the above link we name the CSS file name with this: 'href="myCSS.css"' and we tell the browser that the link is to a CSS page with this attribute: 'type="text/css"'. All that is important here is that the link point to a CSS file with the name: 'myCSS.css'
<br />
<br />So now that we got the style sheet linked to the document, lets look at some CSS code. This first snippet of code 'styles' the unique ID's we were talking about before:
<br />
<br />#navigation {
<br />
<br />position: absolute;
<br />
<br />width: 210px;
<br />
<br />height: 600px;
<br />
<br />margin: 0;
<br />
<br />margin-top: 0px;
<br />
<br />border-right: 1px solid #C6EC8C;
<br />
<br />font-weight: normal;
<br />
<br />}
<br />
<br />#centerDoc {
<br />
<br />position: absolute;
<br />
<br />padding: 0 0 20px 0; /*top right bottom left*/
<br />
<br />margin-top: 50px;
<br />
<br />margin-left: 235px;
<br />
<br />}
<br />
<br />There is a lot going on here so we will focus on just a few elements for now. In the above elements we have 2 selectors, one for each ID and each selectors are grouped/contained by using the curly brackets: { }. So here is the CSS selectors code with all their guts removed:
<br />
<br />#navigation {
<br />
<br />/*Look ma no CSS rules!*/
<br />
<br />}
<br />
<br />#centerDoc {
<br />
<br />/*Look ma no CSS rules!*/
<br />
<br />}
<br />
<br />I just inserted the text: '/*Look ma no CSS rules!*/' to show you where the CSS code would normally be. So now you can see that anything in between the curly brackets is part of one group or package that in CSS can generically be called a selector.
<br />
<br />In our above examples you can see that there is some text that appears before a curly bracket. That text gives a name to the selector. So in this case we have two selector names and thus to selectors: #centerDoc and #navigation. So why do we have the # symbol in front of the text? Why can't we call it simply 'centerDoc' and 'navigation'?
<br />
<br />Like HTML and programming certain text in certain places have special meaning that tells the system to do something particular. In this case whenever you have a # symbol in front of a name of a CSS selector we are saying that this selector is a special type of selector called an 'ID' selector. What is so special about an ID selector? That type of selector can only be applied to one element in the HTML page. Sounds familiar?
<br />
<br />So those of you not asleep at the computer, now see that we have a CSS ID selector for each of our HTML divs that have an ID, and they have the same corresponding names. So the CSS selector #centerDoc applies to the div: '</span></p><div id="centerDoc"><span style="font-weight: normal;font-size:85%;" >' , you got it? Whatever CSS rules/styles we choose to code into our ID selector will change what appears inside the corresponding div. So for the div with the id of: 'navigation' we have these CSS rules:
<br />
<br />#navigation {
<br />
<br />position: absolute;
<br />
<br />width: 210px;
<br />
<br />height: 600px;
<br />
<br />margin: 0;
<br />
<br />margin-top: 0px;
<br />
<br />border-right: 1px solid #C6EC8C;
<br />
<br />font-weight: normal;
<br />
<br />}
<br />
<br />Notice at the bottom we say all text will have a font-weight of 'normal':
<br />
<br />font-weight: normal;
<br />
<br />We could just as easily have said that we want all the text to appear in the div (the div with the ID 'navigation') bold instead:
<br />
<br />font-weight: bold;
<br />
<br />But I digress, I already go into detail about CSS in a my previous article on CSS. This tutorial was about creating an easy to use page template so I will point out the 2 main elements that make this thing work.
<br />
<br />In our page the navigation div is sitting on the left and it has a border ... why? It has a nice light green 1 pixel border because I set this in my CSS:
<br />
<br />border-right: 1px solid #C6EC8C;
<br />
<br />Pretty self explanatory, no? I would suggest changing the color of the border and changing the pixel thickness of the border and see how it looks.
<br />
<br />Why is the navigation sitting on the left of the page while the centerDoc is to the right of it? Well first thing to look at is this line in the navigation selector:
<br />
<br />position: absolute;
<br />
<br />This tells the browser to just place this div on the page as is. This is oversimplifying the subject, but for our purposes this works for now.
<br />
<br />The real magic in this is the CSS code for centerDoc:
<br />
<br />#centerDoc {
<br />
<br />position: absolute;
<br />
<br />padding: 0 0 20px 0; /*top right bottom left*/
<br />
<br />margin-top: 50px;
<br />
<br />margin-left: 235x;
<br />
<br />}
<br />
<br />The line :
<br />
<br />padding: 0 0 20px 0; /*top right bottom left*/
<br />
<br />Tells the browser to insert 20px (pixels) of padding to the bottom of the div with the ID 'centerDoc'.
<br />
<br />Let's back up here a second. We just used something called 'padding' and it is what it sounds like: Space that is wrapped around our element (tag).
<br />
<br />CSS has this feature and concept of a box model that essentially is a box that wraps around HTML elements. This box model consists of: padding, margins, borders and the actual content. This allows us to place a border around elements and space elements in relation to other elements. From the inside out it is ordered like so:
<br />
<br />content -> padding -> border -> margin
<br />
<br />So in our case anything in between our </span><div><span style="font-weight: normal;font-size:85%;" > tags is the 'content'. Right after that comes the padding. Then there is a border and finally a margin. Margin and padding may seem like the same thing but if you think about it, you can see how being able to control the space before the border (padding) and after the border (margins) can really effect your layouts.
<br />
<br />In this example you notice that the navigation div sits higher up on the page than the centerDoc div. This is not because of the order that which they appear in the HTML, as they normally would without CSS, rather it is because of the margin settings I set for each selector; for centerDoc I set the top margin to 50px:
<br />
<br />margin-top: 50px;
<br />
<br />And for the navigation div I set it to:
<br />
<br />margin-top: 0px;
<br />
<br />This sets its top margin to 0 pixels so it will therefore be 50 pixels higher than the centerDoc div. I would suggest that you move the position of the navigation div under the center doc div in the HTML just to see if it changes anything, you will see that where the div appears in the actual HTML code has nothing to do with how it will appear to the user now that CSS positioning has been used. Another thing to try is to play with the CSS values and see what happens, change the padding, change the margins etc .
<br /></span>
<br /></div></div></h2></div></div></div></div></div>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-1182879672471005482008-07-21T09:21:00.000-07:002008-07-21T09:28:57.909-07:00CASCADING STYLE SHEETS TUTORIAL <p>In this CSS tutorial I will not be able to show you everything there is about CSS, but you will learn how to create nice looking CSS styled web pages. </p> <p>After completing this tutorial, you should have enough information to explore CSS and web design even further. </p> <ul style="margin-left: 20px; line-height: 150%;"><li style="color: rgb(0, 153, 0);">You can download the CSS and HTML files we build in this tutorial: CSS files </li><li><span style="color: rgb(0, 153, 0);">You can check out what the page should look like here: CSS example page</span> </li></ul> <div class="call-out"> <p><strong>THINGS TO REMEMBER ABOUT CSS:</strong></p> <p>Remember that CSS code is simply written instructions that tells Web browsers (like FireFox and Internet Explorer) how to display things on a page. For example:</p> <ol><li>make text bold. </li><li>position things a page. </li><li>set the font style for a page or paragraph etc. </li></ol> <p>The sister language to CSS is HTML: code that tells the Web browser WHAT is actually in the page.</p> <p>... I know you knew that already, I just wanted to remind you!</p></div> <p> </p> <h2><span style="font-size:85%;"><strong>CSS REDUCES THE NUMBER OF TAGS USED </strong></span></h2> <p><span style="font-size:85%;">Because of the power of CSS, we will be able to reduce the number of HTML tags we use in a page big time, all the while still being able to layout great looking pages using only 6 types (for lack of better words) of HTML tags. </span></p> <p><span style="font-size:85%;"><strong>The tags we will use to layout the content: </strong></span></p> <p><span style="font-size:85%;">1. <strong><h></h></strong> The Heading tags which range from <strong>'' to ''</strong>, are going to be used to mark/tag headings in our pages. So the most important heading will be wrapped in a </span></p><h1 style="font-weight: normal;"><span style="font-size:85%;"> tag and the least important in a <strong></strong></span></h1><h6 style="font-weight: normal;"><span style="font-size:85%;"> tag. </span> <p><span style="font-size:85%;">An example of a heading: </span></p> <div class="codeSnippet" style="width: 60%;"><h1> <span style="font-size:85%;"><strong>CSS Template Layout </strong></span></h1> </div> <p><span style="font-size:85%;">This tells the browsers and the search engines too, that this page is primarily about: 'CSS Template Layout' </span></p> <p><span style="font-size:85%;">All browsers have a default size (for each<strong> <h></h></strong> tag) as to how it renders text when placed between these tags. Many of these defaults can be unusable (especially<strong> </strong></span></p></h6><h1><span style="font-weight: normal;font-size:85%;" >) because they come out too big. But never fear, CSS is here. We will use CSS to make the text sizes more to our liking. </span> <p style="font-weight: normal;"><span style="font-size:85%;">2.<strong> </strong></span></p><p style="font-weight: normal;"><span style="font-size:85%;"> The Paragraph tag is used to mark parts of the pages as being 'paragraphs', simple enough. Paragraph tags are what they call a 'block element'; that means that it acts like a block where a space is automatically inserted before and after each </span></p><p style="font-weight: normal;"><span style="font-size:85%;"> tag pair. You see it work in the examples coming up. </span></p> <p style="font-weight: normal;"><span style="font-size:85%;">3. <strong></strong></span></p><ul><span style="font-weight: normal;font-size:85%;" > and <strong></strong></span><ol><span style="font-weight: normal;font-size:85%;" > List tags will used to create our menus. The tag <strong></strong></span><ul><span style="font-weight: normal;font-size:85%;" > is the 'un-ordered list tag' that creates a list with bullets or other images/icons that do not specify or denote an order; hence the term 'un-ordered'. The other list tag mentioned (<strong></strong></span><ol><span style="font-weight: normal;font-size:85%;" >) is the 'ordered list tag' and it creates a list that, instead of bullets, the list elements are marked with numbers or letters. Code examples to follow. </span> <p style="font-weight: normal;"><span style="font-size:85%;">4. <strong></strong></span></p><div><span style="font-weight: normal;font-size:85%;" > We all know what the </span><div><span style="font-weight: normal;font-size:85%;" > tag is about since we all read the previous article, right? We will use div's to create containers for parts of our page. One div will be used to 'hold' our navigational menu and another div to 'hold' the main page. </span> <p style="font-weight: normal;"><span style="font-size:85%;">5. <strong></strong><a> The most important tag in HTML: the 'link tag' or the 'hyperlink tag'. This makes text 'hyper' so that when we click on it we can load another page or activate/call some JavaScript (otherwise known as ECMA script). </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="font-weight: normal;"><span style="font-size:85%;"><a>6. <strong><img src="http://www.blogger.com/post-edit.g?blogID=7681105400300687252&postID=118287967247100548" /></strong> This is the 'image tag', allows you to link to images so that they show up in our pages. In HTML images are not embedded into the actual page, instead the image tag (<strong><img src="http://www.blogger.com/post-edit.g?blogID=7681105400300687252&postID=118287967247100548" /></strong>) only points to where the image is and the browser will attempt to load that image when a surfer loads your HTML page. </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="font-weight: normal;"><span style="font-size:85%;"><a>That covers the HTML tags we will use in our layout! No need for table tags, <strong>
<br /></strong> tags and nasty <strong></strong> tags. </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><h2 style="font-weight: normal;"><span style="font-size:85%;"><a><strong>THE BASIC PAGE TEMPLATE</strong></a></span></h2><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="font-weight: normal;"><span style="font-size:85%;"><a>Go to the Web Designers Killer Handbook home page and grab the practice HTML page that we will use as the starting template for this tutorial. You can find it under the heading: 'To create the practice HTML page do the following:' Follow the instructions there and create your basic HTML page. </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="font-weight: normal;"><span style="font-size:85%;"><a>Once you have created the template page, create a folder and name it something like: 'myCSSwebsite' and then drop the HTML page into it. In that same folder, create a new text document and call it: 'myCSS.css'. Once created open that file and paste in this template CSS code and then save it: </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><div style="color: rgb(0, 153, 0); font-weight: normal;" class="codeSnippet"><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>/* Generic Selectors */ </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>body { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-family: Georgia, "Times New Roman", Times, serif; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-size: 14px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #333333; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>background-color: #F9F9F9; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>p { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>width: 80%; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>li { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>list-style-type: none; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>line-height: 150%; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>list-style-image: url(../images/arrowSmall.gif); </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>h1 { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-family: Georgia, "Times New Roman", Times, serif; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-size: 18px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #000000; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>h2 { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-family: Georgia, "Times New Roman", Times, serif; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-size: 16px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #000000; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>border-bottom: 1px solid #C6EC8C; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a> </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>/**************** Pseudo classes ****************/ </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>a:link { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #00CC00; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>text-decoration: underline; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>li :link { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #00CC00; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>text-decoration: none; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>a:visited { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #00CC00; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>text-decoration: underline; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>li a:visited { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: #00CC00; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>text-decoration: none; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>a:hover { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: rgb(0, 96, 255); </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>padding-bottom: 5px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>text-decoration: underline; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>li a:hover { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>display: block; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: rgb(0, 96, 255); </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>padding-bottom: 5px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>border-bottom-width: 1px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>border-bottom-style: solid; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>border-bottom-color: #C6EC8C; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>a:active { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>color: rgb(255, 0, 102); </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: bold; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>/************************* ID's *************************/ </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>#navigation { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>position: absolute; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>width: 210px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>height: 600px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>margin: 0; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>margin-top: 50px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>border-right: 1px solid #C6EC8C; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>font-weight: normal; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>#centerDoc { </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>position: absolute; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>padding: 0 0 20px 0; /*top right bottom left*/ </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>margin-top: 50px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>margin-left: 235px; </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>} </a></span></p></div><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="color: rgb(0, 153, 0); font-weight: normal;"><span style="font-size:85%;"><a>Don't let the CSS freak you out, I will explain the important details and you will soon see how easy it really is. One last thing for you to do before I finish this part of the tutorial, we need to add some code to our HTML page. </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="color: rgb(0, 153, 0); font-weight: normal;"><span style="font-size:85%;"><a>In between the tags you will need to insert this code: </a></span></p><span style="font-weight: normal;font-size:85%;" ><a> </a></span><div style="color: rgb(0, 153, 0); font-weight: normal;" class="codeSnippet"><span style="font-size:85%;"><a> </a></span><div id="navigation"><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span><h2><span style="font-size:85%;"><a>The Main navigation</a></span></h2><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span></div><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span><div id="centerDoc"><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span><h1><span style="font-size:85%;"><a>The Main Heading</a></span></h1><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a> </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>Go to the Web Designers Killer Handbook home page and grab the practice HTML page that we will used as the starting template for this tutorial. You can find it under the heading: 'To create the practice HTML page do the following:'. </a></span></p><span style="font-size:85%;"><a> </a></span><p><span style="font-size:85%;"><a>Follow the instructions there and create your basic HTML page ... and do it now! </a></span></p><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span><span style="font-size:85%;"><a> </a></span></div><span style="font-size:85%;"><a> </a></span></div><span style="font-weight: normal;font-size:85%;" ><a> </a></span><p style="color: rgb(0, 153, 0); font-weight: normal;"><span style="font-size:85%;"><a>And in between the tags you will need to insert this: </a></span></p><a> </a><div style="color: rgb(0, 153, 0);" class="codeSnippet"><a> </a><p><title>First CSS Tutorial</title><a> </a></p><a> </a><p><meta equiv="Content-Type" content="text/html; charset=iso-8859-1"><a> </a></p><a> </a><p><link href="myCSS.css" rel="stylesheet" type="text/css"></p></div></div></div></ol></ul></ol></ul></h1>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-14143870153775790312008-07-21T09:17:00.000-07:002008-07-21T09:19:32.729-07:00Top CSS Shortcuts<div class="storycontent"> <p><span style="font-weight: bold;">Top CSS Shortcuts</span><br /></p><p>When writing your CSS, it is possible to write neater, more readable code by making use of CSS shortcuts. A shortcut is a feature of CSS that allows the developer to specify a number of related properties on a single line rather than specify them all separately. Lets look at the following example:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">padding-top:5px;</span><br /><span style="color: rgb(0, 153, 0);">padding-right:10px;</span><br /><span style="color: rgb(0, 153, 0);">padding-bottom:5px;</span><br /><span style="color: rgb(0, 153, 0);">padding-left:10px;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p style="font-weight: bold;">The code above is perfectly valid and will work fine, but we can save time and make the code much neater using the following code:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">padding:5px 10px 5px 10px;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p>Using the code above we can specify all of the padding for the header div on one line. It works by applying the first attribute (5px) to the top padding of the div. The second (10px) applies to the right side padding, the 3rd (5px) attribute means the padding on the bottom of the div, and the forth (10px) attribute means the left side padding. The padding is always applied in this order.</p> <p style="font-weight: bold;">It is possible to shorten this code even further using the following code:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">padding:5px 10px;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p>This works by taking the first (5px) attribute to mean the top and bottom, or vertical padding, and the second (10px) attribute to mean the horizontal padding (left and right).</p> <p style="font-weight: bold;">The exact same principles can be used to declare the margin of your divs, so what could have looked like this:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">padding-top:5px;</span><br /><span style="color: rgb(0, 153, 0);">padding-right:10px;</span><br /><span style="color: rgb(0, 153, 0);">padding-bottom:5px;</span><br /><span style="color: rgb(0, 153, 0);">padding-left:10px;</span><br /><span style="color: rgb(0, 153, 0);">margin-top:5px;</span><br /><span style="color: rgb(0, 153, 0);">margin-right:10px;</span><br /><span style="color: rgb(0, 153, 0);">margin-bottom:5px;</span><br /><span style="color: rgb(0, 153, 0);">margin-left:10px;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code><br /><span style="font-weight: bold;">Can now look much neater, and is obviously much quicker to write using the following:</span></p> <p><code><br /><span style="color: rgb(0, 102, 0);">.header {</span><br /><span style="color: rgb(0, 102, 0);">padding:5px 10px;</span><br /><span style="color: rgb(0, 102, 0);">margin:5px 10px;</span><br /><span style="color: rgb(0, 102, 0);">}</span><br /></code></p> <h3>Background properties</h3> <p>One of my favorite CSS shortcuts is the background property shortcut. This is how a typical CSS file could look without shortcuts:</p> <p><code><br /><span style="color: rgb(0, 102, 0);">.header {</span><br /><span style="color: rgb(0, 102, 0);">background-image:url(images/image.jpg);</span><br /><span style="color: rgb(0, 102, 0);">background-position:top;</span><br /><span style="color: rgb(0, 102, 0);">background-repeat:repeat-x;</span><br /><span style="color: rgb(0, 102, 0);">background-color:#fff;</span><br /><span style="color: rgb(0, 102, 0);">}</span><br /></code></p> <p style="font-weight: bold;">However, with some nifty CSS it could look like this:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">background: #fff url(images/image.jpg) repeat-x top;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p>The above code is much quicker and more manageable. Take note though, that all of the properties must be provided when using the background shortcut. If I missed off the colour specification at the beginning for example, the code would not work. </p> <h3>Font shortcuts</h3> <p>Another very useful shortcut is the font shortcut. The code below can be shorted considerably:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">body {</span><br /><span style="color: rgb(0, 153, 0);">font-weight: bold;</span><br /><span style="color: rgb(0, 153, 0);">font-family: verdana, sans-serif;</span><br /><span style="color: rgb(0, 153, 0);">font-size: 0.8em;</span><br /><span style="color: rgb(0, 153, 0);">line-height: 1.2em;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p style="font-weight: bold;"><span style="color: rgb(0, 153, 0);">H</span>ere is the shortcut:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">body {</span><br /><span style="color: rgb(0, 153, 0);">font: bold 0.8em/1.2em verdana, sans-serif;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p>It is important to write the shortcut in the same order as above so that web browsers don’t get confused!</p> <h3>Borders</h3> <p>This is my favorite shortcut of all. This saves me a great deal of time when I am developing web sites because whenever I have a problem with a layout or an element, the first thing I do is put a border around it so that I can see its dimensions and work out what’s going on.</p> <p style="font-weight: bold;">Here is some typical code:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">border-width: 1px;</span><br /><span style="color: rgb(0, 153, 0);">border-color: #000;</span><br /><span style="color: rgb(0, 153, 0);">border-style: solid;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p style="font-weight: bold;">This can be shorted to the following:</p> <p><code><br /><span style="color: rgb(0, 153, 0);">.header {</span><br /><span style="color: rgb(0, 153, 0);">border:1px solid #000;</span><br /><span style="color: rgb(0, 153, 0);">}</span><br /></code></p> <p>Then, whenever you are not sure why an element is not behaving properly, just use the border shortcut above to debug your code and see what the dimensions of the element are. </p> <h3>Conclusion</h3> <p>As you can see, you can make your code much shorter and neater using the CSS shortcuts outlined here. Once you get into the habit of using them, I guarantee that you will wonder why you ever did it differently in the past!</p></div>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-49969987756159840312008-07-21T09:14:00.000-07:002008-07-21T09:16:21.654-07:00CSS Shortcuts Tutorial<h1 id="top">CSS Shortcuts</h1> <div class="slug">In CSS, there are a numerous ways to code the same style. In the tutorial, I'll explain some of the most common shortcut structures that will allow you to make your css styles as small and effcient as possible.</div><br /> <div class="mid"> <div id="spon"> <div align="center"><a href="http://www.spoonohost.com/"><br /></a></div></div> <p><b>Fonts</b><br />When defining fonts, you can combine 4 of the most used css attributes into one. For instance, the old-school way of writing this font style:</p><pre style="color: rgb(0, 153, 0);">font-weight: bold;<br />font-family: verdana, sans-serif;<br />font-size: 11px;<br />line-height: 16px;</pre> <p>can be written using shortcut methods as:</p><pre style="color: rgb(51, 204, 0);">font: bold 11px/16px verdana, sans-serif;</pre> <p>The attributes must be arranged in the same order or web browsers will get confused.</p> <p><b>Hex-decimal Colors</b><br />Color attributes for all kinds of CSS styles can be written using defined using hex-decimal colors like <span class="green">color: #ff6600;</span> for a shade of orange. Colors that are made up of pairs of repeated digits can be simplified by using 3 digits instead of all six. For instance, the orange hex-decimal code can be abbreviated as <span class="green">color: #f60;</span>. Each digit represents two digits in the full hex-decimal code. So, if you what to use the color white in your code, don't use <span class="green">color: white;</span> or <span class="green">color: #ffffff;</span>. That's so 1997. Be cool and use <span class="green">color: #fff;</span>. (And just like that you may have saved a character or three...great stuff).</p> <p><b>Borders</b><br />If you were to right out the long-hand version of border code, it could take up some serious space. For example, just to define common attributes for a top border of something you could end up writing:</p><pre style="color: rgb(0, 153, 0);">border-top-width: 2px;<br />border-top-style: dashed;<br />border-top-color: #f00;</pre> <p>That can be simplified to:</p><pre style="color: rgb(0, 153, 0);">border-top: 2px dashed #f00;</pre> <p>Additionally, if you are going to define all four borders you can just use one border attribute like:</p><pre style="color: rgb(51, 204, 0);">border: 2px dashed #f00;</pre> <p><b>Margins, Padding, and Borders</b><br />Margins, padding, and borders all have similar CSS coding, such as:</p><pre style="color: rgb(0, 153, 0);">margin-top: 10px;<br />margin-right: 5px;<br />margin-bottom: 20px;<br />margin-left: 15px;</pre> <p>All four attributes can be defined in shortcut notation like this:</p><pre>margin: 10px 5px 20px 15px;</pre> <p>Note that the attributes go around clock-wise starting from the top. Margin, padding, and borders can be shorted further when some of the attributes are the same. Here is a list all four combinations of shorcuts:</p> <p style="color: rgb(51, 204, 0);">4 Values: (<span class="green">margin: 20px 15px 10px 5px;</span>) first - <i>top</i>, second - <i>right</i>, third - <i>bottom</i>, fourth - <i>left</i>.<br />3 Values: (<span class="green">margin: 20px 15px 10px;</span>) first - <i>top</i>, second - <i>left & right</i>, third - <i>bottom</i>.<br />2 Values: (<span class="green">margin: 20px 15px;</span>) first - <i>top & bottom</i>, second - <i>left & right</i>.<br />1 Value: (<span class="green">margin: 10px;</span>) first - <i>top, right, bottom, & left</i></p> <p><b>Zeros</b><br />While we're talking about shortcuts, it's probably good to note that when defining any size attributes using px, em, pt, pc, in or what ever other measuring increment you wish to use, you can always leave off the measurement unit for values of 0 (ie: 0, 0px, 0em, and 0pt) are all the same. The only caveat is when you are defining with percentages. For reasons beyond our scope of knowlege, the powers that be at the W3C made it necessary to add the % sign to 0%. In some browsers, it doesn't matter. But to be safe, use 0% with combinations of other percentages.</p></div>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-6070939349355340812008-07-21T09:12:00.000-07:002008-07-21T09:14:03.311-07:00CSS: Shortcuts tips<strong><span style="color:#ff6600;">CSS: Shortcuts tips</span></strong><br />(Still on old news for you CSS-pros. I’m wondering why YOU’RE not writing this blog. All the comments have been more helpful than my posts!! LOL!)<br /><strong>Just wanted to jot these down so I could find them later:</strong><br /><span style="color:#009900;">font-weight: bold;font-size: 10px;font-family: Verdana,Arial,Helvetica,sans-serif;shortcut:font: bold 10px Verdana,Arial,Helvetica,sans-serif;<br />margin/padding shortcuts:margin: top# right# bottom# left#ie. margin: 5px 0px 2px 10px;ormargin: top&bottom# left&right#ie. margin: 10px 5px;<br />color shortcuts (websafe hex)color: #000000;shortcut: color: #000color: #FFCC00;shortcut: color: #FC0;</span>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com1tag:blogger.com,1999:blog-7681105400300687252.post-17058249262482487292008-07-21T09:10:00.000-07:002008-07-21T09:12:17.680-07:00CSS ShortcutsShortcuts<br />In CSS, there are a numerous ways to code the same style. In the tutorial, I'll explain some of the most common shortcut structures that will allow you to make your css styles as small and effcient as possible.<br />Sponsors - Spoono Host<br /><a href="http://www.spoonohost.com/"></a><br />FontsWhen defining fonts, you can combine 4 of the most used css attributes into one. For instance, the old-school way of writing this font style:<br />font-weight: bold;<br />font-family: verdana, sans-serif;<br />font-size: 11px;<br />line-height: 16px;<br />can be written using shortcut methods as:font: bold 11px/16px verdana, sans-serif;<br />The attributes must be arranged in the same order or web browsers will get confused.<br />Hex-decimal ColorsColor attributes for all kinds of CSS styles can be written using defined using hex-decimal colors like color: #ff6600; for a shade of orange. Colors that are made up of pairs of repeated digits can be simplified by using 3 digits instead of all six. For instance, the orange hex-decimal code can be abbreviated as color: #f60;. Each digit represents two digits in the full hex-decimal code. So, if you what to use the color white in your code, don't use color: white; or color: #ffffff;. That's so 1997. Be cool and use color: #fff;. (And just like that you may have saved a character or three...great stuff).<br />BordersIf you were to right out the long-hand version of border code, it could take up some serious space. For example, just to define common attributes for a top border of something you could end up writing:border-top-width: 2px;<br />border-top-style: dashed;<br />border-top-color: #f00;<br />That can be simplified to:border-top: 2px dashed #f00;<br />Additionally, if you are going to define all four borders you can just use one border attribute like:border: 2px dashed #f00;<br />Margins, Padding, and BordersMargins, padding, and borders all have similar CSS coding, such as:margin-top: 10px;<br />margin-right: 5px;<br />margin-bottom: 20px;<br />margin-left: 15px;<br />All four attributes can be defined in shortcut notation like this:margin: 10px 5px 20px 15px;<br />Note that the attributes go around clock-wise starting from the top. Margin, padding, and borders can be shorted further when some of the attributes are the same. Here is a list all four combinations of shorcuts:<br />4 Values: (margin: 20px 15px 10px 5px;) first - top, second - right, third - bottom, fourth - left.3 Values: (margin: 20px 15px 10px;) first - top, second - left & right, third - bottom.2 Values: (margin: 20px 15px;) first - top & bottom, second - left & right.1 Value: (margin: 10px;) first - top, right, bottom, & left<br />ZerosWhile we're talking about shortcuts, it's probably good to note that when defining any size attributes using px, em, pt, pc, in or what ever other measuring increment you wish to use, you can always leave off the measurement unit for values of 0 (ie: 0, 0px, 0em, and 0pt) are all the same. The only caveat is when you are defining with percentages. For reasons beyond our scope of knowlege, the powers that be at the W3C made it necessary to add the % sign to 0%. In some browsers, it doesn't matter. But to be safe, use 0% with combinations of other percentages.jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com2tag:blogger.com,1999:blog-7681105400300687252.post-84213525307839405342008-06-27T12:10:00.000-07:002008-06-27T12:19:29.326-07:00Arrow Bullet List Menu<p>This CSS list menu features category headers with a two toned background, UL elements that have their default margins and padding removed, and finally, LI elements with custom bullet images. The result is something simple but elegant, and resembling something you might have seen on this site already! <b>Note: </b>For a version of this menu that dynamically expands and hides its sub menus, see <a href="http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm">Accordion Menu</a>.</p> <p><b class="codetitle">Demo:</b></p> <div class="arrowlistmenu"> <h3 class="headerbar">CSS Library</h3> <ul><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C1/">Horizontal CSS Menus</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C2/">Vertical CSS Menus</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C4/">Image CSS</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C6/">Form CSS</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C5/">DIVs and containers</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C7/">Links & Buttons</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C8/">Other</a> </li><li><a href="http://www.dynamicdrive.com/style/csslibrary/all/">Browse All</a> </li></ul> <h3 class="headerbar">CSS Drive</h3> <ul><li><a href="http://www.cssdrive.com/">CSS Gallery</a> </li><li><a href="http://www.cssdrive.com/index.php/menudesigns/">Menu Gallery</a> </li><li><a href="http://www.cssdrive.com/index.php/news/">Web Design News</a> </li><li><a href="http://www.cssdrive.com/index.php/examples/">CSS Examples</a> </li><li><a href="http://www.cssdrive.com/index.php/main/csscompressor/">CSS Compressor</a> </li><li><a href="http://www.dynamicdrive.com/forums/forumdisplay.php?f=6">CSS Forums</a> </li></ul></div> <p class="iepara"><b class="codetitle">The two images used:</b></p> <p class="codeimages"><img title="Dimensions- 6px by 40px" src="http://www.dynamicdrive.com/cssexamples/media/titlebar.png" height="40" width="10" /> <img title="Dimensions- 15px by 15px" src="http://www.dynamicdrive.com/cssexamples/media/arrowbullet.png" height="17" width="17" /></p> <p><b class="codetitle">The CSS:</b></p> <form> <div> <div class="selectcode"><a class="tabs" href="http://www.dynamicdrive.com/style/csslibrary/item/arrow_bullet_list_menu/#selectcode" rel="1">Select Code</a> <a class="tabs" href="http://www.dynamicdrive.com/style/csslibrary/item/arrow_bullet_list_menu/#expandcode" rev="154 defaultHeight" rel="1">Expand</a></div></div><textarea class="codecontainer" style="margin-top: 0px;" rows="10" cols="70"><style type="text/css"> .arrowlistmenu{ width: 180px; /*width of menu*/ } .arrowlistmenu .headerbar{ font: bold 14px Arial; color: white; background: black url(media/titlebar.png) repeat-x center left; margin-bottom: 10px; /*bottom spacing between header and rest of content*/ text-transform: uppercase; padding: 4px 0 4px 10px; /*header text is indented 10px*/ } .arrowlistmenu ul{ list-style-type: none; margin: 0; padding: 0; margin-bottom: 8px; /*bottom spacing between each UL and rest of content*/ } .arrowlistmenu ul li{ padding-bottom: 2px; /*bottom spacing between menu items*/ } .arrowlistmenu ul li a{ color: #A70303; background: url(media/arrowbullet.png) no-repeat center left; /*custom bullet list image*/ display: block; padding: 2px 0; padding-left: 19px; /*link text is indented 19px*/ text-decoration: none; font-weight: bold; border-bottom: 1px solid #dadada; font-size: 90%; } .arrowlistmenu ul li a:visited{ color: #A70303; } .arrowlistmenu ul li a:hover{ /*hover state CSS*/ color: #A70303; background-color: #F3F3F3; } </style> </textarea> <p><b class="codetitle">The HTML:</b></p> <div> <div class="selectcode"><a class="tabs" href="http://www.dynamicdrive.com/style/csslibrary/item/arrow_bullet_list_menu/#selectcode" rel="2">Select Code</a> <a class="tabs" href="http://www.dynamicdrive.com/style/csslibrary/item/arrow_bullet_list_menu/#expandcode" rev="154 defaultHeight" rel="2">Expand</a></div></div><textarea class="codecontainer" style="margin-top: 0px;" rows="10" cols="70"><div class="arrowlistmenu"> <h3 class="headerbar">CSS Library</h3> <ul> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C1/">Horizontal CSS Menus</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C2/">Vertical CSS Menus</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C4/">Image CSS</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C6/">Form CSS</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C5/">DIVs and containers</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C7/">Links & Buttons</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C8/">Other</a></li> <li><a href="http://www.dynamicdrive.com/style/csslibrary/all/">Browse All</a></li> </ul> <h3 class="headerbar">CSS Drive</h3> <ul> <li><a href="http://www.cssdrive.com">CSS Gallery</a></li> <li><a href="http://www.cssdrive.com/index.php/menudesigns/">Menu Gallery</a></li> <li><a href="http://www.cssdrive.com/index.php/news/">Web Design News</a></li> <li><a href="http://www.cssdrive.com/index.php/examples/">CSS Examples</a></li> <li><a href="http://www.cssdrive.com/index.php/main/csscompressor/">CSS Compressor</a></li> <li><a href="http://www.dynamicdrive.com/forums/forumdisplay.php?f=6">CSS Forums</a></li> </ul> </div> </textarea></form>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com1tag:blogger.com,1999:blog-7681105400300687252.post-48689124646567833212008-06-27T12:04:00.000-07:002008-06-27T12:08:14.904-07:00png transparency problems<p>If you are CSS coder, you've probably ran in to png transparency problems many times. Even Microsoft is having problems with it http://runonce.msn.com/runonce2.aspx open in IE6. So I'll tell you few problems and solutions I've handled so far.</p> <p>First one is if you need just simple transparent image, without some special needs for example backgrounds etc. The solution would be png fix. I've used it many times but it has lots of faults, for example with padding, margins and absolute positioning. Sometimes i can mess up the rest of your JavaScript files, but anyway very useful script. You can download it here http://homepage.ntlworld.com/bobosola/pngfix.js and just include it in your <head> tag</p> <p><img class="mainslika" alt="PNG" src="http://stylizedweb.com/wp-content/themes/dejanc/images/png1.jpg" /></p><pre class="javascript"><!--<span style="color: rgb(102, 204, 102);">[</span><span style="font-weight: bold; color: rgb(0, 0, 102);">if</span> lt IE <span style="color: rgb(204, 0, 0);">7</span>.<span style="color: rgb(102, 204, 102);">]</span>>
<br /><script type="<span" style="color: rgb(51, 102, 204);">"text/javascript"</span> src=<span style="color: rgb(51, 102, 204);">"pngfix.js"</span>></script>
<br /><!<span style="color: rgb(102, 204, 102);">[</span>endif<span style="color: rgb(102, 204, 102);">]</span>--></pre> <p>The second one can partly handle issues from first and it's pure CSS solution. I mostly use this for backgrounds, because if your path for a background is from CSS file then png fix can't handle it.</p>
<br /><p>
<br /></p><pre class="css"><span style="color: rgb(102, 102, 255);">.someelement</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background-image</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">images/image<span style="color: rgb(102, 102, 255);">.png</span></span><span style="color: rgb(102, 204, 102);">)</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />* html <span style="color: rgb(102, 102, 255);">.someelemen</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background-color</span>: <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">333</span></span>;
<br />back\ground-<span style="font-weight: bold; color: rgb(0, 0, 0);">color</span>: <span style="color: rgb(153, 51, 51);">transparent</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background-image</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">images/blank<span style="color: rgb(102, 102, 255);">.gif</span></span><span style="color: rgb(102, 204, 102);">)</span>;
<br />filter: progid<span style="color: rgb(51, 51, 255);">:DXImageTransform</span><span style="color: rgb(102, 102, 255);">.Microsoft</span>.
<br />AlphaImageLoader<span style="color: rgb(102, 204, 102);">(</span>src=<span style="color: rgb(255, 0, 0);">"images/image.png"</span>, sizingMethod=<span style="color: rgb(255, 0, 0);">"scale"</span><span style="color: rgb(102, 204, 102);">)</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p>I found this very useful, and also when you add some hover effects for example some color or other image. You can see live example here
<br /><strong>NOTE:</strong> This simple hover is just example and it doesn't work in IE6</p><pre class="css"><span style="color: rgb(102, 102, 255);">.someelement</span><span style="color: rgb(51, 51, 255);">:hover</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">333</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><span style="color: rgb(102, 102, 255);">.someelement</span><span style="color: rgb(51, 51, 255);">:hover</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background-image</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">images/image2<span style="color: rgb(102, 102, 255);">.gif</span></span><span style="color: rgb(102, 204, 102);">)</span>;
<br />
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p>Only problem I had with this was with <a> tag, link just don't work (when it's in div with this kind of background) and i don't know why (talking again for IE6). And only solution i could think of was to place another absolute div over it for the links, content etc... Yes i know it's not elegant but it works if content is not dynamic.</p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-77704941933297389902008-06-27T11:53:00.000-07:002008-06-27T11:58:15.314-07:00What it's all about...<blockquote cite="http://www.w3.org/Style/CSS/"> <p class="cite">Cascading Style Sheets (<b>CSS</b>) is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.</p></blockquote> <p>The above quote, taken from the W3C website, is one of the reasons for this site. Whilst I agree that it is a mechanism for adding style to web documents, I do not agree that it is a SIMPLE mechanism. It can be very complicated, as I found out when I took my first steps down this path.</p> <p><b class="css">CSS</b><span class="play"><i>p</i>lay</span>, by the way, is now listed on the <a href="http://www.w3.org/Style/CSS/learning" rel="nofollow">w3c.org website</a>.</p><p>So I have created this site in the hope that it will help newcomers to CSS and show old hands that it is more than just a mechanism for styling your documents. It is oh so much more.</p> <p>Because <b class="css">CSS</b><span class="play">play</span> deals with experimental CSS that is exactly what you get JUST CSS, no javascript or any other programming language has been used in any of the demonstrations. For javascript demonstrations please click the javascript link in the main navigation bar which will take you to my other site which is dedicated to demonstrations using CSS and minimal, unobtrusive, javascript.</p> <h3>Use the correct DocType Definition (DTD)</h3> <p>Please , please, please note that for most of my demonstrations to work, especially in Internet Explorer, you MUST use a standards compliant !DOCTYPE, and for Internet Explorer this MUST be the first line of your (x)html.<br />Using <?xml version="1.0" encoding="UTF-8"?> will switch IE into quirks mode.</p> <p>A list of the recommended DTDs can be found at the following link:<br /><a href="http://www.w3.org/QA/2002/04/valid-dtd-list.html" rel="nofollow">Recommended DTDs to use in your Web document</a>.</p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-39194359033782584592008-06-27T11:49:00.000-07:002008-06-27T11:53:18.970-07:00Most used CSS Tricks<p>Earlier before I have written an article about current best CSS hacks which you can see <a href="http://stylizedweb.com/2008/02/14/10-best-css-hacks/">here</a> And now here’s the list of today’s most used CSS tricks – tips. I have added image examples for most of them because of critics on CSS hacks article. If you think I have missed any please let me know</p> <h5>1. Rounded corners without images</h5><pre class="css">
<br /><div id="<span" style="color: rgb(255, 0, 0);">"container"</span>>
<br /><b class="<span" style="color: rgb(255, 0, 0);">"rtop"</span>>
<br /><b class="<span" style="color: rgb(255, 0, 0);">"r1"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r2"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r3"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r4"</span>></b>
<br /></b>
<br /><!--<span style="font-weight: bold; color: rgb(0, 0, 0);">content</span> goes here -->
<br /><b class="<span" style="color: rgb(255, 0, 0);">"rbottom"</span>>
<br /><b class="<span" style="color: rgb(255, 0, 0);">"r4"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r3"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r2"</span>></b> <b class="<span" style="color: rgb(255, 0, 0);">"r1"</span>></b>
<br /></b>
<br /></div>
<br />
<br /><span style="color: rgb(102, 102, 255);">.rtop</span>, <span style="color: rgb(102, 102, 255);">.rbottom</span><span style="color: rgb(102, 204, 102);">{</span>display<span style="color: rgb(51, 51, 255);">:block</span><span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.rtop</span> *, <span style="color: rgb(102, 102, 255);">.rbottom</span> *<span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span>; <span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);">1px</span>; <span style="font-weight: bold; color: rgb(0, 0, 0);">overflow</span>: <span style="color: rgb(153, 51, 51);">hidden</span><span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.r1</span><span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">margin</span>: <span style="color: rgb(153, 51, 51);">0</span> <span style="color: rgb(153, 51, 51);">5px</span><span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.r2</span><span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">margin</span>: <span style="color: rgb(153, 51, 51);">0</span> <span style="color: rgb(153, 51, 51);">3px</span><span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.r3</span><span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">margin</span>: <span style="color: rgb(153, 51, 51);">0</span> <span style="color: rgb(153, 51, 51);">2px</span><span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.r4</span><span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">margin</span>: <span style="color: rgb(153, 51, 51);">0</span> <span style="color: rgb(153, 51, 51);">1px</span>; <span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);">2px</span><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="Rounded corners without images" src="http://stylizedweb.com/examples/rounded1.gif" /></p> <h5>2. Style your order list</h5><pre class="css">
<br /><ol>
<br /><li>
<br />
<br />This is line one
<br /></li>
<br /><li>
<br />
<br />Here is line two
<br /></li>
<br /><li>
<br />
<br />And last line
<br /></li>
<br /></ol>
<br />
<br />ol <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font</span>: <span style="color: rgb(153, 51, 51);">italic</span> <span style="color: rgb(153, 51, 51);">1em</span> Georgia, Times, <span style="color: rgb(153, 51, 51);">serif</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">color</span>: <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">999999</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />ol p <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font</span>: <span style="color: rgb(153, 51, 51);">normal</span> <span style="color: rgb(102, 102, 255);"><span style="color: rgb(153, 51, 51);">.8em</span></span> Arial, Helvetica, <span style="color: rgb(153, 51, 51);">sans-serif</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">color</span>: <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">000000</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="Style your order list" src="http://stylizedweb.com/examples/order.gif" /></p> <h5>3. Tableless forms</h5><pre class="css">
<br /><form>
<br /><label for="<span" style="color: rgb(255, 0, 0);">"name"</span>>Name</label>
<br /><input id="<span" style="color: rgb(255, 0, 0);">"name"</span> name=<span style="color: rgb(255, 0, 0);">"name"</span>><br />
<br /><label for="<span" style="color: rgb(255, 0, 0);">"address"</span>>Address</label>
<br /><input id="<span" style="color: rgb(255, 0, 0);">"address"</span> name=<span style="color: rgb(255, 0, 0);">"address"</span>><br />
<br /><label for="<span" style="color: rgb(255, 0, 0);">"city"</span>>City</label>
<br /><input id="<span" style="color: rgb(255, 0, 0);">"city"</span> name=<span style="color: rgb(255, 0, 0);">"city"</span>><br />
<br /></form>
<br />
<br />label,input <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>: <span style="color: rgb(153, 51, 51);">150px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">float</span>: <span style="font-weight: bold; color: rgb(0, 0, 0);">left</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">margin-bottom</span>: <span style="color: rgb(153, 51, 51);">10px</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />label <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">text-align</span>: <span style="font-weight: bold; color: rgb(0, 0, 0);">right</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>: <span style="color: rgb(153, 51, 51);">75px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">padding-right</span>: <span style="color: rgb(153, 51, 51);">20px</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />br <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">clear</span>: <span style="font-weight: bold; color: rgb(0, 0, 0);">left</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="CSS Tableless forms" src="http://stylizedweb.com/examples/form.gif" /></p> <h5>4. Double blockquote</h5><pre class="css">
<br />blockquote<span style="color: rgb(51, 51, 255);">:first-letter</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">images/open-quote<span style="color: rgb(102, 102, 255);">.gif</span></span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(153, 51, 51);">no-repeat</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">left</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">top</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">padding-left</span>: <span style="color: rgb(153, 51, 51);">18px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font</span>: <span style="color: rgb(153, 51, 51);">italic</span> <span style="color: rgb(153, 51, 51);">1</span><span style="color: rgb(102, 102, 255);"><span style="color: rgb(153, 51, 51);">.4em</span></span> Georgia, <span style="color: rgb(255, 0, 0);">"Times New Roman"</span>, Times, <span style="color: rgb(153, 51, 51);">serif</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="Double blockquote" src="http://stylizedweb.com/examples/double.gif" /></p> <h5>5. Gradient text effect</h5><pre class="css">
<br /><h1><span></span>CSS Gradient Text</h1>
<br />
<br />h1 <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font</span>: <span style="color: rgb(153, 51, 51);">bold</span> <span style="color: rgb(153, 51, 51);"><span style="color: rgb(153, 51, 51);">330</span>%</span>/<span style="color: rgb(153, 51, 51);"><span style="color: rgb(153, 51, 51);">100</span>%</span> <span style="color: rgb(255, 0, 0);">"Lucida Grande"</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">position</span>: <span style="color: rgb(153, 51, 51);">relative</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">color</span>: <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">464646</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />h1 span <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">gradient<span style="color: rgb(102, 102, 255);">.png</span></span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(153, 51, 51);">repeat-x</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">position</span>: <span style="color: rgb(153, 51, 51);">absolute</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>: <span style="color: rgb(153, 51, 51);"><span style="color: rgb(153, 51, 51);">100</span>%</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);">31px</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><!--<span style="color: rgb(102, 204, 102);">[</span>if lt IE <span style="color: rgb(153, 51, 51);">7</span><span style="color: rgb(102, 204, 102);">]</span>>
<br /><style>
<br />h1 span <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(153, 51, 51);">none</span>;
<br />filter: progid<span style="color: rgb(51, 51, 255);">:DXImageTransform</span><span style="color: rgb(102, 102, 255);">.Microsoft
<br /></span><span style="color: rgb(102, 102, 255);">.AlphaImageLoader</span><span style="color: rgb(102, 204, 102);">(</span>src=<span style="color: rgb(255, 0, 0);">'gradient.png'</span>,
<br /> sizingMethod=<span style="color: rgb(255, 0, 0);">'scale'</span><span style="color: rgb(102, 204, 102);">)</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /></style>
<br />
<br /><!<span style="color: rgb(102, 204, 102);">[</span>endif<span style="color: rgb(102, 204, 102);">]</span>-->
<br /> </pre> <p><img class="mainslika" alt="Gradient text effect" src="http://stylizedweb.com/examples/gradient.gif" /></p> <h5>6. Vertical centering with line-height</h5><pre class="css">
<br />div<span style="color: rgb(102, 204, 102);">{</span>
<br />height<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">100px</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />div *<span style="color: rgb(102, 204, 102);">{</span>
<br />margin<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />div p<span style="color: rgb(102, 204, 102);">{</span>
<br />line-height<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">100px</span></span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />Content here
<br /> </pre> <p><img class="mainslika" alt="Vertical centering with line-height" src="http://stylizedweb.com/examples/verticalcenter.gif" /></p> <h5>7. Rounded corners with images</h5><pre class="css">
<br /><div class="<span" style="color: rgb(255, 0, 0);">"roundcont"</span>>
<br /><div class="<span" style="color: rgb(255, 0, 0);">"roundtop"</span>>
<br /><img src="<span" style="color: rgb(255, 0, 0);" />"tl.gif"</span> alt=<span style="color: rgb(255, 0, 0);">""</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>=<span style="color: rgb(255, 0, 0);">"15"</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>=<span style="color: rgb(255, 0, 0);">"15"</span> class=<span style="color: rgb(255, 0, 0);">"corner"</span>
<br />style=<span style="color: rgb(255, 0, 0);">"display: none"</span> />
<br /></div>
<br />
<br />CONTENT
<br /><div class="<span" style="color: rgb(255, 0, 0);">"roundbottom"</span>>
<br /><img src="<span" style="color: rgb(255, 0, 0);" />"bl.gif"</span> alt=<span style="color: rgb(255, 0, 0);">""</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>=<span style="color: rgb(255, 0, 0);">"15"</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>=<span style="color: rgb(255, 0, 0);">"15"</span> class=<span style="color: rgb(255, 0, 0);">"corner"</span>
<br />style=<span style="color: rgb(255, 0, 0);">"display: none"</span> />
<br /></div>
<br /></div>
<br />
<br /><span style="color: rgb(102, 102, 255);">.roundcont</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>: <span style="color: rgb(153, 51, 51);">250px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background-color</span>: <span style="color: rgb(204, 0, 204);">#f90</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">color</span>: <span style="color: rgb(204, 0, 204);">#fff</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><span style="color: rgb(102, 102, 255);">.roundcont</span> p <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">margin</span>: <span style="color: rgb(153, 51, 51);">0</span> <span style="color: rgb(153, 51, 51);">10px</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><span style="color: rgb(102, 102, 255);">.roundtop</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">tr<span style="color: rgb(102, 102, 255);">.gif</span></span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(153, 51, 51);">no-repeat</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">top</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">right</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><span style="color: rgb(102, 102, 255);">.roundbottom</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>: <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">br<span style="color: rgb(102, 102, 255);">.gif</span></span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(153, 51, 51);">no-repeat</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">top</span> <span style="font-weight: bold; color: rgb(0, 0, 0);">right</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />img<span style="color: rgb(102, 102, 255);">.corner</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span>: <span style="color: rgb(153, 51, 51);">15px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);">15px</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">border</span>: <span style="color: rgb(153, 51, 51);">none</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span> !important;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="Rounded corners with images" src="http://stylizedweb.com/examples/rounded2.gif" /></p> <h5>8. Multiple class name</h5><pre class="css">
<br /><img src="<span" style="color: rgb(255, 0, 0);" />"image.gif"</span> class=<span style="color: rgb(255, 0, 0);">"class1 class2"</span> alt=<span style="color: rgb(255, 0, 0);">""</span> />
<br />
<br /><span style="color: rgb(102, 102, 255);">.class1</span> <span style="color: rgb(102, 204, 102);">{</span> border<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">2px</span></span> <span style="color: rgb(153, 51, 51);">solid</span> <span style="color: rgb(204, 0, 204);">#<span style="color: rgb(153, 51, 51);">666</span></span>; <span style="color: rgb(102, 204, 102);">}</span>
<br /><span style="color: rgb(102, 102, 255);">.class2</span> <span style="color: rgb(102, 204, 102);">{</span>
<br />padding<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">2px</span></span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">background</span>:<span style="color: rgb(204, 0, 204);">#ff0</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <h5>9. Center horizontally</h5><pre class="css">
<br /><div id="<span" style="color: rgb(255, 0, 0);">"container"</span>></div>
<br />
<br /><span style="color: rgb(204, 0, 204);">#container</span> <span style="color: rgb(102, 204, 102);">{</span>
<br />margin<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0px</span></span> <span style="color: rgb(153, 51, 51);">auto</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="Center horizontally" src="http://stylizedweb.com/examples/horisontal.gif" /></p> <h5>10. CSS Drop Caps</h5><pre class="css">
<br /><p class="<span" style="color: rgb(255, 0, 0);">"introduction"</span>> This paragraph has the class
<br /><span style="color: rgb(255, 0, 0);">"introduction"</span>.
<br /> If your browser supports the pseudo-class
<br /><span style="color: rgb(255, 0, 0);">"first-letter"</span>, the first letter will be a drop-cap.
<br />
<br />p<span style="color: rgb(102, 102, 255);">.introduction</span><span style="color: rgb(51, 51, 255);">:first-letter</span> <span style="color: rgb(102, 204, 102);">{</span>
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font-size</span> : <span style="color: rgb(153, 51, 51);"><span style="color: rgb(153, 51, 51);">300</span>%</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">font-weight</span> : <span style="color: rgb(153, 51, 51);">bold</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">float</span> : <span style="font-weight: bold; color: rgb(0, 0, 0);">left</span>;
<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">width</span> : <span style="color: rgb(153, 51, 51);">1em</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <p><img class="mainslika" alt="CSS Drop Caps" src="http://stylizedweb.com/examples/drop.gif" /></p> <h5>11. Prevent line breaks in links, oversized content to brake</h5><pre class="css">
<br />a<span style="color: rgb(102, 204, 102);">{</span>
<br />white-space<span style="color: rgb(51, 51, 255);">:nowrap</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br /><span style="color: rgb(204, 0, 204);">#main</span><span style="color: rgb(102, 204, 102);">{</span>
<br />overflow<span style="color: rgb(51, 51, 255);">:hidden</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre> <h5>12. Show firefox scrollbar, remove textarea scrollbar in IE</h5><pre class="css">
<br />html<span style="color: rgb(102, 204, 102);">{</span>
<br />overflow<span style="color: rgb(51, 51, 255);">:-moz-scrollbars-vertical</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br />
<br />textarea<span style="color: rgb(102, 204, 102);">{</span>
<br />overflow<span style="color: rgb(51, 51, 255);">:auto</span>;
<br /><span style="color: rgb(102, 204, 102);">}</span>
<br /> </pre>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-24895396431543430972008-06-27T11:47:00.000-07:002008-06-27T11:49:00.405-07:00CSS HACKS<p>If you are front end coder you must know how important is to make cross browses, valid CSS and xHTML code. And also you must know how much time we are spending in all those hacks and fixes for various browsers. I've written about some of them earlier on <a title="PNG transparency issues" href="http://stylizedweb.com/2007/12/30/png-transparency-issues/">PNG transparency issues</a>, <a title="Yellow fields in web form" href="http://stylizedweb.com/2008/01/02/yellow-fields-in-your-web-form/">Yellow fields in web form</a>, <a title="Vertical align div" href="http://stylizedweb.com/2008/02/01/vertical-align-div/">Vertical align div</a> etc..</p> <p>Here is the list of 10 hand picked CSS hacks and tricks which can help you in your CSS code and also save some time.</p> <h5>1. Vertical align div</h5> <p><a href="http://stylizedweb.com/2008/02/01/vertical-align-div/">http://stylizedweb.com/2008/02/01/vertical-align-div/</a></p> <h5>2. Min-Height</h5><pre class="css"><br />selector <span style="color: rgb(102, 204, 102);">{</span><br />min-height<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">500px</span></span>;<br />height<span style="color: rgb(51, 51, 255);">:auto</span>; !important<br />height<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">500px</span></span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br /> </pre> <h5>3. PNG transparency</h5> <p><a href="http://stylizedweb.com/2007/12/30/png-transparency-issues/">http://stylizedweb.com/2007/12/30/png-transparency-issues/</a></p> <h5>4. Autoclear</h5><pre class="css"><br /><span style="color: rgb(102, 102, 255);">.container</span><span style="color: rgb(51, 51, 255);">:after</span> <span style="color: rgb(102, 204, 102);">{</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">content</span>: <span style="color: rgb(255, 0, 0);">"."</span>;<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span>;<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);">0</span>;<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">clear</span>: <span style="color: rgb(153, 51, 51);">both</span>;<br /><span style="font-weight: bold; color: rgb(0, 0, 0);">visibility</span>: <span style="color: rgb(153, 51, 51);">hidden</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br /><span style="color: rgb(102, 102, 255);">.container</span> <span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">inline-table</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* Hides from IE-mac \*/</span><br />* html <span style="color: rgb(102, 102, 255);">.container</span> <span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">height</span>: <span style="color: rgb(153, 51, 51);"><span style="color: rgb(153, 51, 51);">1</span>%</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><span style="color: rgb(102, 102, 255);">.container</span> <span style="color: rgb(102, 204, 102);">{</span><span style="font-weight: bold; color: rgb(0, 0, 0);">display</span>: <span style="color: rgb(153, 51, 51);">block</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* End hide from IE-mac */</span><br /> </pre> <h5>5. Reset CSS</h5><pre class="css"><br />html, body, div, span,<br /> applet, object, iframe,<br /> h1, h2, h3, h4, h5, h6, p,<br /> blockquote, pre, a, abbr, acronym,<br />address, big, cite, code, del, dfn, em,<br /> <span style="font-weight: bold; color: rgb(0, 0, 0);">font</span>, img, ins, kbd, q, s, samp, small,<br /> strike, strong, sub, sup, tt, var, dl, dt,<br /> dd, ol, ul, li, fieldset, form, label, legend,<br /> table, caption, tbody, tfoot, thead, tr, th,<br /> td <span style="color: rgb(102, 204, 102);">{</span><br />border<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span> <span style="color: rgb(153, 51, 51);">none</span>;<br />font-family<span style="color: rgb(51, 51, 255);">:inherit</span>;<br />font-size<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">100</span></span>%;<br />font-style<span style="color: rgb(51, 51, 255);">:inherit</span>;<br />font-weight<span style="color: rgb(51, 51, 255);">:inherit</span>;<br />margin<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br />outline-color<span style="color: rgb(51, 51, 255);">:invert</span>;<br />outline-style<span style="color: rgb(51, 51, 255);">:none</span>;<br />outline-width<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br />padding<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br />vertical-align<span style="color: rgb(51, 51, 255);">:baseline</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />table <span style="color: rgb(102, 204, 102);">{</span><br />border-collapse<span style="color: rgb(51, 51, 255);">:separate</span>;<br />border-spacing<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />caption, th, td <span style="color: rgb(102, 204, 102);">{</span><br />font-weight<span style="color: rgb(51, 51, 255);">:normal</span>;<br />text-align<span style="color: rgb(51, 51, 255);">:left</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />blockquote<span style="color: rgb(51, 51, 255);">:before</span>, blockquote<span style="color: rgb(51, 51, 255);">:after</span>, q<span style="color: rgb(51, 51, 255);">:before</span>, q<span style="color: rgb(51, 51, 255);">:after</span> <span style="color: rgb(102, 204, 102);">{</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">content</span>:<span style="color: rgb(255, 0, 0);">""</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />blockquote, q <span style="color: rgb(102, 204, 102);">{</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">quotes</span>:<span style="color: rgb(255, 0, 0);">""</span> <span style="color: rgb(255, 0, 0);">""</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />strong <span style="color: rgb(102, 204, 102);">{</span><br />font-weight<span style="color: rgb(51, 51, 255);">:bold</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />em <span style="color: rgb(102, 204, 102);">{</span><br />font-style<span style="color: rgb(51, 51, 255);">:italic</span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br />* <span style="color: rgb(102, 204, 102);">{</span><br />margin<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br />padding<span style="color: rgb(51, 51, 255);">:<span style="color: rgb(153, 51, 51);">0pt</span></span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br /> </pre> <h5>6. Scrolling Render IE</h5><pre class="css"><br />html <span style="color: rgb(102, 204, 102);">{</span><br /> <span style="font-weight: bold; color: rgb(0, 0, 0);">background</span> : <span style="color: rgb(153, 51, 51);">url</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(153, 51, 51);">null</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(153, 51, 51);">fixed</span> <span style="color: rgb(153, 51, 51);">no-repeat</span>;<br /> <span style="color: rgb(102, 204, 102);">}</span><br /> </pre> <h5>7. Opacity</h5><pre class="css"><br /><span style="color: rgb(204, 0, 204);">#transdiv</span> <span style="color: rgb(102, 204, 102);">{</span><br />filter<span style="color: rgb(51, 51, 255);">:alpha</span><span style="color: rgb(102, 204, 102);">(</span>opacity=<span style="color: rgb(153, 51, 51);">75</span><span style="color: rgb(102, 204, 102);">)</span>;<br />-moz-opacity:<span style="color: rgb(102, 102, 255);">.<span style="color: rgb(153, 51, 51);">75</span></span>;<br />opacity:<span style="color: rgb(102, 102, 255);">.<span style="color: rgb(153, 51, 51);">75</span></span>;<br /><span style="color: rgb(102, 204, 102);">}</span><br /> </pre> <h5>8. PRE Tag</h5><pre class="css"><br />pre <span style="color: rgb(102, 204, 102);">{</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">white-space</span>: pre-wrap; <span style="color: rgb(128, 128, 128); font-style: italic;">/* css-3 */</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">white-space</span>: -moz-pre-wrap !important; <span style="color: rgb(128, 128, 128); font-style: italic;">/* Mozilla, since 1999 */</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">white-space</span>: -pre-wrap; <span style="color: rgb(128, 128, 128); font-style: italic;">/* Opera 4-6 */</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">white-space</span>: -o-pre-wrap; <span style="color: rgb(128, 128, 128); font-style: italic;">/* Opera 7 */</span><br />word-wrap: break-word; <span style="color: rgb(128, 128, 128); font-style: italic;">/* Internet Explorer 5.5+ */</span><br /><span style="color: rgb(102, 204, 102);">}</span><br /> </pre> <h5>9. Li Background Repeat IE</h5><pre class="css"><br /><!--<span style="color: rgb(102, 204, 102);">[</span>if lt IE <span style="color: rgb(153, 51, 51);">7</span><span style="color: rgb(102, 204, 102);">]</span>><br /><style><br /><span style="color: rgb(204, 0, 204);">#leftnav</span> li <span style="color: rgb(102, 204, 102);">{</span> zoom: <span style="color: rgb(153, 51, 51);">1</span>;<span style="color: rgb(102, 204, 102);">}</span> <span style="color: rgb(128, 128, 128); font-style: italic;">/* haslayout=true */</span><br /></style><br /><br /><!<span style="color: rgb(102, 204, 102);">[</span>endif<span style="color: rgb(102, 204, 102);">]</span>--><br /> </pre> <h5>10. Good to know</h5><pre class="css"><br /><span style="color: rgb(161, 161, 0);">@charset "UTF-8";</span><br /><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* ----------------------------------------------------------------------<br /> WinIE7<br />---------------------------------------------------------------------- */</span><br />*<span style="color: rgb(51, 51, 255);">:first-child</span>+html selector<span style="color: rgb(102, 204, 102);">{</span>property<span style="color: rgb(51, 51, 255);">:value</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* ----------------------------------------------------------------------<br /> WinIE6 & Mac IE<br />---------------------------------------------------------------------- */</span><br />* html selector<span style="color: rgb(102, 204, 102);">{</span>property<span style="color: rgb(51, 51, 255);">:value</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* ----------------------------------------------------------------------<br /> WinIE6<br />---------------------------------------------------------------------- */</span><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/*\*/</span><br />* html selector<span style="color: rgb(102, 204, 102);">{</span>property<span style="color: rgb(51, 51, 255);">:value</span>;<span style="color: rgb(102, 204, 102);">}</span><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/**/</span><br /><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/* ----------------------------------------------------------------------<br /> MacIE<br />---------------------------------------------------------------------- */</span><br /><span style="color: rgb(128, 128, 128); font-style: italic;">/*\*/</span><span style="color: rgb(128, 128, 128); font-style: italic;">/*/<br />selector{property:value;}<br />/**/</span><br /> </pre>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-27813429863278001452008-06-27T11:44:00.000-07:002008-06-27T11:46:56.703-07:00CSS and Round Corners: Build Boxes with Curves<p><strong>One of the main reasons why designers use images on a Web page is to create curves and round corners. It's currently impossible to create any kind of curved shapes using pure <a class="glossary" title="HTML stands for HyperText Markup Language." href="/glossary.php?q=H#term_75">HTML</a>, so images need to be applied.</strong></p> <p>The problem? Putting these images into an HTML document with a table layout can create a large amount of superfluous code. In this tutorial, we'll use <a class="glossary" title="CSS, or Cascading Style Sheets, comprise styling and formatting rules that are applied to Web documents." href="/glossary.php?q=C#term_8">CSS</a> to create <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners8.htm">this box with round corners</a>, without an <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/img"><img></a></code> tag in sight!</p> <h5>How it Works</h5> <p>The above is basically a normal box that has an orange background colour, over which four corner images are superimposed. All these images have been called up through CSS commands.</p> <p>So, we start off with the following snippet:</p> <p><code><div class="bl">Lorem ipsum dolor sit amet consectetur adipisicing elit</div></code></p> <p>We've used <code>class="bl"</code> as we're going to assign our bottom right corner to this <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code> through a CSS command. As a rule, you can only assign one background image to an HTML tag using CSS, so this is the only image we'll assign to this <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>.</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/1bl.gif"><em>1465_1bl (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/1bl.gif" height="10" width="10" /></a></p>
<br /><p>
<br /></p><p>We'll use the above image, called bl.gif, which we'll place in the bottom-left corner with the following CSS command:</p> <p><code>.bl {background: url(bl.gif) 0 100% no-repeat; width: 20em}</code></p> <p>The CSS background command is broken into three sections: the image URL, its position, and a repeat command. We also inserted a width CSS command so that the box doesn't cover the whole of the screen. Let's examine the three background commands in turn:</p> <p> </p><ol><li><strong>Image URL</strong> - Remember, the image is being called through the CSS, so the path to the image must be the path from the CSS document, not the HTML document.
<br /></li><li><strong>Image Position</strong> - In this example, we've used the command <code>0 100%</code> in our CSS rule. The first number represents the distance from the left edge of the <code><div> ;</code> the second number identifies the distance from the top edge. In this instance <code>%</code> was used, but a different distance value, such as em or px, could just as easily have been used instead. If this command was left out, the default value, <code>0 0</code>, would be used, and the image would be placed in the top-left corner.
<br /></li><li><strong>Repeat Command</strong> – Obviously, we don't want this image to repeat, so we insert the <code>no-repeat</code> CSS command. If we wanted to, we could have used <code>repeat-x</code>, to repeat the image horizontally, <code>repeat-y</code>, to repeat it vertically, and <code>repeat</code> to repeat it both horizontally and vertically. If this command was left out, the default value, <code>repeat</code>, would be used. </li></ol> <p>It doesn't matter in which order these three CSS background commands are placed. <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners3.htm">Our box with curves now looks like this</a>.</p> <h5>Bottom-Right Curve</h5> <p>Next, we'll stick in that bottom-right curve. As previously mentioned, we can only assign one background image to each <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code> in the CSS, so we'll need to insert a new <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>:</p> <p><code><div class="bl"><div class="br">
<br />Lorem ipsum dolor sit amet consectetur adipisicing elit
<br /></div></div></code></p> <p>Here's the image we'll use:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/1br.gif"><em>1465_1br (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/1br.gif" height="10" width="10" /></a></p> <p>Naming this bottom-right image br.gif, we'll insert a new CSS rule:</p> <p><code>.br {background: url(br.gif) 100% 100% no-repeat}</code></p> <p>This CSS rule is essentially the same as the last one, although now we've changed the position from the left to 100%, where previously it was 0%. <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners4.htm">The box now looks like this</a>.</p> <h5>Top Curves</h5> <p>To make our top curves, we'll need two new images:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/1tl.gif"><em>1465_1tl (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/1tl.gif" height="10" width="10" /></a></p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/1tr.gif"><em>1465_1tr (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/1tr.gif" height="10" width="10" /></a></p> <p>We'll call these tl.gif and tr.gif. We'll need to create two new <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>s for them:</p> <p><code><div class="bl"><div class="br"><div class="tl"><div class="tr">
<br />Lorem ipsum dolor sit amet consectetur adipisicing elit
<br /></div></div></div></div></code></p> <p>The new CSS rules are as follows:</p> <p><code>.tl {background: url(tl.gif) 0 0 no-repeat}
<br />.tr {background: url(tr.gif) 100% 0 no-repeat}</code></p> <p>These give us <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners5.htm">this display</a>.</p> <h5>Background Colour</h5> <p>We'll now insert our orange background colour into the box, in order to achieve the whole round corners effects.
<br />
<br />The background colour must always be assigned to the very first CSS rule. This is because each CSS background rule is essentially a layer on top of the previous one. So, in this example, we have a layering order of br.gif, bl.gif, tl.gif and then tr.gif. But, in this example, the images don't overlap, so we don't really notice this layering effect.</p> <p>By default, a background colour covers the entire <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code> and will layer on top of any other previously assigned background images and/or colours. Therefore, if we place the orange colour in any <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code> other than the first, it will be placed on top of the preceding images and will essentially cause them to disappear. Therefore, we must place our orange background colour (#e68200) in the very first CSS rule:</p> <p><code>.bl {background: url(bl.gif) 0 100% no-repeat #e68200; width: 20em}</code></p> <p>As before, it doesn't matter where we place this colour command within the CSS background rule. <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners6.htm">Our box now looks like this</a>.</p> <h5>Padding</h5> <p>Padding is needed to prevent the text from overlapping on to the images, which are 10px x 10px in size. Therefore, we need 10px-worth of padding on the text. But to which <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code> should we assign the padding CSS rule? Does it matter? Well, yes it does.</p> <p>Whichever element we assign padding to, each of the elements inside it will inherit that padding. If we were to assign padding to the very first <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>, <code><div class=""></code>, <a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners7.htm">we'd get this effect</a>.</p> <p>To get this padding to work properly, we need to assign it to the very last <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>, <code><div class="bl"></code>:
<br />
<br /><code>.tr {background: url(tr.gif) 100% 0 no-repeat; padding:10px}</code></p> <p><a class="sublink" href="http://www.sitepoint.com/examples/roundcorners/box-corners8.htm">Here's how it looks now</a>.</p> <h5>Internet Explorer Issues</h5> <p>You may have noticed the bottom corners were called up before the top corners. If we were to do things the other way round, that is, call the top corners first, some parts of the orange background colour would sneak out under the bottom curves, causing a rather unsightly effect. Switch the order of the <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/div"><div></a></code>s around and see for yourself.</p> <p>Another issue in Internet Explorer is that the background colour of the box sometimes overlaps on to the element below, again causing an unattractive effect. This can be solved simply by placing a tiny placeholder beneath the box with round corners. Immediately after the fourth closing <code></div></code>, insert the following HTML:</p> <p><code><div class="clear"> </div></code></p> <p>Now, assign it this CSS rule:</p> <p><code>.clear {font-size: 1px; height: 1px}</code></p> <h5>The Final Code</h5> <p>Our finished HTML now looks like this:</p> <p><code><div class="bl"><div class="br"><div class="tl"><div class="tr">
<br />Lorem ipsum dolor sit amet consectetur adipisicing elit
<br /></div></div></div></div>
<br /><div class="clear"> </div></code></p> <p>Here's the CSS that makes it all happen:</p> <p><code>.bl {background: url(bl.gif) 0 100% no-repeat #e68200; width: 20em}
<br />.br {background: url(br.gif) 100% 100% no-repeat}
<br />.tl {background: url(tl.gif) 0 0 no-repeat}
<br />.tr {background: url(tr.gif) 100% 0 no-repeat; padding:10px}
<br />.clear {font-size: 1px; height: 1px}</code></p> <script src="http://ads.aws.sitepoint.com/adjs.php?region=79&did=adz&adtype=vertical" type="text/javascript"></script> jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-90761914352878197762008-06-27T11:42:00.000-07:002008-06-27T11:44:51.032-07:00CSS and Round Corners: Build Accessible Menu Tabs<p><strong>One of the best Websites out there, in terms of functionality, is <a class="sublink" href="http://www.amazon.com/" rel="external">Amazon</a>. </strong></p> <p>In terms of <a class="glossary" title="Accessibility deals with the issues of making online content available for experience, enjoyment, and use by all visitors, including those who do not fit the standard "Web user" mould." href="/glossary.php?q=A#term_61">accessibility</a>, though, it's not great.</p> <h5>The Problem</h5> <p>Amazon's menu tabs, with their nice round corners, look good -- but they're totally inaccessible. First of all, they're missing ALT tags. Additionally, the <a class="glossary" title="The World Wide Web Consortium (W3C) - A consortium of industry leaders for drafting Web standards." href="/glossary.php?q=W#term_49">W3C</a> accessibility guideline 3.1 (priority 2) clearly states:</p><q>When an appropriate markup language exists, use markup rather than images to convey information.</q> <p>This basically means that we shouldn't use images to display text. Users with poor vision are unable to <a class="sublink" href="http://www2.tec.govt.nz/home/accessibility.htm#text" rel="external">resize text</a> that's displayed through images. Similarly, users of <a class="sublink" href="http://www.magnifiers.org/links/Download_Software/Screen_Magnifiers/" rel="external">screen magnifiers</a> may be unable to read text embedded in images, as it can appear blurry and pixelated to them.</p> <h5>The Solution: <a class="glossary" title="CSS, or Cascading Style Sheets, comprise styling and formatting rules that are applied to Web documents." href="/glossary.php?q=C#term_8">CSS</a> Menu Tabs</h5> <p>CSS, as usual, comes to our rescue. Look at this menu tab, created through <a class="glossary" title="HTML stands for HyperText Markup Language." href="/glossary.php?q=H#term_75">HTML</a> and CSS -- not an <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/img"><img></a></code> tag in sight! </p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home1.gif"><em>1388_home1 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home1.gif" height="37" width="90" /></a></p> <p>Have a <a class="sublink" href="http://www.sitepoint.com/examples/cssaccessiblenav/css-1.htm" rel="external">look at it in action</a> -- when you do, adjust the text size in your browser. Notice that the menu tab increased in size with the text: it all fits perfectly. </p> <p>Today, you're going to learn how to do this.</p> <p><strong><em>How It's Done</em></strong></p> <p>We start with a simple link:</p> <p><code><div id="navigation"><a href="#">Home</a></div></code></p> <p>We'll assign it this CSS code:</p> <p><code>#navigation a
<br />{
<br />color: #000;
<br />background: #fb0;
<br />text-decoration: none
<br />}</code>
<br />
<br />This gives us the following result:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home2.gif"><em>1388_home2 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home2.gif" height="43" width="77" /></a></p> <p>It needs a bit of work, right? Let's do it.</p> <p><strong><em>Add the Left Menu Tab Corner</em></strong></p> <p>We need to make a small image with the same colour for the rounded left-hand corner. Here's one I made earlier.
<br />
<br /><a class="beatbox" href="http://sitepointstatic.com/graphics/tab-orange-left2.gif"><em>1388_taborangeleft (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/tab-orange-left2.gif" height="16" width="10" /></a></p> <p>Let's call this image left-tab.gif and place it into the background of the link using this CSS rule:</p> <p><code>#navigation a
<br />{
<br />color: #000;
<br />background: #fb0 url("left-tab.gif") left top no-repeat;
<br />text-decoration: none
<br />}</code></p> <p>This new CSS rule says that the background image should be left-menu-tab.gif, the image should be on the left at the top, and it shouldn't be repeated. The result?</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home3.gif"><em>1388_home3 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home3.gif" height="38" width="73" /></a></p> <p>We're getting there, but we need to move the text over slightly as it's overlapping the left rounded corner. It's pretty simple to reposition the text with the addition of padding to our CSS rule:</p> <p><code>#navigation a
<br />{
<br />color: #000;
<br />background: #fb0 url("left-tab.gif") left top no-repeat;
<br />text-decoration: none;
<br /><strong>padding-left: 10px</strong>
<br />}</code></p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home4.gif"><em>1388_home4 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home4.gif" height="39" width="83" /></a></p> <p><strong><em>The Right Corner</em></strong></p> <p>We can only assign one background image to a CSS rule, so we need to make a new CSS rule and assign the right corner image to that. We'll start by inserting a <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code> tag into the HTML code:</p> <p><code><div id="navigation"><a href="/"><strong><span></strong>Home<strong></span></strong></a></div></code></p> <p>Now we'll create a new CSS rule in which we'll assign the right menu tab shown below (another one I made earlier) to the <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code>, and we're ready to go! </p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/tab-orange-right2.gif"><em>1388_taborangeright (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/tab-orange-right2.gif" height="16" width="10" /></a></p> <p>We'll name this image right-tab.gif.</p> <p><code>#navigation a span
<br />{
<br />background: url("right-tab.gif") right top no-repeat;
<br />}</code></p> <p>This CSS rule means that every <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code> tag within an <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/a"><a></a></code> tag will have this image as its background. The final result looks like this:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home5.gif"><em>1388_home5 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home5.gif" height="39" width="81" /></a></p> <p>Perfect... No, wait a minute! Can you spot why it's not so perfect? We forgot to assign some padding to that <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code> tag in the CSS rule:</p> <p><code>#navigation a span
<br />{
<br />background: url("right-tab.gif") right top no-repeat;
<br /><strong>padding-right: 10px</strong>
<br />}</code></p> <p>This code gives us:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/home1.gif"><em>1388_home1 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/home1.gif" height="37" width="90" /></a></p> <p>Now, that really is perfect! Have a <a class="sublink" href="http://www.sitepoint.com/examples/cssaccessiblenav/css-1.htm" rel="external">look at the results here</a> and resize the text to see how it looks.</p> <p><strong><em>The Final CSS Touches</em></strong></p> <p>Let's assign this link a nice hover effect using a few final CSS rules. We'll need a couple more background images:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/tab-blue-left2.gif"><em>1388_tabblueleft (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/tab-blue-left2.gif" height="16" width="10" /></a></p> <p>We'll call this left-tab-hover.gif.
<br />
<br /><a class="beatbox" href="http://sitepointstatic.com/graphics/tab-blue-right2.gif"><em>1388_tabblueright (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/tab-blue-right2.gif" height="16" width="10" /></a></p> <p>This one's named right-tab-hover.gif.</p> <p>Now, we just insert the following CSS rules, and away we go!</p> <p><code>#navigation <strong>a:hover</strong> {
<br />color: #fff;
<br />background: #fb0 url(<strong>"left-tab-hover.gif"</strong>) left top no-repeat;
<br />text-decoration: none;
<br />padding-left: 10px
<br />}
<br />
<br />#navigation <strong>a:hover</strong> span
<br />{
<br />background: url(<strong>"right-tab-hover.gif"</strong>) right top no-repeat;
<br />padding-right: 10px
<br />}</code></p> <p>Have a <a class="sublink" href="http://www.sitepoint.com/examples/cssaccessiblenav/css-2.htm" rel="external">look at this code in action</a> -- be sure to mouse over it! </p> <h5>Make a Tab Menu</h5> <p>Now we've done all the hard work, we can make as many of these menu tabs as we want:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/nav.gif"><em>1388_nav (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/nav.gif" height="70" width="504" /></a></p> <p><a class="sublink" href="http://www.sitepoint.com/examples/cssaccessiblenav/css-3.htm" rel="external">See the nav in action</a> -- be sure to mouse over the nav items! </p> <p>Looks great, doesn't it? Note, though, that building your menu this way does bring up a new accessibility problem: this navigation won't make sense to anyone who has disabled CSS. Without CSS, the navigation looks like this:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/nocssnav.png"><em>1388_nocssnav (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/nocssnav.png" height="33" width="314" /></a></p> <p>That's quite a problem. The solution? Let's put the tabs into a list! The HTML will look like this:</p> <p><code><<strong>ul id="navigation"</strong>>
<br /><<strong>li</strong>><a href="/"><span>Home</span></a><<strong>/li</strong>>
<br /><<strong>li</strong>><a href="/"><span>Services</span></a><<strong>/li</strong>>
<br /><<strong>li</strong>><a href="/"><span>Take a tour</span></a><<strong>/li</strong>>
<br /><<strong>li</strong>><a href="/"><span>About us</span></a><<strong>/li</strong>>
<br /><<strong>li</strong>><a href="/"><span>Contact us</span></a><<strong>/li</strong>>
<br /><<strong>/ul</strong>></code>
<br />
<br />Now, let's create some CSS rules for our list items, so that all the menu tabs display next to one other on the same line:</p><p><code>#navigation
<br />{
<br />list-style: none;
<br />padding: 0;
<br />margin: 0;
<br />}
<br />
<br />#navigation li
<br />{
<br />float: left;
<br />display: block;
<br />margin: 0;
<br />padding: 0;
<br />}</code></p> <p>To get rid of the bullets, we used the CSS command, <code>list-style: none</code>. To display our menu tabs inline, stacked next to each other, we used <code>float: left</code>.</p> <p>At this point, some of the more expert CSS coders may question the point of keeping the <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code> tag, especially those who've read <a class="sublink" href="http://www.alistapart.com/articles/slidingdoors/" rel="external">Doug Bowman's Sliding Doors article</a>. The reason we leave in the <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/span"><span></a></code> tag is to make the entire menu tab clickable. If we were to assign one of the corners to <code class="ref-term"><a title=""> tag in the SitePoint HTML Reference." href="http://reference.sitepoint.com/html/li"><li></a></code> as a background image, that corner wouldn't be clickable.</p> <h5>IE 5.x Problems</h5> <p>Unfortunately, these tabs won't work on IE 5.0 on PC (and a couple of other browsers), as the rounded edges of the tabs don't appear. As such, each menu tab will be displayed as a rectangle, with sharp corners. There's an easy solution to this, which is to insert <code>display: block</code> into the <code>#navigation a</code> and <code>#navigation a span</code> CSS commands.</p> <p>Sounds easy, right? Unfortunately, it's not. By inserting these commands into the CSS, IE 5 on Mac will stack the menu items on top of each other. To make these display properly for IE 5 on Mac, we'll need to also insert the <code>float:left</code> command, but apply it only to this browser. But how do we apply a CSS command to just one browser? Easy -- we use the commented backslash hack:</p> <p><code>#navigation a, #navigation a span
<br />{
<br />display: block;
<br /><strong>float: left</strong>
<br />}
<br />
<br />/* Commented backslash hack hides rule from <a class="glossary" title="Microsoft Internet Explorer is the leading Web browser on Microsoft Windows OS." href="/glossary.php?q=I#term_30">IE5</a>-Mac \*/
<br />#navigation a, #navigation a span
<br />{
<br /><strong>float: none</strong>
<br />}
<br />/* End IE5-Mac hack */ </code></p> <p>The first CSS command says to float the menu tab content to the left, and the second CSS command cancels this out for every browser except IE 5 on Mac. When two CSS commands are specified for the same selector, the second one always takes precedence. However, IE 5 on Mac can't read the second command because of the slashes and stars, so defaults to the first CSS command. (If you really want to know how and why this works, read <a class="sublink" href="http://www.sam-i-am.com/work/sandbox/css/mac_ie5_hack.html" rel="external">Commented Backslash MacIE5 CSS Hack by Sam Foster</a>.)</p> <h5>The Final Code</h5> <p>The final HTML is:</p> <p><code><ul id="navigation">
<br /><li><a href="/"><span>Home</span></a></li>
<br /><li><a href="/"><span>Services</span></a></li>
<br /><li><a href="/"><span>Take a tour</span></a></li>
<br /><li><a href="/"><span>About us</span></a></li>
<br /><li><a href="/"><span>Contact us</span></a></li>
<br /></ul> </code></p> <p>And here's the entire CSS code:</p> <p><code>#navigation a
<br />{
<br />color: #000;
<br />background: #fb0 url("left-tab.gif") left top no-repeat;
<br />text-decoration: none;
<br />padding-left: 10px
<br />}
<br />
<br />#navigation a span
<br />{
<br />background: url("right-tab.gif") right top no-repeat;
<br />padding-right: 10px
<br />}
<br />
<br />#navigation a, #navigation a span
<br />{
<br />display: block;
<br />float: left
<br />}
<br />
<br />/* Commented backslash hack hides rule from IE5-Mac \*/
<br />#navigation a, #navigation a span
<br />{
<br />float: none
<br />}
<br />/* End IE5-Mac hack */
<br />
<br />#navigation a:hover
<br />{
<br />color: #fff;
<br />background: #26a url("left-tab-hover.gif") left top no-repeat;
<br />text-decoration: none;
<br />padding-left: 10px
<br />}
<br />
<br />#navigation a:hover span
<br />{
<br />background: url("right-tab-hover.gif") right top no-repeat;
<br />padding-right: 10px
<br />}
<br />
<br />#navigation
<br />{
<br />list-style: none;
<br />padding: 0;
<br />margin: 0
<br />}
<br />
<br />#navigation li
<br />{
<br />float: left;
<br />display: block;
<br />margin: 0;
<br />padding: 0
<br />}</code></p> <h5>The End Product... With and Without CSS</h5> <p>Let's look at it one more time. First, the CSS version of the nav:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/nav.gif"><em>1388_nav (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/nav.gif" height="70" width="504" /></a></p> <p>When CSS is disabled, it looks like this:</p> <p><a class="beatbox" href="http://sitepointstatic.com/graphics/navcssdisabled.png"><em>1388_navdisabled (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/navcssdisabled.png" height="108" width="125" /></a></p> <p>Now, that really is <a class="glossary" title="Accessibility deals with the issues of making online content available for experience, enjoyment, and use by all visitors, including those who do not fit the standard "Web user" mould." href="/glossary.php?q=A#term_61">accessible</a>!</p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-39964189508340084632008-06-27T11:40:00.000-07:002008-06-27T11:42:14.884-07:00Style Web Forms Using CSS<p><strong>Whether your main business is Web design or backend development, chances are you spend a fair amount of time creating forms for user input. So you already know that the default appearance of forms isn't always appropriate for the look and feel of your site.</strong></p> <p>In this article we'll look at how you can use <span class="glossary">CSS</span> to create attractive and usable forms.</p> <h5>Styling Form Elements</h5> <p>It's possible to change the default look of form elements by styling their <span class="glossary">html</span> tags: <code class="ref-term">input</code>, <code class="ref-term">select</code> and <code class="ref-term">textarea</code>.</p> <p><strong><em>The <code class="ref-term">input</code> Tag</em></strong></p> <p>Defining rules for the input tag will change any instance of that tag in your document. For example, if I wish all elements to have a purple background, I could define the following in my style sheet. </p> <p><code>input {
<br /> background-color: #666699;
<br />}</code></p> <p>This will add a purple background color to those elements that are marked up using the input tag.
<br />
<br /><span class="beatbox"><em>1166_image1 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/rimg1.jpg" height="202" width="185" /></span></p> <p><strong><em>The <code class="ref-term">select</code> Tag</em></strong></p> <p>The <code class="ref-term"><select></code> tag creates a list menu. You can create rules for select which will affect any list menus in your document.</p> <p><code>select {
<br /> background-color: #666699;
<br /> color: #ffffff;
<br />}</code>
<br />
<br /><span class="beatbox"><em>1166_image2 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/rimg2.jpg" height="116" width="102" /></span></p> <p><strong><em>The <code class="ref-term">textarea</code> Tag</em></strong></p> <p>The <code class="ref-term"><textarea></code> tag marks up multiple line text input fields. Once again, setting rules for textarea will change the look of all of these elements in your document.</p> <p><code>textarea {
<br /> background-color: #666699;
<br /> color: #ffffff;
<br />}</code>
<br />
<br /><span class="beatbox"><em>1166_image3 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/rimg3.jpg" height="107" width="355" /></span></p> <p><strong><em>The <code class="ref-term">form</code> Tag</em></strong></p> <p>You can also style the form tag itself, adding borders, background colors and adjusting the margins and padding. Form is a block level element, so you can change the way it displays in much the same way that you would style a paragraph.</p> <p><code>form {
<br /> border: 1px solid #666699;
<br /> padding: 5px;
<br />}</code>
<br />
<br /><span class="beatbox"><em>1166_image4 (click to view image)</em><img alt="" src="http://sitepointstatic.com/graphics/rimg4.jpg" height="176" width="285" /></span></p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-71379433304188969172008-06-27T11:36:00.000-07:002008-06-27T11:38:24.388-07:00Style Web Forms Using CSSWe continue to review text and source editors for designers and web-developers. After a thorough consideration of WYSIWIG- and source code editors now it’s time to take a closer look at applications for advanced CSS-coding. Reason: while numerous HTML-editors offer more or less advanced CSS-support there are also allround-CSS-editors which offer a sophisticated integrated development environment for CSS-coding.<br /><br />Of course, real CSS ninjas accept nothing but a minimalistic Notepad or some sophisticated source code-editor. In fact, CSS-editors are often considered to be unnecessary and superflous — after all, you can do the same in your favourite text editor. And sometimes this is true — while there are some really bad HTML-editors there are also some even worse CSS-editors. Particularly code autocompletion tools are extremely good at bloating the code to extremes, making the resulting stylesheet unnecessary complex and hard to maintain. Why would someone purchase a CSS-editor to raise the maintenance costs afterwards?<br /><br />Yet CSS-editors can be helpful; furthermore, you can effectively use them in different settings by developers with different skills. Web professionals can use a CSS-editor to improve workflow and get all useful CSS-tools provided by one single application. Newbies can easier learn CSS by analzying stylesheets and using live-editing to understand how the design is built up and what is actually going on behind the scenes. In either case you should make sure you know what you are doing and not end up producing quick’n'dirty stylesheet.jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-284116574688062912008-06-27T11:33:00.000-07:002008-06-27T11:36:08.947-07:0070 Expert Ideas For Better CSS CodingCSS isn’t always easy to deal with. Depending on your skills and your experience, CSS coding can sometimes become a nightmare, particularly if you aren’t sure which selectors are actually being applied to document elements. An easy way to minimize the complexity of the code is as useful as not-so-well-known CSS attributes and properties you can use to create a semantically correct markup.
<br />
<br />We’ve taken a close look at some of the most useful CSS tricks, tips, ideas, methods, techniques and coding solutions and listed them below. We also included some basic techniques you can probably use in every project you are developing, but which are hard to find once you need them.
<br />
<br />And what has come out of it is an overview of over 70 expert CSS ideas which can improve your efficiency of CSS coding. You might be willing to check out the list of references and related articles in the end of this post.
<br />
<br />We’d like to express sincere gratitude to all designers who shared their ideas, techniques, methods, knowledge and experience with their readers. Thank you, we, coders, designers, developers, information architects - you name it - really appreciate it.
<br />
<br />You might be interested in reading our article 53 CSS-Techniques You Couldn’t Live Without, which should provide you with a basic toolbox for CSS-based techniques you might use in your next projects.
<br />
<br />Update (29/05/2007): Brazilian-Portuguese translation of the article is also available. Thanks to Maurício Samy Silva.
<br />
<br />1.1. Workflow: Getting Started
<br />After you have a design, start with a blank page of content. “Include your headers, your navigation, a sample of the content, and your footer. Then start adding your html markup. Then start adding your CSS. It works out much better.” [CSSing]
<br />Use a master stylesheet. “One of the most common mistakes I see beginners and intermediates fall victim to when it comes to CSS is not removing the default browser styling. This leads to inconsistencies in the appearance of your design across browsers, and ultimately leaves a lot of designers blaming the browser. It is a misplaced blame, of course. Before you do anything else when coding a website, you should reset the styling.” [Master Stylesheet: The Most Useful CSS Technique], [Ryan Parr]
<br />master.css
<br />@import url(”reset.css”);
<br />@import url(”global.css”);
<br />
<br />@import url(”flash.css”);
<br />@import url(”structure.css”);
<br /><style type="text/css" media="Screen">
<br />/**/@import url("css/master.css");/**/
<br /></style>
<br />Reset your CSS-styles first. “You can often eliminate the need to specify a value for a property by taking advantage of that property’s default value. Some people like doing a Global white space reset by zeroing both margin and padding for all elements at the top of their stylesheets. [Roger Johansson]
<br />Keep a library of helpful CSS classes. Useful for debugging, but should be avoided in the release version (separate markup and presentation). Since you can use multiple class names (i.e. <p class="floatLeft alignLeft width75">...</p>), make use of them debugging your markup. (updated) [Richard K. Miller]
<br />CSS:
<br />.width100 { width: 100%; }
<br />.width75 { width: 75%; }
<br />.width50 { width: 50%; }
<br />.floatLeft { float: left; }
<br />.floatRight { float: right; }
<br />.alignLeft { text-align: left; }
<br />.alignRight { text-align: right; }
<br />Eric Meyer’s Global Reset, Christian Montoya’s initial CSS file, Mike Rundle’s initial CSS file, Ping Mag’s initial CSS file.
<br />1.2. Organize your CSS-code
<br />Organize your CSS-styles, using master style sheets. “Organizing your CSS helps with future maintainability of the site. Start with a master style sheet. Within this style sheet import your reset.css, global.css, flash.css (if needed) and structure.css and on occasion a typography style sheet. Here is an example of a “master” style sheet and how it is embedded in the document:”
<br />h2 { }
<br />#snapshot_box h2 {
<br /> padding: 0 0 6px 0;
<br /> font: bold 14px/14px "Verdana", sans-serif; }
<br />#main_side h2 {
<br /> color: #444;
<br /> font: bold 14px/14px "Verdana", sans-serif; }
<br />.sidetagselection h2 {
<br /> color: #fff;
<br /> font: bold 14px/14px "Verdana", sans-serif; }
<br />Organize your CSS-styles, using flags. “Divide your stylesheet into specific sections: i.e. Global Styles – (body, paragraphs, lists, etc), Header, Page Structure, Headings, Text Styles, Navigation, Forms, Comments, Extras. [5 Tips for Organizing Your CSS]
<br />/* -----------------------------------*/
<br />/* ---------->>> GLOBAL <<<-----------*/
<br />/* -----------------------------------*/
<br />Organize your CSS-styles, making a table of contents. At the top of your CSS document, write out a table of contents. For example, you could outline the different areas that your CSS document is styling (header, main, footer etc). Then, use a large, obvious section break to separate the areas. [5 Steps to CSS Heaven]
<br />Organize your CSS-styles, ordering properties alphabetically. “I don’t know where I got the idea, but I have been alphabetizing my CSS properties for months now, and believe it or not, it makes specific properties much easier to find.” [Christian Montoya]
<br />body {
<br /> background: #fdfdfd;
<br /> color: #333;
<br /> font-size: 1em;
<br /> line-height: 1.4;
<br /> margin: 0;
<br /> padding: 0;
<br />}
<br />Separate code into blocks.. “This might be common sense to some of you but sometimes I look at CSS and it’s not broken down into “sections.” It’s easy to do an it makes working with code weeks, months, or years later much easier. You’ll have an easier time finding classes and elements that you need to change. Examples: /* Structure */, /* Typography */ etc.” [CSS Tips and Tricks]
<br />Hook, line, and sinker. Once you have your CSS and sections in place start considering where your selector “hooks” will live by using structural hooks in your mark up. This is your saving grace for future editing and maintenance of the site. This will also give you strength in your document.” [Ryan Parr]
<br />Break your style sheet in separate blocks. “I break down my style sheet into three separate blocks. The first is straight element declarations. Change the body, some links styles, some header styles, reset margins and padding on forms, and so on. […] After element declarations, I have my class declarations; things like classes for an error message or a callout would go here. [..] I start by declaring my main containers and then any styles for elements within those containers are indented. At a quick glance, I can see how my page is broken down and makes it easier to know where to look for things. I’ll also declare containers even if they don’t have any rules.” [Jonathan Snook]
<br />1.3. Workflow: Handling IDs, Classes, Selectors, Properties
<br />Keep containers to a minimum. “Save your document from structural bloat. New developers will use many div’s similar to table cells to achieve layout. Take advantage of the many structural elements to achieve layout. Do not add more div’s. Consider all options before adding additional wrappers (div’s) to achieve an effect when using a little nifty CSS can get you that same desired effect.” [Ryan Parr]
<br />Keep properties to a minimum. “Work smarter, not harder with CSS. Under this rule, there are a number of subrules: if there isn’t a point to adding a CSS property, don’t add it; if you’re not sure why you’re adding a CSS property, don’t add; and if you feel like you’ve added the same property in lots of places, figure out how to add it in only one place.” [CSSing]
<br />Keep selectors to a minimum. “Avoid unnecessary selectors. Using less selectors will mean less selectors will be needed to override any particular style — that means it’s easier to troubleshoot.” [Jonathan Snook]
<br />Keep CSS hacks to a minimum. “Don’t use hacks unless its a known and documented bug. This is an important point as I too often see hacks employed to fix things that aren’t really broken in the first place. If you find that you are looking for a hack to fix a certain issue in your design then first do some research (Google is your friend here) and try to identify the issue you are having problems with. [10 Quick Tips for an easier CSS life]
<br />Use CSS Constants for faster development. “The concept of constants – fixed values that can be used through your code [is useful]. [..] One way to get round the lack of constants in CSS is to create some definitions at the top of your CSS file in comments, to define ‘constants’. A common use for this is to create a ‘color glossary’. This means that you have a quick reference to the colors used in the site to avoid using alternates by mistake and, if you need to change the colors, you have a quick list to go down and do a search and replace.” [Rachel Andrew]
<br /># /*
<br /># Dark grey (text): #333333
<br /># Dark Blue (headings, links) #000066
<br /># Mid Blue (header) #333399
<br /># Light blue (top navigation) #CCCCFF
<br /># Mid grey: #666666
<br /># */
<br />Use a common naming system. Having a naming system for id’s and classes saves you a lot of time when looking for bugs, or updating your document. Especially in large CSS documents, things can get a big confusing quickly if your names are all different. I recommend using a parent_child pattern. [10 CSS Tips]
<br />Name your classes and IDs properly, according to their semantics. “We want to avoid names that imply presentational aspects. Otherwise, if we name something right-col, it’s entirely possible that the CSS would change and our “right-col” would end up actually being displayed on the left side of our page. That could lead to some confusion in the future, so it’s best that we avoid these types of presentational naming schemes. [Garrett Dimon]
<br />Group selectors with common CSS declarations. “Group selectors. When several element types, classes, or id:s share some properties, you can group the selectors to avoid specifying the same properties several times. This will save space – potentially lots of it.” [Roger Johansson]
<br />Isolate single properties that you are likely to reuse a lot. “If you find yourself using a single property a lot, isolate it to save yourself repeating it over and over again and also enabling you to change the display of all parts of the site that use it.” [5 Steps to CSS Heaven]
<br />Move ids and class naming as far up the document tree as you can. Leverage contextual selectors as much as possible. Don’t be afraid to be verbose in your selectors. Longer selectors can make css documents easier to read while also cutting down the chances of developing class- or divitis. [Chric Casciano]
<br />Learn to exploit the cascading nature of CSS. “Say you have two similar boxes on your website with only minor differences - you could write out CSS to style each box, or you could write CSS to style both at the same time, then add extra properties below to make one look different.” [5 Steps to CSS heaven]
<br />Use Your Utility Tags: <small>, <em> and <strong>. “Many times you’ll have a section in your design that calls for various typographical weights/looks all on the same line, or very close to each other. drop in random divs and classes because I feel they’re not semantic and defeat the purpose of your nice XHTML everywhere else.” Instead, use semantic tags. [Mike Rundle’s 5 CSS Tips]
<br />1.4. Workflow: Use shorthand notation
<br />Shorten hexadecimal colour notation. “In CSS, when you use hexadecimal colour notation and a colour is made up of three pairs of hexadecimal digits, you can write it in a more efficient way by omitting every second digit: #000 is the same as #000000, #369 is the same as #336699 [Roger Johansson]
<br />Define pseudo classes for links in the LoVe/HAte-order: Link, Visited, Hover, Active. “To ensure that you see your various link styles, you’re best off putting your styles in the order “link-visited-hover-active”, or “LVHA” for short. If you’re concerned about focus styles, they may go at the end– but wait until you’ve read this explanation before you decide.” [Eric Meyer]
<br />a:link { color: blue; }
<br />a:visited { color: purple; }
<br />a:hover { color: purple; }
<br />a:active { color: red; }
<br />Define element’s margin, padding or border in TRouBLed-order: Top, Right, Bottom, Left. “When using shorthand to specify an element’s margin, padding or border, do it clockwise from the top: Top, Right, Bottom, Left.” [Roger Johansson]
<br />You can use shorthand properties. “Using shorthand for margin, padding and border properties can save a lot of space.
<br />CSS:
<br />margin: top right bottom left;
<br />margin: 1em 0 2em 0.5em;
<br />(margin-top: 1em; margin-right: 0; margin-bottom: 2em; margin-left: 0.5em;)
<br />CSS:
<br />border: width style color;
<br />border: 1px solid #000;
<br />CSS:
<br />background: color image repeat attachment position;
<br />background: #f00 url(background.gif) no-repeat fixed 0 0;
<br />CSS:
<br />font: font-style (italic/normal) font-variant (small-caps) font-weight font-size/line-height font-family;
<br />font: italic small-caps bold 1em/140% “Lucida Grande”,sans-serif;
<br />1.5. Workflow: Setting Up Typography
<br />To work with EMs like with pxs, set font-size on the body-tag with 62.5%. Default-value of the font-size is 16px; applying the rule, you’ll get one Em standing for roughly ten pixels (16 x 62.5% = 10). “I tend to put a font-size on the body tag with value: 62.5%. This allows you to use EMs to specify sizes while thinking in PX terms, e.g. 1.3em is approximately 1.3px. ” [Jonathan Snook]
<br />Use universal character set for encoding. “[..] The answer is to use a single universal character set that’s able to cover most eventualities. Luckily one exists: UTF-8, which is based on Unicode. Unicode is an industry standard that’s designed to enable text and symbols from all languages to be consistently represented and manipulated by computers. UTF- 8 should be included in your web page’s head like this. [20 pro tips]
<br /><meta http-equiv="content-type" content="text/ html;charset=utf-8" />
<br />You can change capitalisation using CSS. If you need something written in capitals, such as a headline, rather than rewriting the copy, let CSS do the donkey work. The following code will transform all text with an h1 attribute into all capitals, regardless of format”. [20 pro tips]
<br />h1 {
<br /> text-transform: uppercase;
<br />}
<br />You can display text in small-caps automatically. The font-variant property is used to display text in a small-caps font, which means that all the lower case letters are converted to uppercase letters, but all the letters in the small-caps font have a smaller font-size compared to the rest of the text.
<br />h1 {
<br /> font-variant: small-caps;
<br />}
<br />Cover all the bases - define generic font-families. “When we declare a specific font to be used within our design, we are doing so in the hope that the user will have that font installed on their system. If they don’t have the font on their system, then they won’t see it, simple as that. What we need to do is reference fonts that the user will likely have on their machine, such as the ones in the font-family property below. It is important that we finish the list with a generic font type. [Getting into good coding habits]
<br />p {
<br /> font-family: Arial, Verdana, Helvetica, sans-serif;
<br />}
<br />Use 1.4em - 1.6em for line-height. “line-height:1.4” for readable lines, reasonable line-lengths that avoid lines much longer than 10 words, and colors that provide contrast without being too far apart. For example, pure black on pure white is often too strong for bright CRT displays, so I try to go with an off-white (#fafafa is a good one) and a dark gray (#333333, another good one).” [Christian Montoya]
<br />Set 100.01% for the html-element. This odd 100.01% value for the font size compensates for several browser bugs. First, setting a default body font size in percent (instead of em) eliminates an IE/Win problem with growing or shrinking fonts out of proportion if they are later set in ems in other elements. Additionally, some versions of Opera will draw a default font-size of 100% too small compared to other browsers. Safari, on the other hand, has a problem with a font-size of 101%. The current “best” suggestion is to use the 100.01% value for this property.” [CSS: Getting into good habits]
<br />1.6. Workflow: Debugging
<br />Add borders to identify containers. “Use plenty of test styles like extra borders or background colors when building your documents or debugging layout issues. div { border:1px red dashed; } works like a charm. There are also bookmarklets that apply borders and do other things for you.” You can also use * { border: 1px solid #ff0000; }. [Chric Casciano]. Adding a border to specific elements can help identify overlap and extra white space that might not otherwise be obvious. [CSS Crib Sheet]
<br />* { border: 1px solid #f00; }
<br />Check for closed elements first when debugging. “If you ever get frustrated because it seemed like you changed one minor thing, only to have your beautiful holy-grail layout break, it might be because of an unclosed element. [10 CSS Tips]
<br />2.1. Technical Tips: IDs, Classes
<br />1 ID per page, many classes per page. “Check your IDs: Only one element in a document can have a certain value for the id attribute, while any number of elements can share the same class name. [..] Class and id names can only consist of the characters [A-Za-z0-9] and hyphen (-), and they cannot start with a hyphen or a digit (see CSS2 syntax and basic data types).” [Roger Johansson]
<br />Element names in selectors are case sensitive. “Remember case sensitivity. When CSS is used with XHTML, element names in selectors are case sensitive. To avoid getting caught by this I recommend always using lowercase for element names in CSS selectors. Values of the class and id attributes are case sensitive in both HTML and XHTML, so avoid mixed case for class and id names.” [Roger Johansson]
<br />CSS classes and IDs must be valid. “I.e. beginning with a letter, not a number or an underscore. IDs must be unique. Their names should be generic, describe functionality rather than appearance.” [CSS Best Practices]
<br />You can assign multiple class names to a given element. “You can assign multiple class names to an element. This allows you to write several rules that define different properties, and only apply them as needed.” [Roger Johansson]
<br />2.2. Technical Tips: Use the power of selectors
<br />Roger Johansson has written an extremely useful series of articles about CSS 2.1 Selectors. These articles are highly recommended to read - some useful aspects can be found in the list below. Note that selectors ‘>’ and ‘+’ aren’t supported in IE6 and earlier versions of Internet Explorer (updated).
<br />
<br />You can use child selectors. “A child selector targets an immediate child of a certain element. A child selector consists of two or more selectors separated by a greater than sign, “>”. The parent goes to the left of the “>”, and whitespace is allowed around the combinator. This rule will affect all strong elements that are children of a div element. [Roger Johansson]
<br />div > strong { color:#f00; }
<br />You can use adjacent sibling selectors. An adjacent sibling selector is made up of two simple selectors separated by a plus sign, “+”. Whitespace is allowed around the adjacent sibling combinator. The selector matches an element which is the next sibling to the first element. The elements must have the same parent and the first element must immediately precede the second element. [Roger Johansson]
<br />p + p { color:#f00; }
<br />You can use attribute selectors. Attribute selectors match elements based on the presence or value of attributes. There are four ways for an attribute selector to match:
<br />[att]
<br />Matches elements that have an att attribute, regardless of its value.
<br />[att=val]
<br />Matches elements that have an att attribute with a value of exactly “val”.
<br />[att~=val]
<br />Matches elements whose att attribute value is a space-separated list that contains “val”. In this case “val” cannot contain spaces.
<br />[att|=val]
<br />Matches elements whose att attribute value is a hyphen-separated list that begins with “val”. The main use for this is to match language subcodes specified by the lang attribute (xml:lang in XHTML), e.g. “en”, “en-us”, “en-gb”, etc.
<br />The selector in the following rule matches all p elements that have a title attribute, regardless of which value it has:
<br />p[title] { color:#f00; }
<br />The selector matches all div elements that have a class attribute with the value error:
<br />div[class=error] { color:#f00; }
<br />Multiple attribute selectors can be used in the same selector. This makes it possible to match against several different attributes for the same element. The following rule would apply to all blockquote elements that have a class attribute whose value is exactly “quote”, and a cite attribute (regardless of its value):
<br />blockquote[class=quote][cite] { color:#f00; }
<br />You should use descendant selectors. “Descendant selectors can help you eliminate many class attributes from your markup and make your CSS selectors much more efficient. ” [Roger Johansson]
<br />2.3. Technical Tips: Styling Links
<br />Be careful when styling links if you’re using anchors. “If you use a classic anchor in your code (<a name="anchor">) you’ll notice it picks up :hover and :active pseudo-classes. To avoid this, you’ll need to either use id for anchors instead, or style with a slightly more arcane syntax: :link:hover, :link:active” [Dave Shea]
<br />Define relationships for links. “The rel attribute is supposed to indicate a semantic link relationship from one resource to another.
<br />a[rel~="nofollow"]::after {
<br /> content: "2620";
<br /> color: #933;
<br /> font-size: x-small;
<br />}
<br />a[rel~="tag"]::after {
<br /> content: url(http://www.technorati.com/favicon.ico);
<br />}
<br />“These make use of the attribute selector for space separated lists of values. Any a element with a relationship containing those values will be matched. Links with the nofollow relationship will be followed by a dark red skull and crossbones (?) and those with the tag relationship will be followed by the Technocrati icon.” [Handy CSS]
<br />You can mark external links automatically. Many people make use of the non-standard rel="external" relationship to indicate a link to an external site. However, adding that to each and every link is time consuming and and unnecessary. This style rule will place an north east arrow after any link on your site to an external site. [Handy CSS]
<br />a[href^="http://"]:not([href*="smashingmagazine.com"])::after {
<br /> content: "2197";
<br />}
<br />You can remove dotted links with outline: none;. To remove dotted links use outline: none;
<br />a:focus {
<br /> outline: none;
<br />}
<br />2.4. Technical Tips: CSS-Techniques
<br />You can specify body tag ID. “In most cases placing an ID in the body tag will allow you manipulate CSS presentational items and markup elements by page by page basis. Not only will you be able to organize your sections you will be able to create multiple CSS presentations without changing your markup from template to template or page to page.” [Ryan Parr, Invasion of Body Switchers]
<br />You can create columns with equal heights with CSS. Equal Height Technique: a method to make all columns appear to be the same height. But without the need for faux column style background images. Faux Columns: with background images.
<br />You can align vertically with CSS. “Say you have a navigation menu item whose height is assigned 2em. Solution: specify the line height to be the same as the height of the box itself in the CSS. In this instance, the box is 2em high, so we would insert line-height: 2em into the CSS rule and the text now floats in the middle of the box!” [Evolt.org]
<br />You can use pseudo-elements and classes to generate content dynamically. Pseudo-classes and pseudo-elements. Pseudo-classes and pseudo-elements can be used to format elements based on information that is not available in the document tree. For example, there is no element that refers to the first line of a paragraph or the first letter of an element’s text content. You can use :first-child, :hover, :active, :focus, :first-line, :first-letter, :before, :after and more.
<br />You can set <hr> to separate posts beautifully. “Restyling the horizontal rule (<hr>) with an image can be a beautiful addition to a web page. [CSS: Best Practices]
<br />You can use the same navigation (X)HTML-code on every page. “Most websites highlight the navigation item of the user’s location in the website. But it can be a pain as you’ll need to tweak the HTML code behind the navigation for each and every page. So can we have the best of both worlds?” [Ten More CSS Tricks you may not know]
<br />XHTML:
<br /><ul>
<br /><li><a href=”#” class=”home”>Home</a></li>
<br /><li><a href=”#” class=”about”>About us</a></li>
<br />
<br /><li><a href=”#” class=”contact”>Contact us</a></li>
<br /></ul>
<br />Insert an id into the <body> tag. The id should be representative of where users are in the site and should change when users move to a different site section.
<br />CSS:
<br />#home .home, #about .about, #contact .contact
<br />{
<br /> commands for highlighted navigation go here
<br />}
<br />You can use margin: 0 auto; to horizontally centre the layout. “To horizontally centre an element with CSS, you need to specify the element’s width and horizontal margins.” [Roger Johansson]
<br />XHTML:
<br /><div id=”wrap”>
<br /><!– Your layout goes here –>
<br /></div>
<br />CSS:
<br />#wrap {
<br />width:760px; /* Change this to the width of your layout */
<br />
<br />margin:0 auto;
<br />}
<br />You can add CSS-styling to RSS-feeds. “You can do a lot more with an XSL stylesheet (turn links into clickable links, etc), but CSS can make your feed look much less scary for the non-technical crowd. [Pete Freitag]
<br /><?xml version="1.0" ?>
<br /><?xml-stylesheet type="text/css" href="http://you.com/rss.css" ?>
<br />
<br />...
<br />You can hide CSS from older browsers. “A common way of hiding CSS files from old browsers is to use the @import trick. [Roger Johansson]
<br />@import "main.css";
<br />Always declare margin and padding in block-level elements. [10 CSS Tips]
<br />Set a width OR margin and padding. “My rule of thumb is, if I set a width, I don’t set margin or padding. Likewise, if I’m setting a margin or padding, I don’t set a width. Dealing with the box model can be such a pain, especially if you’re dealing with percentages. Therefore, I set the width on the containers and then set margin and padding on the elements within them. Everything usually turns out swimmingly.” [Jonathan Snook]
<br />Avoid applying padding/borders and a fixed width to an element. “IE5 gets the box model wrong, which really makes a mess of things. There are ways around this, but it’s best to side-step the issue by applying the padding to the parent element instead of the child that gets a fixed-width. [CSS Crib Sheet]
<br />Provide print styles. “You can add a print stylesheet in exactly the same way that you would add a regular stylesheet to your page:
<br /><link rel="stylesheet" type="text/css" href="print.css" media="print">
<br />or
<br /><style type=”text/css” media=”print”> @import url(print.css); </style>
<br />This ensures that the CSS will only apply to printed output and not affect how the page looks on screen. With your new printed stylesheet you can ensure you have solid black text on a white background and remove extraneous features to maximise readability. More about CSS-based print-Layouts. [20 pro tips]
<br />2.5. Technical Tips: IE Tweaks
<br />You can force IE to apply transparence to PNGs. “In theory, PNG files do support varied levels of transparency; however, an Internet Explorer 6 bug prevents this from working cross-browser.” [CSS Tips, Outer-Court.com]
<br />#regular_logo
<br />{
<br /> background: url('test.png'); width:150px; height:55px;
<br />}
<br />/* */
<br />* html #regular_logo
<br />{
<br /> background:none;
<br /> float:left;
<br /> width:150px;
<br /> filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='test.png', sizingMethod='scale');
<br />}
<br />/* */
<br />You can define min-width and max-width in IE. You can use Microsoft’s dynamic expressions to do that. [Ten More CSS Trick you may not know]
<br />#container
<br />{
<br /> min-width: 600px;
<br /> max-width: 1200px;
<br /> width:expression(document.body.clientWidth < 600? "600px" : document.body.clientWidth > 1200? "1200px" : "auto");
<br />}
<br />You can use Conditional Comments for IE. “The safest way of taking care of IE/Win is to use conditional comments. It feels more future-proof than CSS hacks – is to use Microsoft’s proprietary conditional comments. You can use this to give IE/Win a separate stylesheet that contains all the rules that are needed to make it behave properly. ” [Roger Johansson]
<br /><!--[if IE]>
<br /><link rel="stylesheet" type="text/css" href="ie.css" />
<br /><![endif]-->
<br />jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-68888323205316961722008-06-27T11:19:00.000-07:002008-06-27T11:29:10.060-07:00Top CSS Tips<p>I thought I'd share some of my habits when it comes to doing CSS work and let me warn you, some of what I have to say is probably a little controversial. But what's life without living it on the edge. (Yeah, I live an exciting life when CSS is considered 'the edge'.)</p> <h2>px for font sizes</h2> <p>Sacrilege, I know. There are perfectly good ways to get consistent font sizing and I really should use them but Internet Explorer is the only browser that I can think of that doesn't resize text. If the majority of your audience uses IE, then be nice to them and don't use pixels. Otherwise, I figure with IE7 supporting it, pixels are the new ems. </p> <p>When using pixel sizes, I also get to be sparing in my usage. I specify it on the body and any headers that need it. Inheritance is less of an issue (how many sites have you seen list items inexplicably smaller than the rest of the content like it was less important).</p> <h2>CSS declarations on one line</h2> <p>I've always put my entire declaration on one line. Here's an example to explain what I mean:</p><pre><code>h2 {font-size:18px; border:1px solid blue; color:#000; background-color:#FFF;}<br /><br />h2 {<br /> font-size:18px;<br /> border:1px solid blue;<br /> color:#000;<br /> background-color:#FFF;<br /> }</code></pre> <p>The second one may look prettier but it sure doesn't help me find anything. When looking for something in a style sheet, the most important thing is the ruleset (that's the part before the { and } ). I'm looking for an element, an id or a class. Having everything on one line makes scanning the document much quicker as you simply see more on a page. Once I've found the ruleset I was looking for, find the property I want is usually straightforward enough as there are rarely that many.</p> <h2>Blocking the Styles</h2> <p>I break down my style sheet into three separate blocks. The first is straight element declarations. Change the body, some links styles, some header styles, reset margins and padding on forms, and so on. This is usually a small block as I only like to redefine what I need to. No global margin and padding reset for me. I clear the body and form and maybe adjust paragraph if the design really needs it. Otherwise, let the browser handle it. I find the more you try to override what the browser does, the more styles you have to put in, which simply adds to the time to track down bugs and maintain the code.</p> <p>After element declarations, I have my class declarations; things like classes for an error message or a callout would go hear. I usually only have a couple of these. </p> <p>Finally, the meat. I start by declaring my main containers and then any styles for elements within those containers are indented. At a quick glance, I can see how my page is broken down and makes it easier to know where to look for things. I'll also declare containers even if they don't have any rules.</p><pre><code>#content {float:left;}<br /> #content p { ... }<br /><br />#sidebar {float:left;}<br /> #sidebar p { ... }<br /><br />#footer {clear:both;}<br /> #sidebar p { ... }</code></pre> <h2>Browser Support</h2> <p>Support only the latest browsers. That means dropping support for IE5 and IE5.5. Lots of time and effort to be saved here. No box model hacks needed for IE6. In fact, in supporting just the most recent versions of browsers, I end up using very few hacks. Along with using very few hacks means I can avoid shovelling different style sheets to separate browsers. I have one sheet, and that's it. Any hacks I do use are normally commented as such. Similar to the use of pixel measurements, you have to consider your audience before dropping browser support.</p> <p>The biggest thing for me is still triggering hasLayout in IE to do float containment and I've been using <code>zoom:1</code> for that. I like it because it's innocuous and shouldn't mess with anything else. </p> <h2>Containing Floats</h2> <p>I just touched on float containment so let's expand on that. My current approach to containing floats is using <code>overflow:hidden</code> (with possibly <code>zoom:1</code> for Internet Explorer). No clearing div or use of <code>:after</code>. Only worry about containing your floats if you have a background you are trying to set on your container. The overflow should be set on the container.</p> <p>Keep in mind that the content within the container should be designed to stay within the container. Anything too big and it'll get clipped. Shifting things using negative margins outside the container will also get clipped.</p> <h2>Understand Overflow</h2> <p>Overflow is usually where people get bit by IE. If you've got two floated elements and the content from the left container overflows then, in IE, the container grows and inevitably pushes the right container below it. This is usually a sign that you've messed up your margins, widths, or padding on one of these containers but Firefox (et al) won't reveal this. Using something like overflow:hidden or overflow:scroll on a container can help prevent IE from allowing the content to push the width of the container but you're better off trying to fix the issue in the design.</p> <h2>Allow Block Elements to Fill Their Space Naturally</h2> <p>My rule of thumb is, if I set a width, I don't set margin or padding. Likewise, if I'm setting a margin or padding, I don't set a width. Dealing with the box model can be such a pain, especially if you're dealing with percentages. Therefore, I set the width on the containers and then set margin and padding on the elements within them. Everything usually turns out swimmingly.</p> <h2>Use CSS Shorthand</h2> <p>This might seem like beating a dead horse but I still see people doing really verbose statements where they're setting margin-top, margin-right, margin-bottom and margin-left. My general rule of thumb is, you can use the long form only if you're setting one side. Once you have to set more than one side, it'll take less bytes to use shorthand. </p> <p>In shorthand, remember that the properties start at the top and work clockwise. <code>margin: <i>top right bottom left</i>;</code> It's also handy to know the shorter forms if you have equal values for top and bottom or left and right. </p><pre><code>margin: 5px 10px 20px; /* top left/right bottom */<br />margin: 10px 20px; /* top/bottom left/right */<br />margin: 0; /* all sides */</code></pre> <p>For border, if you only have to set more than one side differently then use two declarations. The first to set all sides, and then a second to change the values for one of the properties.</p><pre><code>/* 1px blue border on the left and bottom */<br />border:1px solid blue; border-width: 0 0 1px 1px; </code></pre> <h2>Avoid Unnecessary Selectors</h2> <p>Just specify the minimum number of selectors necessary for the style. If you find yourself doing <code>ul li {...}</code> or <code>table tr td {...}</code> then you're being more verbose than you need. LI's will inevitably be in UL's (okay, I suppose they could find themselves in OL's, in which case, be more specific for those styles) and a TD will inevitably be in a TR and a TABLE.</p> <p>Or putting the element name in front of an ID selector (Example: div#navigation). I used to do this because it'd help me "remember" which element the ID is on. As it turns out, I tend to use similar class names from project to project and they inevitably appear on the same elements. I also tend to just do a search to find where something is. So, these days, I just leave it at <code>#navigation</code>.</p> <p>Using less selectors will mean less selectors will be needed to override any particular style — that means it's easier to troubleshoot.</p> <h2>Keep it Simple</h2> <p>If it hasn't been evident throughout this post, only add when you need to, and that includes hacks. No need to get any more complicated than you need to. </p> <p>Now, I'd love to hear some of your tips.</p>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-76257317872093638062008-03-14T11:53:00.002-07:002008-03-14T11:55:27.604-07:00Lists: the 'list-style-type', 'list-style-image', 'list-style-position', and 'list-style' properties<p>The <a name="x36"><span class="index-def" title="list properties"><dfn>list properties</dfn></span></a> allow basic visual formatting of lists. As with more general markers, a element with 'display: list-item' generates a <a href="visuren.html#principal-box">principal box</a> for the element's content and an optional marker box. The other list properties allow authors to specify the marker type (image, glyph, or number) and its position with respect to the principal box (outside it or within it before content). They do not allow authors to specify distinct style (colors, fonts, alignment, etc.) for the list marker or adjust its position with respect to the principal box. </p><p>Furthermore, when a marker M (created with 'display: marker') is used with a list item created by the list properties, M replaces the standard list item marker. </p><p>With the list properties, the <a href="colors.html#background-properties">background properties</a> apply to the principal box only; an 'outside' marker box is transparent. Markers offer more control over marker box style. </p><div class="propdef"> <dl><dt><span class="index-def" title="'list-style-type'"><a class="propdef-title" name="propdef-list-style-type"><strong>'list-style-type'</strong></a></span> </dt><dd> <table class="propinfo" cellpadding="0" cellspacing="0"> <tbody> <tr valign="baseline"> <td><em>Value:</em> </td><td>disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha | upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana | katakana | hiragana-iroha | katakana-iroha | none | <a class="noxref" href="cascade.html#value-def-inherit"><span class="value-inst-inherit">inherit</span></a> </td></tr><tr valign="baseline"> <td><em>Initial:</em> </td><td>disc </td></tr><tr valign="baseline"> <td><em>Applies to:</em> </td><td>elements with 'display: list-item' </td></tr><tr valign="baseline"> <td><em>Inherited:</em> </td><td>yes </td></tr><tr valign="baseline"> <td><em>Percentages:</em> </td><td>N/A </td></tr><tr valign="baseline"> <td><em>Media:</em> </td><td><a class="noxref" href="media.html#visual-media-group">visual</a> </td></tr></tbody></table></dd></dl></div> <p>This property specifies appearance of the list item marker if <a class="noxref" href="generate.html#propdef-list-style-image"><span class="propinst-list-style-image">'list-style-image'</span></a> has the value 'none' or if the image pointed to by the URI cannot be displayed. The value 'none' specifies no marker, otherwise there are three types of marker: glyphs, numbering systems, and alphabetic systems. <strong>Note.</strong> Numbered lists improve document accessibility by making lists easier to navigate. </p><p>Glyphs are specified with <strong><span class="index-def" title="disc"><a class="value-def" name="value-def-disc">disc</a></span></strong>, <strong><span class="index-def" title="circle"><a class="value-def" name="value-def-circle">circle</a></span></strong>, and <strong><span class="index-def" title="square"><a class="value-def" name="value-def-square">square</a></span></strong>. Their exact rendering depends on the user agent. </p><p>Numbering systems are specified with:</p> <dl><dt><span class="index-def" title="decimal"><a class="value-def" name="value-def-decimal"><strong>decimal</strong></a></span> </dt><dd>Decimal numbers, beginning with 1. </dd><dt><strong><span class="index-def" title="decimal-leading-zero"><a class="value-def" name="value-def-decimal-leading-zero">decimal-leading-zero</a></span></strong> </dt><dd>Decimal numbers padded by initial zeros (e.g., 01, 02, 03, ..., 98, 99). </dd><dt><strong><span class="index-def" title="lower-roman"><a class="value-def" name="value-def-lower-roman">lower-roman</a></span></strong> </dt><dd>Lowercase roman numerals (i, ii, iii, iv, v, etc.). </dd><dt><strong><span class="index-def" title="upper-roman"><a class="value-def" name="value-def-upper-roman">upper-roman</a></span></strong> </dt><dd>Uppercase roman numerals (I, II, III, IV, V, etc.). </dd><dt><strong><span class="index-def" title="hebrew"><a class="value-def" name="value-def-hebrew">hebrew</a></span></strong> </dt><dd>Traditional Hebrew numbering. </dd><dt><strong><span class="index-def" title="georgian"><a class="value-def" name="value-def-georgian">georgian</a></span></strong> </dt><dd>Traditional Georgian numbering (an, ban, gan, ..., he, tan, in, in-an, ...). </dd><dt><strong><span class="index-def" title="armenian"><a class="value-def" name="value-def-armenian">armenian</a></span></strong> </dt><dd>Traditional Armenian numbering. </dd><dt><strong><span class="index-def" title="cjk-ideographic"><a class="value-def" name="value-def-cjk-ideographic">cjk-ideographic</a></span></strong> </dt><dd>Plain ideographic numbers </dd><dt><strong><span class="index-def" title="hiragana"><a class="value-def" name="value-def-hiragana">hiragana</a></span></strong> </dt><dd>a, i, u, e, o, ka, ki, ... </dd><dt><strong><span class="index-def" title="katakana"><a class="value-def" name="value-def-katakana">katakana</a></span></strong> </dt><dd>A, I, U, E, O, KA, KI, ... </dd><dt><strong><span class="index-def" title="hiragana-iroha"><a class="value-def" name="value-def-hiragana-iroha">hiragana-iroha</a></span></strong> </dt><dd>i, ro, ha, ni, ho, he, to, ... </dd><dt><strong><span class="index-def" title="katakana-iroha"><a class="value-def" name="value-def-katakana-iroha">katakana-iroha</a></span></strong> </dt><dd>I, RO, HA, NI, HO, HE, TO, ... </dd></dl> <p>A user agent that does not recognize a numbering system should use 'decimal'. </p><div class="note"> <p><em><strong>Note.</strong> This document does not specify the exact mechanism of each numbering system (e.g., how roman numerals are calculated). A future W3C Note may provide further clarifications. </em></p></div> <p>Alphabetic systems are specified with:</p> <dl><dt><strong><span class="index-def" title="lower-latin"><a class="value-def" name="value-def-lower-latin">lower-latin</a></span></strong> or <strong>lower-alpha</strong> </dt><dd>Lowercase ascii letters (a, b, c, ... z). </dd><dt><strong><span class="index-def" title="upper-latin"><a class="value-def" name="value-def-upper-latin">upper-latin</a></span></strong> or <strong>upper-alpha</strong> </dt><dd>Uppercase ascii letters (A, B, C, ... Z). </dd><dt><strong><span class="index-def" title="lower-greek"><a class="value-def" name="value-def-lower-greek">lower-greek</a></span></strong> </dt><dd>Lowercase classical Greek alpha, beta, gamma, ... (έ, ή, ί, ...) </dd></dl> <p>This specification does not define how alphabetic systems wrap at the end of the alphabet. For instance, after 26 list items, 'lower-latin' rendering is undefined. Therefore, for long lists, we recommend that authors specify true numbers. </p><div class="html-example"> <p>For example, the following HTML document: </p><pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<br /><html>
<br /> <head>
<br /> <title>Lowercase latin numbering</title>
<br /> <style type="text/css">
<br /> OL { list-style-type: lower-roman }
<br /> </style>
<br /> </head>
<br /> <body>
<br /> <ol>
<br /> <li> This is the first item.
<br /> <li> This is the second item.
<br /> <li> This is the third item.
<br /> </ol>
<br /> </body>
<br /></html>
<br /></pre> <p>might produce something like this: </p><pre> i This is the first item.
<br />ii This is the second item.
<br />iii This is the third item.
<br /></pre> <p>Note that the list marker alignment (here, right justified) depends on the user agent. </p></div> <div class="note"> <p><em><strong>Note.</strong> Future versions of CSS may provide more complete mechanisms for international numbering styles. </em></p></div> <div class="propdef"> <dl><dt><span class="index-def" title="'list-style-image'"><a class="propdef-title" name="propdef-list-style-image"><strong>'list-style-image'</strong></a></span> </dt><dd> <table class="propinfo" cellpadding="0" cellspacing="0"> <tbody> <tr valign="baseline"> <td><em>Value:</em> </td><td><a class="noxref" href="syndata.html#value-def-uri"><span class="value-inst-uri"><uri></span></a> | none | <a class="noxref" href="cascade.html#value-def-inherit"><span class="value-inst-inherit">inherit</span></a> </td></tr><tr valign="baseline"> <td><em>Initial:</em> </td><td>none </td></tr><tr valign="baseline"> <td><em>Applies to:</em> </td><td>elements with 'display: list-item' </td></tr><tr valign="baseline"> <td><em>Inherited:</em> </td><td>yes </td></tr><tr valign="baseline"> <td><em>Percentages:</em> </td><td>N/A </td></tr><tr valign="baseline"> <td><em>Media:</em> </td><td><a class="noxref" href="media.html#visual-media-group">visual</a> </td></tr></tbody></table></dd></dl></div> <p>This property sets the image that will be used as the list item marker. When the image is available, it will replace the marker set with the <a class="noxref" href="generate.html#propdef-list-style-type"><span class="propinst-list-style-type">'list-style-type'</span></a> marker. </p><div class="example"> <p style="display: none;">Example(s):</p> <p>The following example sets the marker at the beginning of each list item to be the image "ellipse.png". </p><pre>UL { list-style-image: url("http://png.com/ellipse.png") }
<br /></pre></div> <div class="propdef"> <dl><dt><span class="index-def" title="'list-style-position'"><a class="propdef-title" name="propdef-list-style-position"><strong>'list-style-position'</strong></a></span> </dt><dd> <table class="propinfo" cellpadding="0" cellspacing="0"> <tbody> <tr valign="baseline"> <td><em>Value:</em> </td><td>inside | outside | <a class="noxref" href="cascade.html#value-def-inherit"><span class="value-inst-inherit">inherit</span></a> </td></tr><tr valign="baseline"> <td><em>Initial:</em> </td><td>outside </td></tr><tr valign="baseline"> <td><em>Applies to:</em> </td><td>elements with 'display: list-item' </td></tr><tr valign="baseline"> <td><em>Inherited:</em> </td><td>yes </td></tr><tr valign="baseline"> <td><em>Percentages:</em> </td><td>N/A </td></tr><tr valign="baseline"> <td><em>Media:</em> </td><td><a class="noxref" href="media.html#visual-media-group">visual</a> </td></tr></tbody></table></dd></dl></div> <p>This property specifies the position of the marker box in the principal block box. Values have the following meanings:</p> <dl><dt><strong>outside</strong> </dt><dd>The marker box is outside the principal block box. <strong>Note.</strong> CSS1 did not specify the precise location of the marker box and for reasons of compatibility, CSS2 remains equally ambiguous. For more precise control of marker boxes, please use markers. </dd><dt><strong>inside</strong> </dt><dd>The marker box is the first inline box in the principal block box, after which the element's content flows. </dd></dl> <div class="html-example"> <p>For example: </p><pre><html>
<br /> <head>
<br /> <title>Comparison of inside/outside position</title>
<br /> <style type="text/css">
<br /> UL { list-style: outside }
<br /> UL.compact { list-style: inside }
<br /> </style>
<br /> </head>
<br /> <body>
<br /> <ul>
<br /> <li>first list item comes first
<br /> <li>second list item comes second
<br /> </ul>
<br />
<br /> <ul class="compact">
<br /> <li>first list item comes first
<br /> <li>second list item comes second
<br /> </ul>
<br /> </body>
<br /></html>
<br /></pre> <p>The above example may be formatted as:</p></div>jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-33863985475982781612008-03-14T11:53:00.001-07:002008-03-14T11:53:54.877-07:00Markers and listsMost block-level elements in CSS generate one principal block box. In this section, we discuss two CSS mechanisms that cause an element to generate two boxes: one principal block box (for the element's content) and one separate marker box (for decoration such as a bullet, image, or number). The marker box may be positioned inside or outside the principal box. Unlike :before and :after content, the marker box does not affect the position of the principal box, whatever the positioning scheme.
<br />
<br />The more general of the two mechanisms is new in CSS2 and is called markers. The more limited mechanism involves the list properties of CSS1. The list properties give authors quick results for many common ordered and unordered list scenarios. However, markers give authors precise control over marker content and position. Markers may be used with counters to create new list styles, to number margin notes, and much more.
<br />
<br />For instance, the following example illustrates how markers may be used to add periods after each numbered list item. This HTML program and style sheet:
<br />
<br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<br /><HTML>
<br /> <HEAD>
<br /> <TITLE>Creating a list with markers</TITLE>
<br /> <STYLE type="text/css">
<br /> LI:before {
<br /> display: marker;
<br /> content: counter(mycounter, lower-roman) ".";
<br /> counter-increment: mycounter;
<br /> }
<br /> </STYLE>
<br /> </HEAD>
<br /> <BODY>
<br /> <OL>
<br /> <LI> This is the first item.
<br /> <LI> This is the second item.
<br /> <LI> This is the third item.
<br /> </OL>
<br /> </BODY>
<br /></HTML>
<br />
<br />should produce something like this:
<br />
<br /> i. This is the first item.
<br /> ii. This is the second item.
<br /> iii. This is the third item.
<br />
<br />With descendant selectors and child selectors, it's possible to specify different marker types depending on the depth of embedded lists.
<br />
<br />jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-22448452194201344152008-03-14T11:52:00.000-07:002008-03-14T11:53:01.030-07:00Counters in elements with 'display: none'An element that is not displayed ('display' set to 'none') cannot increment or reset a counter. <br /><br />Example(s):<br /><br />For example, with the following style sheet, H2s with class "secret" do not increment 'count2'. <br /><br />H2.secret {counter-increment: count2; display: none}<br /><br />Elements with 'visibility' set to 'hidden', on the other hand, do increment counters.jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-31561146914905744472008-03-14T11:51:00.004-07:002008-03-14T11:52:31.298-07:00css Counter stylesBy default, counters are formatted with decimal numbers, but all the styles available for the 'list-style-type' property are also available for counters. The notation is:<br /><br />counter(name)<br /><br />for the default style, or:<br /><br />counter(name, 'list-style-type')<br /><br />All the styles are allowed, including 'disc', 'circle', 'square', and 'none'. <br /><br />Example(s):<br /><br /><br />H1:before { content: counter(chno, upper-latin) ". " }<br />H2:before { content: counter(section, upper-roman) " - " }<br />BLOCKQUOTE:after { content: " [" counter(bq, hebrew) "]" }<br />DIV.note:before { content: counter(notecntr, disc) " " }<br />P:before { content: counter(p, none) }jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-63660369995129126562008-03-14T11:51:00.003-07:002008-03-14T11:51:57.162-07:00Nested counters and scopeCounters are "self-nesting", in the sense that re-using a counter in a child element automatically creates a new instance of the counter. This is important for situations like lists in HTML, where elements can be nested inside themselves to arbitrary depth. It would be impossible to define uniquely named counters for each level. <br /><br />Example(s):<br /><br />Thus, the following suffices to number nested list items. The result is very similar to that of setting 'display:list-item' and 'list-style: inside' on the LI element: <br /><br />OL { counter-reset: item }<br />LI { display: block }<br />LI:before { content: counter(item) ". "; counter-increment: item }<br /><br />The self-nesting is based on the principle that every element that has a 'counter-reset' for a counter X, creates a fresh counter X, the scope of which is the element, its preceding siblings, and all the descendants of the element and its preceding siblings. <br /><br />In the example above, an OL will create a counter, and all children of the OL will refer to that counter. <br /><br />If we denote by item[n] the nth instance of the "item" counter, and by "(" and ")" the beginning and end of a scope, then the following HTML fragment will use the indicated counters. (We assume the style sheet as given in the example above). <br /><br /><OL> <!-- (set item[0] to 0 --><br /> <LI>item <!-- increment item[0] (= 1) --><br /> <LI>item <!-- increment item[0] (= 2) --><br /> <OL> <!-- (set item[1] to 0 --><br /> <LI>item <!-- increment item[1] (= 1) --><br /> <LI>item <!-- increment item[1] (= 2) --><br /> <LI>item <!-- increment item[1] (= 3) --><br /> <OL> <!-- (set item[2] to 0 --><br /> <LI>item <!-- increment item[2] (= 1) --><br /> </OL> <!-- ) --><br /> <OL> <!-- (set item[3] to 0 --><br /> <LI> <!-- increment item[3] (= 1) --><br /> </OL> <!-- ) --><br /> <LI>item <!-- increment item[1] (= 4) --><br /> </OL> <!-- ) --><br /> <LI>item <!-- increment item[0] (= 3) --><br /> <LI>item <!-- increment item[0] (= 4) --><br /></OL> <!-- ) --><br /><OL> <!-- (reset item[4] to 0 --><br /> <LI>item <!-- increment item[4] (= 1) --><br /> <LI>item <!-- increment item[4] (= 2) --><br /></OL> <!-- ) --><br /><br />The 'counters()' function generates a string composed of the values of all counters with the same name, separated by a given string. <br /><br />Example(s):<br /><br /><br />The following style sheet numbers nested list items as "1", "1.1", "1.1.1", etc. <br /><br />OL { counter-reset: item }<br />LI { display: block }<br />LI:before { content: counters(item, "."); counter-increment: item }jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0tag:blogger.com,1999:blog-7681105400300687252.post-44837858484462420672008-03-14T11:51:00.001-07:002008-03-14T11:51:29.418-07:00Automatic counters and numberingAutomatic numbering in CSS2 is controlled with two properties, 'counter-increment' and 'counter-reset'. The counters defined by these properties are used with the counter() and counters() functions of the the 'content' property. <br /><br />'counter-reset' <br />Value: [ <identifier> <integer>? ]+ | none | inherit <br />Initial: none <br />Applies to: all elements <br />Inherited: no <br />Percentages: N/A <br />Media: all <br /><br />'counter-increment' <br />Value: [ <identifier> <integer>? ]+ | none | inherit <br />Initial: none <br />Applies to: all elements <br />Inherited: no <br />Percentages: N/A <br />Media: all <br /><br />The 'counter-increment' property accepts one or more names of counters (identifiers), each one optionally followed by an integer. The integer indicates by how much the counter is incremented for every occurrence of the element. The default increment is 1. Zero and negative integers are allowed. <br /><br />The 'counter-reset' property also contains a list of one or more names of counters, each one optionally followed by an integer. The integer gives the value that the counter is set to on each occurrence of the element. The default is 0. <br /><br />If 'counter-increment' refers to a counter that is not in the scope (see below) of any 'counter-reset', the counter is assumed to have been reset to 0 by the root element. <br /><br />Example(s):<br /><br />This example shows a way to number chapters and sections with "Chapter 1", "1.1", "1.2", etc. <br /><br />H1:before {<br /> content: "Chapter " counter(chapter) ". ";<br /> counter-increment: chapter; /* Add 1 to chapter */<br /> counter-reset: section; /* Set section to 0 */<br />}<br />H2:before {<br /> content: counter(chapter) "." counter(section) " ";<br /> counter-increment: section;<br />}<br /><br />If an element increments/resets a counter and also uses it (in the 'content' property of its :before or :after pseudo-element), the counter is used after being incremented/reset. <br /><br />If an element both resets and increments a counter, the counter is reset first and then incremented. <br /><br />The 'counter-reset' property follows the cascading rules. Thus, due to cascading, the following style sheet:<br /><br />H1 { counter-reset: section -1 }<br />H1 { counter-reset: imagenum 99 }<br /><br />will only reset 'imagenum'. To reset both counters, they have to be specified together:<br /><br />H1 { counter-reset: section -1 imagenum 99 }jonhttp://www.blogger.com/profile/07893884823282842200noreply@blogger.com0