Skip to main content

Things you may not know about CSS

Grammatical error like style using CSS:


.grammar{ 
   -moz-text-decoration-color: green;
   -moz-text-decoration-line: underline;
   -moz-text-decoration-style: wavy;
   text-decoration-color: green;
   text-decoration-line: underline;
   text-decoration-style: wavy;
}
Output:


CSS 'empty-cells' Property

table{
   empty-cells:hide;
}

  



CSS @supports 

Usually we do CSS feature-test using JavaScript. Now it can be done in CSS with a new property '@supports'. So for Firefox 22+ , Chrome 28+, Opera 12.1+ supports this feature. So we can look forward to using it soon!

Example:
/* basic usage */
@supports(prop:value) {
    /* more styles */
}

/* real usage */
@supports (display: flex) {
    div { 
      display: flex;
    }
}

/* testing prefixes too */
@supports (display: -webkit-flex) or
          (display: -moz-flex) or
          (display: flex) {

    section {
      display: -webkit-flex;
      display: -moz-flex;
      display: flex;
      float: none;
    }
}


CSS Filter Effects:

For an Image, we usually apply filters using Canvas. But CSS supports this filter operation via 'filter' property. Note that this property is significantly different from and incompatible with Microsoft's older "filter" property. So for only webkit browsers support this feature (Chrome 18+, Safari 7+, Opera 15+)

Supported filter properties:
  1. blur
  2. grayscale 
  3. drop-shadow 
  4. sepia 
  5. brightness 
  6. contrast 
  7. hue-rotate 
  8. invert 
  9. saturate 
  10. opacity
Click here for demo

Example:
.blurFilter{
-webkit-filter: blur(2px);
} 
 .imageFilter{
     -webkit-filter: blur(5px) brightness(3.9) contrast(3.5) drop-shadow(72px 72px 20px black) grayscale(0.5) hue-rotate(120deg) invert(0.2) opacity(0.1) saturate(1.9) sepia(0.2);
}


CSS 'pointer-events':

This property is magical. Yes you can really disable a element using the power of CSS. You don't need JavaScript anymore to do the stuff.  
'pointer-events' CSS property actually disables the mouse events on an element.

Example:
/*CSS:*/
.disabled{
     pointer-events:none;
}
<!--HTML:-->
<a href="http://www.google.com" class="disabled">Google</a>

<p onclick="alert(1)" class="disabled">Pop an alert</p>
The above example wont fire any mouse events on the element.


CSS Counters: 

CSS3 introduces the numbering of HTML elements using CSS Counters. For example, if we need to mention the chapter count with respect to h2 tag - usually we do some JavaScript stuffs to achieve it. But CSS counters done an awesome job to achieve the same.

Initializing the CSS Counter:

Syntax:
counter-reset: none|identity [number]
Example:
section{
   counter-reset: chapter;
}
 In the above example, 'chapter' is a user defined identity that is used for the increment and display purpose. By default the identity is reset to '0'. 'none'  will disable the counter

Incrementing the CSS Counter:

Syntax:
counter-increment: none|identity [number]
Example:
section > h1{
   counter-increment: chapter;
}

counter-increment increments the counter identity by '1' by default. The increment value can be specified next to the identity. Be aware that you must use '>' in your selector if you have nested lists so that your list numbering doesn't get incremented at the wrong points.

'none'  will disable the counter.

Note: IE8 supports the counter-increment property only if a !DOCTYPE is specified. Also, an element that is not displayed (display:none) cannot increment or reset a counter.


Using the Counter Value:

We use counter values with pseudo elements for display purpose. The in built 'counter' function will return the current elements increment value with respect to the chapter. The return value can be formatted by passing the following property values as parameter to the counter function.

decimal
Decimal numbers, beginning with 1.

decimal-leading-zero
Decimal numbers padded by initial zeros (e.g., 01, 02, 03, ..., 98, 99).
lower-roman
Lowercase roman numerals (i, ii, iii, iv, v, etc.).
upper-roman
Uppercase roman numerals (I, II, III, IV, V, etc.).
georgian
Traditional Georgian numbering (an, ban, gan, ..., he, tan, in, in-an, ...).
armenian
Traditional uppercase Armenian numbering.
lower-latin or lower-alpha
Lowercase ascii letters (a, b, c, ... z).
upper-latin or upper-alpha
Uppercase ascii letters (A, B, C, ... Z).
lower-greek
Lowercase classical Greek alpha, beta, gamma, ... (α, β, γ, ...)


Example:
section{
     counter-reset: chapter;
}
section > h1{
    counter-increment: chapter;
}
section h1:before{
    content:"(Chapter " counter(chapter, upper-roman) ")"
}

ul{
    counter-reset: list;
}
ul > li {
    counter-increment:list;
}
ul li:before{
    content: "(Item " counters(list, ".") ")";
}
Output:

 


:empty Pseudo Selector:

The :empty pseudo selector will select empty elements or elements with only comments. This will be helpful in hiding empty elements.
Example:
/*CSS*/
div:empty { 
   display: none; 
}
<!--HTML-->
<div></div>
<div><!-- test --></div>


'will-change' CSS Property - For Performance

