Category Archives: ADP Payroll Tracking

ADP Payroll Tracking

Guil Hernandez writes on January 10, 2013 50 0 18 11 Besides the usual type, descendant, class and ID selectors, CSS offers several pseudo-class and pseudo-element selectors that allow us to target HTML elements based on their positions in the document –– some even target virtual elements and generate content from the CSS. In this article, we’ll take a look at 5 handy CSS selectors to keep in mind when styling your web pages and applications. :first-child and :last-child The :first-child and :last-child structural pseudo-classes let us select the first or last child of a parent element. For example, if we only need to select the first list item of an unordered list, we can use the :first-child pseudo-class: li:first-child { border-top: none; font-weight: bold; } Similar to :first-child, the :last-child pseudo-class selects an element that is the last child of its parent element. li:last-child { border-bottom: none; } :nth-child :nth-child is one of the most useful structural pseudo-classes available; it lets us select elements based on their positions within a parent element. :nth-child uses a function-like syntax that allows an argument to be passed in between parentheses –– inside the parentheses is where we declare how the elements will be selected. One of the arguments that can be accepted is the keyword odd or even, which can be used to select every other child element. The following rule will only target the even-numbered list items. li:nth-child(even) { color: white; background-color: black; } The keyword “even” is useful for selecting every other item in a list. Another argument we can use in between the parentheses is an integer. For example, this rule will only select the third list item inside the parent ul. li:nth-child(3) { background-color: tomato; } What makes arguments really powerful is when using expressions to select a particular combination of child elements. Our basic expression syntax looks something like this: :nth-child(an+b) The values a and b are always represented by a number, and the n value does not change. The b value is an offset value that determines which element is selected first. The a value determines the cycle of elements to select after the first one has been selected. The n value doesn’t change — think of n as a counter that starts at zero and indicates the a value to the browser. li:nth-child(2n+3) In the expression above, the third list item will be the first one selected in our list (the b value) ignoring all sibling list items that precede it, then every 2nd list item (determined by the a value) until there are no more list items to select. An expression like the one below will select the 5th list item first, then all list items before it (indicated by the -n value). li:nth-child(-n+5) Sometimes it may be beneficial—and practical—to use a class instead of an overly complex rule, as some can be difficult to maintain over time. For example, say you have a rule like the following: div:nth-last-of-type(2n+10) { background: yellow; color: red; } Think of the developer (or yourself) that has to manage this code a few weeks or months down the road. This is when we’re better off using a simple class such as:
Read more