Академический Документы
Профессиональный Документы
Культура Документы
target elements or instances that lie outside that lie outside of the DOM or are too specific for simple
selectors to target
:hover (pseudo-class selector)
a:hover (targeted pseudo-class selector)
ul a:hover (descendant selector with a pseudo-class selector)
Dynamic Pseudo-class Selectors
Target elements based on something other than attributes, content, or element type. Usually refers
to something that can change over time, or that is based on user interaction.
UI Element State Pseudo-class Selectors
Target specific user interface elements in regards to whether or not they are currently enabled.
Structural Pseudo-class Selectors
Target elements based on specialized information within the DOM that simple selectors cannot
target. This can be pattern-matching child-to-parent relationships, or other structural information.
Other Pseudo-class Selectors
Other pseudo-class selectors exist that can't really be grouped into any one category. These
selectors give you even more specific targeting capabilities based on things like language or URL
targeting.
Dynamic Pseudo-Class Selectors
links, link states and target pseudo-class selectors
<a> should be in the order l v h a
a:link, a:visited, a:hover, a:active
a:(id) - matching id value to specific web page
Structural Pseudo-Class Selectors
span:first-child - find every span in the document and if it is the first child of its parent element, go
ahead and give it this styling
h2:first-of-type: find all h2s and see when they are inside of a parent element. When they are the first
h2 within the parent element, style them.
p:only-child: find a paragraph and that paragraph is the only child inside the parent, go ahead and
give it that styling
p:only-of-type: when the paragraph is the only paragraph inside of a parent element style it.
Nth-child selectors
Target elements based on patterns that describe which elements within a parent that you should
target.
Simple nth-child
li:nth-child(2): second element
li:nth-child(2n): every second element
li:nth-child(odd): every odd element
li:nth-child(even): every even element
li:nth-child(2n+1): every second element beginning with 1 (oset)
li:nth-child(-2n+8): start at 8 and select every second one going back
li:nth-child(5n-1): start at -1 and select every fifth element
Complex nth-child
li:nth-child(1n+6): start at 6 and select every one after that
li:nth-child(1n+6):nth-last-child(1n+6):
start at 6 element and select every one after that
start at 6 element from the end of the list and every element going up: these two are meeting
li:nth-child(-1n+5), li:nth-last-child(-1n+5)
start at 5 element and select every one going back
start at 5 element from the end of the list and every element going back
Pseudo-element selectors
p::first-line:
p::first-letter:
a::after { content: " (outside link)";}
a::after { content: "[" attar(href) "]"; }
RESOLVING CONFLICTS
What happens when styles conflict?
If the properties conflict, the properties of one rule will replace the other.
If the properties conflict, the properties of one rule will replace the other.
If they don't conflict with one another, the properties are added and the rules are cumulative, leaving
you with a mixture of the two rules.
Understanding the cascade
The last rule applied wins.
NOTE: inline have other things to take into account: specificity, inheritance. But inline styles almost
always win in the event of a conflict.
Using inheritance
If you apply the property to a parent element, all the elements inside of it will have that property
applied to it as well.
If a child element has a style that diers or conflicts with the parent styles, the child styles always
wins.
As sites become more complex, inheritance becomes more dicult to track.
Keep styles organized will help you avoid conflicts caused by inheritance.
Placing your most basic, default styles on top-level elements is an ecient way to style elements sitewide.
Remember that styles are cumulative; you must account for formatting inherited through parent
elements.
Selector specificity
how specific is it?
Element: specificity value of 1
ID: specificity value of 100
Classes: specificity value of 10
NOTE: Inheritance takes precedence over selector specificity
The !Important declaration
WMD of CSS
Important declaration wins
Only another more specific important declaration can win over an important declaration
Reducing conflicts through planning
General Guidelines
Avoid using local styles when possible.
They add a sometimes unwarranted extra layer of complexity to a site.
Updating or modifying styles can become a chore.
Local styles are easy to miss, especially in a team environment
Do not use inline styles except to very specific circumstances.
They are almost impossible to detect and maintain.
Develop a Strategy for Specificity
Don't mix class and ID selectors without having a plan that guides when they are to be used.
Sections of ID selectors can be hard to overwrite later if not accounted for.
If you find yourself writing descendent selectors with three or more selectors, consider revising the
strategy.
Use Inheritance to your Advantage
If you are familiar with your page structure, you should be able to identify global formatting across
your site.
Those formatting needs can then be written as global styles on parent elements, and inherited by the
rest of the site.
This results in fewer rules to write and easier styles to maintain.
Think About How Styles Relate to One Another
New designers often make the mistake of styling each element individually, as it's encountered.
This can lead to bloated style sheets and hard to maintain styles.
Thinking of styles as related formatting allows you to plan and write organized style sheets.
BASIC TEXT FORMATTING
Setting a font family (using a font-stack)
font-family: first_value, second_value, third_value;
Using @font-face (using web fonts)
/* @font-face rule declarations */
Normal, bold, italic, bold italic