Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Friday, April 27, 2012

Date time stamp using jquery ui framework

If you are using jquery ui framework then you can show you date time in a cool way. The final result will look like this,




It will of course depend on what theme you are using. Here it goes.

HTML

Apr ´10
25th

1:05 pm


CSS

.date {
 width: 55px;
 text-align:center;
 font-family: cursive;
}

.date .ui-widget-header {
 padding: 2px 5px 2px 5px;
 font-size: .9em !important;
}

.day, .time {
 font-size: .8em !important;
}

.date hr {
 margin: 0px;
 border: 0;
 height: 1px;
 background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(31,52,60,0.75), rgba(0,0,0,0)); 
 background-image:    -moz-linear-gradient(left, rgba(0,0,0,0), rgba(31,52,60,0.75), rgba(0,0,0,0)); 
 background-image:     -ms-linear-gradient(left, rgba(0,0,0,0), rgba(31,52,60,0.75), rgba(0,0,0,0)); 
 background-image:      -o-linear-gradient(left, rgba(0,0,0,0), rgba(31,52,60,0.75), rgba(0,0,0,0));
}

sup, sub {
 vertical-align: baseline;
 position: relative;
 top: -0.4em;
}
sub { top: 0.4em; }

The style of hr element will of course vary for different theme.

Sunday, December 11, 2011

Project Portfolios engine for Refinery CMS

Just added a new kind of portfolio to get it running in RefineryCMS. Here is demo.
Project portfolio
Project details popup

Saturday, August 8, 2009

Tips on writing browser compatible css

Writing browser compatible css is a difficult job for people with less experience in css. Specially Internet Explorer make things interesting(or gives you headache, what ever you prefer ;) ). As an application grows it becomes more and more difficult to manage browser compatibility. And as Internet explorer continues to release new versions, it leaves a few time for developers to spare. Some times different browser is needed to tweak differently. It may be the size of the font, padding floating problems etc.

People then started to use Conditional Comments like bellow to give browser compatibility,

<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="ie_hacks.css" />
<![endif]—>

And there is the !important hack

Normally in CSS whichever rule is specified last takes precedence. However if you use !important after a command then this CSS command will take precedence regardless of what appears after it. This is true for all browsers except IE. Here you can find more.

h1 { font-size: 1.6em !important; font-size: 1.4em; }

Here IE still takes 1.4em as the font size.

Tantek box model hack

Tantek introduced a hack for ie and opera regarding the box model problem.

Hybrid Hacking defined css as,

#wrapper {
width: 770px;
wid\th: 750px;
}

It's a legal 'escape' backslash and should be ignored, but when it is inside the property name it is not ignored by IE5 and IE5.5 for Windows. Instead it causes those browsers to ignore the following "t" character in this case, thus making the property name unreadable to them. Which was explained here.

Then there was the The Child and Adjacent Sibling Hacks, as IE does not understands html>body. Which looks like,

#wrapper {
min-height: 500px; /* IEwin does not support min-height */
height: 500px;
}

html>body #wrapper {
height: auto;
}

This is discussed more elaborately here.

Here is a list of rule compatibility of browsers which is really useful.

An easy solution to write css which can easily support different browser

It is a combination of Javascript and CSS. Here is the Javascript that detects the browser and add a dummy class to body tag.

if ( $.browser.msie && $.browser.version == "6.0" ) {
$("body").addClass("ie6");
}
Although it is written in JQuery, there are plain Javascript available.

So now if your clients browser is IE6 then you already have a dummy class added to you body tag. Now you can write IE6 specific hack easily.

h1 { font-size: 1.6em; }
.ie6 h1 { font-size: 1.4em; }

It is more readable and you can provide different hack for different browser and versions with this hack.

References

http://www.positioniseverything.net/articles/ie7-dehacker.html

http://www.evolt.org/ten-css-tricks-you-may-not-know

Friday, July 17, 2009

Some Css and Javascripts optimization tips

There are so many aspect for optimizing the performance of a web application, that some times people tends to forget about Javascript and Css.

Yahoo developers experienced that, 80% of the end-user response time is spent on the front-end. Most of the time browser is busy downloading images, stylesheets, scripts, Flash, etc. Here you can find the details.

But there are improvement opportunities in these areas to improve the over all performance of the application.

Mostly we concentrate on some basic criteria

  1. Caching
  2. Minifying Javascript and Css
  3. Reducing number of files

Caching

Caching is great and browser gives you for free :). But should all our css and Javascripts should be cached??

Actually no!! Because some times browsers cache too much(specially Internet Explorer). You want the client to get the latest files if the file is changed.

So we need to identify the files that changes and files that do not change(library files,  like jquery, prototype etc). We expect library files to get cached and custom files that changes a lot, not to be cached. We can skip caching by passing a random query string like,

<script type="text/javascript" src="scripts/default.js?rand=1"></script>
That random number can be generated from the server side while serving the page (which is a built in facility for rails).
Now for common libraries(jQuery, protopye) we should use Google API for 2 reasons
  1. It grabs the library from the closest location it can get. So it loads faster.
  2. It frees your server from serving the library file, so that your server can serve more files instead.
