css « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ css ’

Getting started with jQuery Mobile

Posted by on September 15th, 2012

JQuery mobile provides set of features which are supported on almost all smartphones such as touch UI, ajax navigation, animated page transitions. Building jQuery mobile page is very simple, here’s how:

  1. A jQuery Mobile site must start with an HTML5 ‘doctype’ to take full advantage of all of the framework’s features.
  2. First of all you need jQuery, jQuery mobile, mobile theme stylesheets from CDN.
  3. Reference all styles & scripts in the head of page.
  4. <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Page Title</title>
    <link rel="stylesheet" href="css/jquery.mobile-1.1.1.css"/>
    <script src="js/jquery-1.8.0.min.js"></script>
    <script src="js/jquery.mobile-1.1.1.min.js"></script>
    </head>
  5. A meta viewport tag in the head sets the screen width to the pixel width of the device.
  6. Inside body of html page a div with data-role of page is used as a wrapper for whole page.
  7. For header bar add a div with data-role of header.
  8. For content region add a div with a data-role of content & add content between this div.
  9. <body>
    <div data-role="page">
            <div data-role="header">
                    Header
            </div>
            <div data-role="content">
                    <p>This is jquery mobile test page</p>
            </div>
            <div data-role="footer">
                   ©intelligrape
            </div>
    </div>
    </body>
    
  10. There are many features provided by jQuery mobile. Here i am explaining one of them which is list. For list, simply add ul tag with attribute data-role of listview between

    .
  11. To make it look like an inset module add an attribute data-inset=”true”.
  12. For dynamic search filter just add another attribute data-filter=”true”.
  13. <div data-role="content">
        <ul data-role="listview" data-inset="true" data-filter="true">
              <li>Blue</li>
              <li>Black</li>
              <li>Green</li>
              <li>Yellow</li>
              <li>White</li>
        </ul>
    </div>
    

Making a text vertical aligned in a DIV

Posted by on September 12th, 2012

Recently in my project I had to implement one page in which an image and the related text had to be shown side by side using the DIV tags, where the text needed to be centered vertically with respect to the image.

Example : Let’s take a scenario where we cannot use vertical-align with DIV to display the text in center adjacent to the image.

Here we are having an unordered-list having 2 DIV components containing an image and text respectively.


<ul><li>

<div class="image"></div>

<div class="details">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>

</li></ul>

To make the DIV adjacent to each other we have applied the following CSS. But still it does not solve our use case to centrally align the text in DIV as specified above.


ul{ list-style:none; margin:0px;}

ul li{  margin-bottom:20px;}

