Monday, September 14, 2015

CSS Best practices list

Here is a quick list of Best practices for CSS

1. http://www.innofied.com/25-css-best-practices-we-follow-at-innofied/

2. Understanding Class selectors of CSS
http://anvilstudios.co.za/blog/2010/08/13/how-to-target-an-element-with-multiple-classes-in-css/

3. CSS Specificity
https://medium.com/@dte/understanding-css-selector-specificity-a02238a02a59

4. Mastering CSS

http://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/

5. More on Specificity
http://specificity.keegan.st/

6. Selectors with multiple classes
http://anvilstudios.co.za/blog/2010/08/13/how-to-target-an-element-with-multiple-classes-in-css/

7. More curious .. Read the documents of CSS3

The following table summarizes the Selector syntax:
Pattern Meaning Described in section First defined in CSS level
* any element Universal selector 2
E an element of type E Type selector 1
E[foo] an E element with a "foo" attribute Attribute selectors 2
E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar" Attribute selectors 2
E[foo~="bar"] an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" Attribute selectors 2
E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar" Attribute selectors 3
E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar" Attribute selectors 3
E[foo*="bar"] an E element whose "foo" attribute value contains the substring "bar" Attribute selectors 3
E[foo|="en"] an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en" Attribute selectors 2
E:root an E element, root of the document Structural pseudo-classes 3
E:nth-child(n) an E element, the n-th child of its parent Structural pseudo-classes 3
E:nth-last-child(n) an E element, the n-th child of its parent, counting from the last one Structural pseudo-classes 3
E:nth-of-type(n) an E element, the n-th sibling of its type Structural pseudo-classes 3
E:nth-last-of-type(n) an E element, the n-th sibling of its type, counting from the last one Structural pseudo-classes 3
E:first-child an E element, first child of its parent Structural pseudo-classes 2
E:last-child an E element, last child of its parent Structural pseudo-classes 3
E:first-of-type an E element, first sibling of its type Structural pseudo-classes 3
E:last-of-type an E element, last sibling of its type Structural pseudo-classes 3
E:only-child an E element, only child of its parent Structural pseudo-classes 3
E:only-of-type an E element, only sibling of its type Structural pseudo-classes 3
E:empty an E element that has no children (including text nodes) Structural pseudo-classes 3
E:link
E:visited
an E element being the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited) The link pseudo-classes 1
E:active
E:hover
E:focus
an E element during certain user actions The user action pseudo-classes 1 and 2
E:target an E element being the target of the referring URI The target pseudo-class 3
E:lang(fr) an element of type E in language "fr" (the document language specifies how language is determined) The :lang() pseudo-class 2
E:enabled
E:disabled
a user interface element E which is enabled or disabled The UI element states pseudo-classes 3
E:checked a user interface element E which is checked (for instance a radio-button or checkbox) The UI element states pseudo-classes 3
E::first-line the first formatted line of an E element The ::first-line pseudo-element 1
E::first-letter the first formatted letter of an E element The ::first-letter pseudo-element 1
E::before generated content before an E element The ::before pseudo-element 2
E::after generated content after an E element The ::after pseudo-element 2
E.warning an E element whose class is "warning" (the document language specifies how class is determined). Class selectors 1
E#myid an E element with ID equal to "myid". ID selectors 1
E:not(s) an E element that does not match simple selector s Negation pseudo-class 3
E F an F element descendant of an E element Descendant combinator 1
E > F an F element child of an E element Child combinator 2
E + F an F element immediately preceded by an E element Adjacent sibling combinator 2
E ~ F an F element preceded by an E element General sibling combinator 3

The meaning of each selector is derived from the table above by prepending "matches" to the contents of each cell in the "Meaning" column.  


Media Query


@media (max-width: 400px) {
  div { background: red; }
}
@media (min-width: 401px) and (max-width: 800px) {
  div { background: green; }
}
@media (min-width: 801px) and (max-width: 1100px){
  div { background: blue; }
}
@media (min-width: 1101px) {
  div { background: purple; }
}

@media screen and (resolution: 96px){
    div { background: yellow; }
}

Monday, August 4, 2014

What is Float property in CSS


Elements are floated horizontally, this means that an element can only be floated left or right, not up or down.
A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element.
The elements after the floating element will flow around it.
The elements before the floating element will not be affected.
If an image is floated to the right, a following text flows around it, to the left:


Sunday, August 3, 2014

specifying cursor URL in CSS element

div
{
cursor:url(smiley.gif),url(myBall.cur),auto;
}

Syntax of CSS

There are  basically  two parts 1clas

Selector     Declaration

Selector may be anything .. like element , element id , element class
Declaration is  property value pair separated by semi colon
eg.
h1  -  >  element
h1class --> Element class
h1id --> Element id

1.
h1    {
 color:blue;
font-size:12px;
}

2.
.h1class    {
 color:blue;
font-size:12px;
}

3. #h1id
{
 color:blue;
font-size:12px;
}

Friday, August 1, 2014

How to change Style of a HTML page at run time

It is simply disabling and enabling different style tag at run time.
Say there are two themes represented by styleSheets[0]  (GREEN) & styleSheets[1] (BLUE)

<script> 
function removeStyles() {
document.styleSheets[0].disabled = true; 
document.styleSheets[1].disabled = true; 

}

function applyGreenStyle() {
removeStylesStyles()
document.styleSheets[0].disabled = false; 
}

function applyBlueStyle() {
removeStylesStyles()
document.styleSheets[1].disabled = false; 
}
</script> 



How can you disable all style tags in HTML.

Suppose there are 4 Style tag which might be applied on your HTML page.
You can disable all those styles using following statement

JavaScript Function to Remove Styles 

function removeStyles() {
document.styleSheets[0].disabled = true;
document.styleSheets[1].disabled = true;
document.styleSheets[2].disabled = true;
document.styleSheets[3].disabled = true;
}

How can you access each Style Tag in JavaScript

Style tags array can be accessed using below statement .

document.styleSheets[0]
...
document.styleSheets[n-1]

For each Style tag in HTML page there is one entry in document object.

<head>
<!--document.styleSheets[0]-->
<style>

</style>

<!--document.styleSheets[1]-->
<style>

</style>


<!--document.styleSheets[2]-->
<style>

</style>




<!--document.styleSheets[3]-->
<style>


</style>





</head>