Reports from our 2016 Meetings
Reports from our 2016 Meetings
This March we had a look how all HTML tags are nested and how we can use that to address the tags within the cascading style sheet. We also looked at how and why the cascading style sheet cascades.
All tags in HTML are nested and therefore all tags have Parents, Children, Ancestors and Descendants. All tags have a start and an end tag, to and all tags are nested inside the HTML tags. The HTML tag has two children they are the Head and Body
All other tags are children of either the head or body, with a nest, any tag inside a tag would have a parent and or an ancestor. That is, it would be a descendent to the tag in which the parent was nested.
Using this code we can look at how that idea works.
paragraph
paragraph 1
paragraph 2
paragraph
paragraph 1
paragraph 2
Paragraphs 1 & 2 are siblings
We then look at this youtube video from day four of the course, 30 Days to Learn HTML & CSS
It gives a good idea of how the parent child relationship works.
So how do you target the children? There are four selectors called combinators
And a Child star selector which uses * eg
You can use this to highlight any element after the end tag eg the above code turns the all the paragraphs green
To see how they all worked we run through the “try it yourself” demonstrations in the W3C Schools.
Here is the html it asked us to edited.
This is a paragraph inside a div element.
This is another paragraph inside a div element.
This a paragraph inside a span element, inside a div element.
This is a paragraph, not inside a div element.
This is another paragraph, not inside a div element.
Inside the head is a style tag and we had to enter the correct code to test the selectors.
Here is the code we entered and the result
We also had a look at some of the other selectors described in the W3S Schools.
The Cascade
Browsers read style sheets to determine how a site should appear and there are at least three sheets. I think of it as the 3 + 3 rule
The first three are,
Here are the other three, that is the ones the web designer created
The browser looks at all these sheets and in ascending order applies the rules to either 1, 2 or 3
There are three rules the browser applies
There is a formula for how this is weighting, it is
Add a number for each item in the four areas and highest number wins
Inline Style: | ID: | Classes, Attributes, and Pseudo-classes | Element Types and Pseudo-elements |
Add a number | Add a number | Add a number | Add a number |
This table is from a Sitepoint article on specificity and weight.
http://www.sitepoint.com/web-foundations/specificity/
Heres an example.
Table
The inline style should win at 1000 over the ID at 100 or the class at 10
Here is a link to lesson 3 of the course "Understanding the CSS Cascade " which we looked at. The course is from Sitepoint Premium a paid site you can subscribe to but this one is a free example.
https://www.sitepoint.com/premium/courses/understanding-the-css-cascade-2874/lesson/3/step/1
To sum this up I quoted “Charlie’s Simple Cascade Summary” by Charles Wyke-Smith from page 54 of “Stylin with CSS” http://www.stylinwithcss.com/index.php
Steve South
Sig Leader