ul li .image{ border:1px solid #666; height:100px; width:100px; float:left; margin-right:10px;}

ul li .details{  color:#000;  font-size:14px; min-height:100px; }

ul li .details p{ margin:0px;}

Here is the output of the above CSS. The text will start from top of the DIV and will be displayed as follows:

Image without vertical alignment of text

If we want the text to be centrally aligned in the text DIV, you need to do the following steps:

  1. Add following CSS property display:table to the LI element.
  2. Then you need to add CSS properties display:table-cell;  vertical-align:middle;  to the class named ‘details’ which is applied on DIV containing text.


ul li{  margin-bottom:20px; display:table;}

ul li .details{ display:table-cell; vertical-align:middle; color:#000;  font-size:14px; min-height:100px; }

After applying this CSS to your HTML, your output will look like this :

Image with vertical-align DIV

Hope it helps. :)

Regards.
Rajan Shergill
rajan@intelligrape.com
https://twitter.com/RajanShergill3

Posted in HTML-UI-CSS

960 Grid System

Posted by on September 11th, 2012

The 960 Grid system contains 960 pixel width. This is a CSS Framework. There are 3 types of grids in 960 Grid stystem, that is

  1. 12-Column Grid
  2. 16-Column Grid
  3. 24-Column Grid

It is in fact based on a very simple and a basic principle of designing – ALIGNMENT. The 960 Grid system comes with framework sheets for designing the webpages. Conversion of psd to html is very easy in 960 Grid System

The image above shows an example of 12 columns. In the width of 960px, each column has a width of 60px and left and right margins of 10px.

Posted in HTML-UI-CSS

Sprite Up !!! Automate your process of creating sprites.

Posted by on June 23rd, 2011

Hi all,

In the past few days, I was given a push to find a suitable method that allowed us to automate the much needed but  painstaking of creating sprites for webpages to improve their performance.The problem was that going through the process of spriting images was a tedious process for a person not used to Photoshop tools and meticulous image adjustments in the corresponding Css.
After spending some time with Mr Google, I stumbled upon an application that allowed us to automate the process, leaving the task of spriting images and adjusting the corresponding css upto the application.

Lets take a look at it. I’m sure that even if you give it 1 shot, you are bound to appreciate the ease of spriting your images to give it another go.

First things first, get SMARTSPRITES : - http://csssprites.org/.

Once you’ve got that done, all you’ve got to do is put in place holders to indicate that a particular image is to be included in the spriting process.
To do that indicate where you would like the sprite to be placed with something like this at the top of your css …

 /** sprite: myspriteVertical; sprite-image: url('../images/myspriteVertical.png'); sprite-layout: vertical */ 
sprite: myspriteVertical  - This is the reference for the final image to be used in the css
sprite-image: url(‘../images/myspriteVertical.png’)  -This specifies the path of the final image.
sprite-layout: vertical  - It specifies the layout of images in your sprite. It can be vertical, horizontal or repeating.

Next go to the place in the css where you have an image. For example, my Css had something like

.home .searchWiget_widget_Header{font-size:18px;color:#fff;padding:14px 10px 2px 10px; background:url("../images/header-top.png") no-repeat 0 0;}
Now for this to application to recognize candidate images the background image property needs a separate line of it’s own. Although the refactor doesn’t take time, it becomes easier if you start off with separate lines the next time you create a css.
So I split it into something like
.home .searchWiget_widget_Header{font-size:18px;color:#fff;padding:14px 10px 2px 10px;
background-image:url("../images/header-top.png");
background-repeat: no-repeat;
background-position:0 0; }

Note that this image specifies a positioning of top,left. We need to provide that for our image position in the final sprite.

Now simply add placeholders as shown below.
.home .searchWiget_widget_Header{font-size:18px;color:#fff;padding:14px 10px 2px 10px;
background-image:url("../images/header-top.png");/** sprite-ref: myspriteVertical; sprite-alignment: left */
background-repeat: no-repeat;}
sprite-ref: myspriteVerticalThis is the reference to the final sprite where it will be included as one of the images.
sprite-alignment: leftThis specifies that the image is to be aligned on the left in the final sprite. This corresponds to the background-position attribute. Other than left, it can be top, bottom or right.

Now that we have provided an alignment in the placeholder, we need to delete the  ’background-position’ attribute in the original implementation, so that it doesn’t override the new changes.
Now here we need to take care that images that are positioned to align on the left or right have to be arranged on a vertical layout.
Images aligned top or bottom are to be horizontally aligned.
This arrangement needs to be taken care of otherwise you might have images popping out in the webpage at unwanted places.
Now repeat the procedure or putting placeholders for all the images you want to be sprited. Make sure to keep left/right positioned images in a vertical layout and top/bottom images in a horizontal layout

Once that’s done, we simply need to issue a command to generate to sprite and adjust the css properties to accommodate the new image. It will contain the css you have modified as an argument.
  ./smartsprites.sh ~/Desktop/Demo/web-app/css/demo.css 

It will create a new file with the same name appended with a default extension value. The original files in the CSS will remain unchanged. To switch your design to CSS sprites, link these CSS files instead of the original ones in your HTML.
A plethora of options has been provided on the home page along with helpful documentation. Go through them if you encounter any problems.

Thats it .!!!! Check out your sprites

Notes :
1) Make sure to check the output of the sprite command. You should watch out for Warn and Error messages. It might show why your output isn’t coming out as it should.
2) Try to keep separate sprites for  horizontally aligned , vertically aligned and repeating images. Combining them will more often than not result in error-prone images.
3) Repeating images can be tricky. I had to redo a sprite since my image wasn’t repeating properly. Give it more than 1 shot and you’ll definitely get it right.

Hope this helps!!

Manoj Mohan
manoj(at)intelligrape(dot)com
Posted in HTML-UI-CSS

clearfix css hack

Posted by on November 13th, 2010

The clearfix hack, or “easy-clearing” hack, is a useful method of clearing float(left, right) effort. The clearfix hack works great, but the browsers that it targets are either obsolete or well on their way. Specifically, Internet Explorer 5 for Mac is now history, so there is no reason to bother with it when using the clearfix method of clearing floats.

When the container not wrapping floated divs within it.clearfix hack (which includes the guillotine bug for IE etc). It fixes the problem.


Definition and Usage
This code define in css

/* new clearfix */ .clearfix:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } * html .clearfix { zoom: 1; } /* IE6 */ *:first-child+html .clearfix { zoom: 1; } /* IE7 */

Tips and Notes
Add class in html code

Class=”clearfix”