This is how you can use Google API to load popular Javascript libraries.
<script type="text/javascript" src="http://www.google.com/jsapi"></script><br /><script type="text/javascript"><br />  google.load("jquery", "1.3.2");<br /></script>

Minifying Javascript and Css

According to Yahoo!'s Exceptional Performance Team, 40% to 60% of Yahoo!'s users have an empty cache experience and about 20% of all page views are done with an empty cache (see this article by Tenni Theurer on the YUIBlog for more information on browser cache usage).

So surely you want to minify all your javascripts and css on your production server. There are some nice online Javascript and css packer which actually does the trick.

Javascript

http://jscompress.com/

http://dean.edwards.name/packer/

Css

http://www.cssoptimiser.com/

http://flumpcakes.co.uk/css/optimiser/

I know what you are thinking. You can’t go to web and pack all your css and Javascripts all the time you deploy, specially if you are following Agile and deploying your code after every 2 weeks.

There are platform specific implementations to resolve this problem. For rails we can use this to minify and pack javascripts and reduce number of Javascripts.

You can use yahoo compressor written in Java, so you can run that in any platform.

http://developer.yahoo.com/yui/compressor/#work

There is another implementation by Douglas Crockford,

http://crockford.com/javascript/jsmin

We can add necessary commands to our deployment script, so that after or before deployment the compressor is run.

Reducing number of files

Web servers can not serve a lot of files consecutively. There are limitation for browsers as well. If you watch your site with firebug net inspection, you will see that a lot of file calls which are not called parallely. So reduction in number of files served can improve the performance of the web application.

How can we reduce number of files?

There are several ways we can reduce number of files.

1. We can merged css and javascript the way we minified it.

2. Most of the cases we don’t care about the images. As a result the number of images grow rapidly.

There are some nice ways to merge images into one using css background-position property. People call this css sprite.

And every one use it to reduce file size as well as number of files.

If you merge some images into one, then size is actually reduced. Because other then the picture information every image maintains a color template. If some images are merged then a super set of color template is generated which reduces the total size of the image then the sum of the size of individuals.

Here are some nice examples

http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/

http://www.alistapart.com/articles/sprites

http://css-tricks.com/css-sprites/

Here is a site that generates css sprite.



Sunday, February 1, 2009

Png Corner is the solution of rounded/styled corners which is browser compatible

I was searching for an easy and simple implementation of smooth rounded corner that is browser compatible. If you want smooth corners you will need png images and Internet Explorer 6 has issues with png alpha transparency. Then I came with a project pngcorner . This is very easy to use and very small in size(less than 4 kb ). You can download the demo from here.

For png transparency I used unitpngfix , a very small(less than 1 kb ) and yet very effective javascript library. And used a table structure rounded corner template. For detail please visit the project page.

Here is a demo and here is the demo with jquery plugin.

Why use png corners

  1. It is browser compatible(works in IE 6/7, FireFox 3, Opera 9, Chrome 1.x)
  2. It's small(less than 4 kb )
  3. Easy to use(Just follow 3 easy steps)
  4. Can use png transparency feature so that you can create your own styled box.
  5. Same behavior across browsers
  6. Size of your content is totally flexible
  7. You can change images from css
Why special
There are a lot of implementation on rounded corner. And there are simpler implementation.
But if you need smooth(using png images), transparent(that works even in IE6), browser compatible, small(less than 4kb), with flexible content dimension(content can have any dimension) you should use pngcorners.
Places to use
  1. Use to create smooth rounded corner content with shades
  2. Use to create buttons with shades(as the size is expandable you can have small buttons as well as long ones)

Limitations

  1. It uses table for the structure of rounded corner. So your rounded corner is not as flexible as div layout (It is a small sacrifice for IE 6 png transparency)
  2. The images at left, right, top and bottom will be scaled not repeated. As Microsoft.Alpha filter do not support repeating.

Usage

1. Add png _corner. css in page

2. Add html structure for rounded corner, which looks like this,

<table class="rounded_corner" border="0" cellpadding="0" cellspacing="0">
  <tr><td class="top_left"/><td class="top"/><td class="top_right"/> </tr>
  <tr><td class="left"/>
    <td class="content">The content goes here :)</td>
    <td class="right"/>
  </tr>
  <tr><td class="bottom_left"/><td class="bottom"/><td class="bottom_right"/></tr>
</table>

3. Add png hack css in header as shown bellow so that the script is only added for Internet Explorer 6.

4. Add clear. gif in root_file/images

And you should be good to go :)

jQuery Version

There is a jQuery version of png corners. For that you will have to follow all the steps and add another javascript file pngcorners.js. But now the step 2 is now being simplified.

No need to remember all those tags and make your view complex. Just call,

$(".round_me").pngcorner();

Where you are expecting for elements with round_me class name will become rounded corner :)

So it reduces tags and cleans the view a bit.

Caution

When you load you content from ajax call or create your content dynamically after your page is loaded then you have to call the following javascript after you have done loading your content.

pngfix();

I am still searching for a solution with lesser limitation and complexity. So any suggestion is welcome.