Monday, April 21, 2014

Best shorthand to CSS border property

When I started coding CSS I coded the border property as:
.box{ 
  border-width: 1px;
  border-style: solid;
  border-color: blue;
}
And after a few months later I improved in coding the same property as shorthand:
.box{
  border: 1px solid blue;
}
If the border colors needed to be different, or if the requirement is like - I need left, right, and top borders but not the bottom border. To this, I used the property as:
.box{ 
  border-top: 1px solid blue;
  border-left: 1px solid blue;
  border-right: 1px solid blue;
  border-bottom: 0 none;
}
The above method can be improved with the new/unknown CSS border shorthand:
.box{
  border-color: blue;
  border-style: solid;
  border-width: 1px 1px 0 1px; /*top right bottom left*/
}
Check the demo: http://jsfiddle.net/X3QHc/

Here's how it works: 
.box{
  border-color: red green blue black; /*top right bottom left*/
  border-style: solid dotted dashed double;
  border-width: 6px 4px 2px 10px;
}
Check the demo: http://jsfiddle.net/X3QHc/1/

Related Articles: 
Styling input type file
- IE 7/8 stretching background image to 100% width and height
Change parent elements background image position on child mouseover


Thursday, April 10, 2014

jQuery modal dialog popup window without plugin

I just googled for jQuery Modal dialog window and to my surprise, I saw some links that redirected me to some jQuery plugins which is not necessary for such a small task. I didn't see a pain and easy to understand solution to it. So I decided to put it up in this post.
 
Here's a simple jQuery Modal Dialog Popup Window that even works in IE7: Demo



Related Articles:
- IE 7/8 stretching background image to 100% width and height
- HTML - DIV vertically center align image/elements
- jQuery increase/decrease number in input field

Tuesday, April 8, 2014

AngularJS show hide html elements

AngularJS is becoming more popular in web application development day by day. And it is not as simple as jQuery. Its main focus is not DOM manipulation, but it's more in Data manipulation, and is more logical. It teaches all jQuery developers a more sophisticated way of coding where the developers understand the next level of OOP.

I miss jQuery a lot. Especially, the handy methods like show() hide(). If we want to get the same effect with AngularJS, we have to put some logic in controllers and implement it with ng-click, ng-class, ng-show, ng-hide. In this post I will write some simple and easy to understand examples for this most needed ng-hide and ng-show methods .

Show Hide DIV on Click: Demo



Toggle DIV : Demo 



Toggle DIV with Animations: Demo



Related Articles:
AngularJS Add Class and Toggle Class
AngularJS Toggle Class with Animation


Saturday, April 5, 2014

Separate CSS for different browsers

It's a general expectation that the web application you are working on must be supported in all major browsers. Since the implementation of CSS properties in different browsers varies, they force front-end developers to write specific properties separately for them. There are some CSS properties that don't give similar result in all browsers. The most popular one is vertical-align; it behaves differently in chrome/firefox and in IE. The situation becomes even tougher when the client asks support for different versions of the same browser.

Here are some tricks that help developers serve separate CSS files/classes for different browsers and browser versions depending on the requirements.

Separate CSS for Mozilla Firefox - CSS only solution:
@-moz-document url-prefix(){
    div{ color: red; }
}

Separate CSS for IE version - with conditional comments:
The traditional code:

The HTML5 BoilerPlate code:

These conditional classes get appeneded in the <html> tag depending on the version you are using. For example, if you are using IE9, the '.ie9' class will get appeneded in the <html> tag which gives you an option to write CSS only for IE9 with '.ie9' class as a parent class -
.ie8 .className{ color: green; } /* This css will be applied to IE8 only*/
.ie9 .className{ color: red; } /* This css will be applied to IE9 only*/

Separate CSS for IE version - with jQuery:


Read more on jQuery.browser

Separate CSS for Windows OS Versions using javascript:
If you are supporting all versions of windows OS, these tricks can help you write separate CSS files for Windows OS versions.

For Windows 8: 

For Windows 7:

For Windows XP:

Read more on understanding user-agent string

Related Articles:
Vertically center align image, DIV, and other html elements in IE 7 and IE 8
Styling input type file
Essential CSS Pseudo Classes


Wednesday, April 2, 2014

AngularJS Add Class and Toggle Class

There are several ways of adding a class to an element in angularJS which varies in different situations. I want to put the solutions without much of explanation in angularJS terminology, because sometimes it scares to the HTML developers, so I won't get into that. I will just post some plane code which will be useful to most of the developers and designers.

Add/Remove Class:
The directive you need to read to understand this example:
ng-app  ng-click and ng-class




Toggle Class Example 1:
The directive you need to read to understand this example:
ng-controller ng-app  ng-click and ng-class




Toggle Class Example 2:
The directive you need to read to understand this example:
ng-init ng-app  ng-click and ng-class



Related Articles:
- AngularJS Toggle Class with Animation