I happens most often (or is most noticeable) when you’ve got a design that wants to go flush to the bottom of the browser. However, for some damn reason, it just won’t go flush — it is that pesky five or so pixels that just won’t budge. Playing with the padding and margins don’t help — what could it be? Check the containing element and see if you’ve applied the clearfix css hack to it … because if you did, our money is that is your problem.

There are many variations of clearfix floating around the web.The clearfix method applies clearing rules to standards-compliant browsers using the :after pseudo-class. For IE6 and IE7, This clearfix method triggers has Layout with some proprietary CSS. Thus Clearfix method effectively clears floats in all currently used browsers without using any hacks.

Support browser

IE Firefox Safari Chrome Opera iPhone Android
6.0+ 3.5+ 3.0+ 3.0+ 10.5+ 1.0+ 2.0+
Posted in HTML-UI-CSS

canvas

Posted by on September 7th, 2010

The HTML <canvas> tag is used for creating graphics on the fly. It can be used for rendering graphs, game graphics, or other visual images.

 

To draw on the canvas, the <canvas> tag is used in conjunction with the getContext(contextId) method.

 

Any content between the <canvas></canvas> tags is “fallback content”- meaning, it will be displayed only if the canvas cannot be displayed.

 

As a script:

function displayCanvas()
	{
      var canvas = document.getElementById("myCanvas");
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        ctx.fillStyle = "rgb(200,0,0)";
        ctx.fillRect (0, 0, 150, 75);

        ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
        ctx.fillRect (40, 30, 125, 75);

        ctx.fillStyle = "rgb(0,0,150)";
        ctx.strokeRect (20, 20, 50, 100);
      }
    }

 

and this is html

<canvas id="myCanvas" width="300" height="200">Your browser does not support the canvas tag. At the time of writing, Firefox, Opera, and Chrome support this tag.

Here's an image of what it's supposed to look like image.
</canvas>

Attributes
width: {Specifies the canvas width in pixels. The default value is 300.Possible values:[Non-negative integer] (for example, 300)}
Height: {Specifies the canvas height in pixels. The default value is 150.Possible values:[Non-negative integer] (for example, 150)}

Posted in HTML-UI-CSS

Accessing remote fonts on Client’s system by @font-face

Posted by on June 7th, 2010

@font-face allows authors to specify online fonts to display text on their web pages. By allowing authors to provide their own fonts.

We Use it

I.We choose  font and  we have right now. First of all  font format generate four another format as like(ttf, eot,otf,svg,woff)

and upload server where we access.

II. Create in css This Syntex

@font-face {
font-family: 'PalatinoRegular';
 src: url('palatino-webfont.eot');
 src: local('Palatino'), local('Palatino'),
url('palatino-webfont.woff') format('woff'),
url('palatino-webfont.ttf') format('truetype'),
 url('palatino-webfont.svg#webfontoXFrZcNP') format('svg');
font-weight: normal;
font-style: normal;
}

III. We acces in html page as class or Id and define body tag font-family

Values

<a-remote-font-name>

Specifies a font name that will be used as font face value for font properties.

<source>

URL for the remote font file location, or the name of a font on the user’s computer in the form local("Font Name").

<weight>

A Font-weight value.

You can specify a font on the user’s local computer by name using the local() syntax. If that font isn’t found, other sources will be tried until one is found.
Note:
When not avaible font local machine . This time  @font- face download fonts in browser temporary download font and display text

Supported font formats

  • Internet Explorer (all versions): EOT
  • Safari (3.2+): TTF / OTF
  • iPhone (3.1) SVG
  • Chrome (all versions): SVG (TTF/OTF added 25th Jan 2010)
  • Firefox (3.5+): TTF/OTF (.WOFF added 3.6)
  • Opera (10+) TTF/OTF

Browser compatibility

Browser Lowest version Support of
Internet Explorer 4.0 Embedded OpenType fonts only
Firefox (Gecko) 3.5 (1.9.1) TrueType and OpenType fonts only
3.6 (1.9.2) Web Open Font Format (WOFF)
Opera 10.0 TrueType and OpenType fonts only
Safari (WebKit) 3.1 (525) TrueType and OpenType fonts only

## Umar Pahat##
umar@intelligrape.com
www.IntelliGrape.com

Posted in HTML-UI-CSS

IE 6/7 Z-index issue

Posted by on June 3rd, 2010

Recently I got struck in an IE issue … Z-index did not seem to work on IE 6 or 7 ..
After some surfing found a pretty easy solution .
i.e use

position:relative

with z-index ..and voila it works

_____________________
Hitesh Bhatia
hitesh@intelligrape.com
_____________________

Posted in HTML-UI-CSS