If you tried getting some complex animations and transforms via css3, you might noticed some flickers in the animation in most of the webkit based browsers. Here you might need to understand the term 'Hardware acceleration'. Hardware Acceleration means that the Graphics Processing Unit (GPU) will assist your browser in rendering a page by doing some of the heavy lifting, instead of throwing it all onto the Central Processing Unit (CPU) to do.

Click here to Read More....

translateZ() (or translate3d()) Hack:
transform: translate3d(0, 0, 0);
Generally the browser's 3d rendering is hardware accelerated. So, this hack informs the browser to hardware accelerate the element.
Hardware-accelerating an operation results in the creation of what is known as a compositor layer that is uploaded to and composited by the GPU. However, force-hacking layer creation may not always be the solution to certain performance bottlenecks on a page. Layer creation techniques can boost page speed, but they come with a cost: they take up memory in system RAM and on the GPU (particularly limited on mobile devices) and having lots of them can have a bad impact (especially on mobile devices), so they must be used wisely and you need to make sure that hardware-accelerating your operation will really help the performance of your page, and that a performance bottleneck is not being caused by another operation on your page. 

In order to avoid such layer creation hacks, CSS introduces a new property 'will-change', which enables the browser to hardware accelerate the element while performing certain operation that we mention in the property.

Example:
will-change: transform, opacity;
Note: Don’t Use will-change to Declare Changes to Too Many Properties or Element, this may lead to browser crash. Example,
*,
*::before,
*::after {
 will-change: all;
}


New CSS3 Cursors 

Mouse over the list to view cursors,

  1. none
  2. context-menu
  3. cell
  4. vertical-text
  5. alias
  6. copy
  7. no-drop
  8. not-allowed
  9. col-resize
  10. row-resize
  11. all-scroll
  12. zoom-in
  13. zoom-out

Browser support:

FIREFOX - All supported. Issue: no-drop same as not-allowed

IE - Doesn't support none, context-menu, cell, alias, copy, zoom-in/out.

OPERA - Only supports col-resize, row-resize, all-scroll and zoom-in/out on Windows

SAFARI - All supported

CHROME - All supported

Comments

  1. Good work! Most was new to me, and I just finished a book on CSS.

    You maybe want to change 'intimates' to 'imitates.'

    ReplyDelete
  2. Thanks Martin :) ...... I changed it to 'inform' - it suits for the sentence....

    ReplyDelete

Post a Comment

Popular posts from this blog

RGB in C

Default palette size for normal graphics driver is 16 i.e) the color number rages from 0 to 15 To use rgb color modes we have to choose VGA or IBM 8514 as a graphics driver For VGA, Palette size is 16 i.e) color number ranges from 0-16 For IBM 8514, Palette size is 256 i.e) color number ranges from 0-255, we can also say it as VGA with 256 palette size By using setrgbpalette function we can generate RGB colors, we can generate colors with respect to Palette size. This function replaces the default palette colors with the generated Palette colors. Syntax: void setrgbpalette(int colornum, int red, int green, int blue); /* colornum - color number in palette (0-15 or 0-255 depens on graphics driver) red - color value for red (0-255) green - color value for green (0-255) blue - color value for blue (0-255) */ Example: #include<graphics.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<time.h> void main(){ int gd=VGA,

Simple Animation Using C

Here i have used fillpoly function to draw the object body and used fillellipse function to draw tier. animation is done by looping through the objects x & y position until user hits a key. Keypress event is achived  by using kbhit function. Smoothness of animation is controlled by delay function. Change the delay values to change the animation speed Source: #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { int gd=DETECT,gm,i=-300,j; int poly[16]={100,100,250,100,250,50,300,50,325,90,325,140,100,140,100,100}; int tpoly[16]={100,100,250,100,250,50,300,50,325,90,325,140,100,140,100,100}; initgraph(&gd,&gm,""); getch(); while(!kbhit()) { for(j=0;j<16;j+=2) { poly[j]=tpoly[j]+i; } fillpoly(8,poly); setfillstyle(5,7); bar(275+i,60,295+i,85); setfillstyle(5,8); fillellipse(140+i,140,20,20); fillellipse(280+i,140,20,20); setfillstyle(1,0); fillellipse(140+i,140,10,10); fillellipse(280+i,140,10

Random Bouncing Ball Animation

Simple animation of random balls that bounces within the screen Source: #include<stdio.h> #include<graphics.h> #include<conio.h> #include<dos.h> #include<math.h> void drawBall(struct ball *b, int color); struct ball{ int x, y; int dx, dy; int radius; }; void main() { int gd=0, gm=VGAHI; int i; struct ball b[10]; initgraph(&gd, &gm, ""); for(i=1;i<=15;i++){ b[i].radius = rand()%20; b[i].x=rand()%getmaxx(); b[i].y=rand()%getmaxy(); b[i].dx=2; b[i].dy=4; } while(!kbhit()) { delay(5); cleardevice(); for(i=1;i<=15;i++) drawBall(&b[i],i); } closegraph(); } void drawBall(struct ball *b, int color){ setfillstyle(1,color); setcolor(color); fillellipse(b->x, b->y, b->radius, b->radius); if(b->x+b->radius > getmaxx() || b->x-b->radius<0) b->dx = -b->dx; if(b->y+b->radius > getmaxy() || b->y-b->radius<0) b->dy = -b->dy; b->x+=b-&g