|
My handy IE CSS tweaks list |
I'm not really a design kind of person, I like designing things, and I'm learning more and more CSS all the time, but it's the server side coding that I love like Apple Pie and custard.
Recently I've had to do a bit more design work, so I've been tripping all over myself to get CSS working in IE6,IE7,IE8 and firefox. I've learnt a few interesting things in the last few days, and I know I'm going to need to use them again. Some are considered 'hacks', some are just clever CSS techniques. They all feel a bit like secret rules of a club I'm not really a member of yet though.
So I'm making a handy list, so I don't loose them. I hope to refine and add to this on an ongoing basis, so if you know a better / easier way please let me know. After all coding standards are for life, not just Christmas, and I don't like the idea of anything being a hack, even if it is CSS.
Adding a 1px high line to IE
I am trying to add a 1px line, like a HR line to the page, it displays fat in IE?It seems that some versions of IE will display a div without content as the same height as your font size. Add html comments to it to drop it down to the right height:
2.yellow-ruler {color: #ffd520; background-color:#ffd520; width: 100%; height:2px; margin: 3px 0px 0px 0px;}
3</style>
4<div class="yellow-ruler"><!-- --></div>
IE is adding padding and margins to everything by default
I think there is a lot more information about this out there, but for now I've found that adding the code below will kill most of IE's random padding/margin issues.
I've built a JQuery accordion and the content doesn't move correctly
When expanding a JQuery accordion element the content underneath it is not moving down, and the accordion is expanding over it. This was a simple fix, but a bit of a pain to find. Just do not specify a height attribute on the div that hold the accordion, IE will stick to the height, but firefox will let it grow to be longer.
Styling form element borders
If you have a CSS rule like the one above that removes all the margins, padding and borders then all your form elements will have no border. IE your text fields and textareas etc will not have a clearly defined edge to them. By adding the line of CSS under this (select,input, etc) you can set the style width and colour of your form elements so that you control them, rather than the browser defaults. In Internet explorer this will also add borders to the checkbox and radio form elements. There does not seem to be any way of writing a CSS style to remove this inherently, so create a style of borderless and set all your radio and checkbox fields to "class=borderless".
2
3select,input,textarea{border-width: 1px; border-style: solid; border-color: grey;}
4
5/* IE stops the radio borders */
6.borderless{border: 0px;}
Strange IE positioning fix
Sometimes in IE (mainly 6) using position: absolute just does not render the div on screen. I am not sure why. Adding a "clear: both;" or a "clear: left;" or a "clear: right;" appears to fix this.
Easy centering of elements
I used to struggle with centering elements on a page all the time, but now you can do something like this:
2 margin-left: auto;
3 margin-right: auto;
4 width: 6em
5}
6
7<p class="blocktext">Text</p>
This will center a block of text and give it a width of 6.
For images you can do this:
2 display: block;
3 margin-left: auto;
4 margin-right: auto }
5
6<img class="displayed" src="..." alt="...">
That will auto center the image inside its containing div.
|
Using Isapi rewrite to serve up non existing templates |
I was discussing some ideas for an application framework this morning with the team, and one of the issues we hit upon was having a common directory for templates, but serving them up as if they were from a different directory.
The idea is to have one instance of a reusable skinnable template, that appears to live on several sites.
IE all the content lives in "webroot/content/templateName.cfm", but is actually served up by many sites, IE "127.0.0.1/site1/template1.cfm", "127.0.0.1/site2/template1.cfm" ... etc
In this way they can be re skinned or adapted as needed, and they aren't database driven. The main stumbling block for the discussion was the need to actually create blank versions of each of the named templates, in each of the sites, as ColdFusion server would error on the request.
I spent twenty minutes trying to work it so that my Application.cfc's onRequest or onRequestStart method would intercept the request before it was actually made, but that just wasn't working. My other idea was to use the onMissingTemplate method, but the server is only running ColdFusion 7, so that was a no go (I figured I could catch the missing template request and just re path it, although I'd have to assess if that was really inefficient due to almost every page request logging as failed).
My eventual solution was Isapi rewrite. I am re writing all the requests to the same template, and just passing in the template variable. In that way I can request pages that don't actually exist, but they appear in the url.
Create an index.cfm template like this:
2<ul>
3 <li><a href="page1">Page 1</a></li>
4 <li><a href="page2">Page 2</a></li>
5 <li><a href="page3">Page 3</a></li>
6 <li><a href="page4">Page 4</a></li>
7</ul>
8
9<cfdump var="#url#">
10<!--- write a handler to go get the url var passed in --->
For this example I am using the free version of Helicon's Isapi rewrite, you can get it here: Link to Helicons Isapi re write
In the example below I have altered the first page link to look like it is actually a .cfm template request, just in case you want the url string to have a .fileextension look to it.
2# Version 3.1.0.68
3
4RewriteEngine on
5RewriteBase /mywebroot
6
7#no physical page testing
8RewriteRule page1.cfm(/)? isapitest/index.cfm?p=page1
9RewriteRule page2(/)? /index.cfm?p=page2
10RewriteRule page3(/)? /index.cfm?p=page3
11RewriteRule page4(/)? /index.cfm?p=page4
So when you fire it up and test it you just see /page1, /page2 etc, and the pages don't actually exist.
I'm not experienced enough with Isapi rewrite to know if there is a downside to this, but bookmarking in a browser still works correctly, so I can't see an issues at present.
|
Firefox helpfully caching forms and their values |
Whilst building a form recently I hit a real noob stumbling block. I was trying to set a select value to selected if the value had previously been submitted, something like this:
2 <select name="title" size="1" class="form-select">
3 <option value="">Please select from</option>
4 <cfloop list="#variables.prefix#" index="variables.index" delimiters=",">
5 <option value="#variables.index#" <cfif attributes.title EQ #variables.index#> selected="yes" </cfif>>#variables.index#</option>
6 </cfloop>
7 </select>
Pretty straight forward, you'll all agree. The issue comes in where I had entered selected="selected". This isn't the correct code for a select option.
Handily Firefox will cache the form structure and form data, so that when you refresh the page it just loads up the cached version. This is great if you coded it correctly, otherwise it happily serves you up your coding errors again. So don't refresh your forms in testing.
Add ?test=1 or something to make the request a new URL.
|
Recommended Applications - Belarc PC Audit software - Acronis True Image Home 2010 |
Every now and then my PC gets a little clunky. Windows will gets a little slower once an installation of it is a bit long in the tooth. One really handy application that a friend recommended to me was Belarc's Personal PC Audit software.
It will create a log of all the applications and serial numbers on your system, which is great if you keep re-installing your operating system (I'm always forgetting which applications I'm running).
Along the same theme Acronis have just released the newest version of their backup software. True Image Home 2010 is Windows 7 compatible, and gives you a wealth of backup options, from full disk images to specific files. What most interests me though is the 'Continuous data protection' option. I've been used to team members working on Macs using 'Time machine' online continuous backup software, and this appears to have very similar functionality.