reading-notes

Software Development Reading Notes

View project on GitHub

Read: 05 - Design web pages with CSS

CSS is a language for specifying how documents are presented to users — how they are styled, laid out, etc. h1 { color: red; font-size: 5em; } The rule opens with a selector . This selects the HTML element that we are going to style. In this case we are styling level one headings (<h1>). We then have a set of curly braces { }. Inside those will be one or more declarations, which take the form of property and value pairs. Each pair specifies a property of the element(s) we are selecting, then a value that we’d like to give the property.

Adding CSS to your document.

To link styles.css to index.html, add the following line somewhere inside the <head> of the HTML document:

CSS reference https://www.w3schools.com/css/default.asp to reference index of syntax

33 ways to insert CSS

External- styles are defined within the element, inside the <head> section of an HTML page:

<!DOCTYPE html>

Internal- styles are defined within the </head> Inline- styles are defined within the "style" attribute of the relevant element: <!DOCTYPE html>

This is a heading

This is a paragraph.

## CSS HTML elements To target all paragraphs in the document, you would use the selector p. To turn all paragraphs green, you would use: p { color: green; } You can target multiple selectors at the same time by separating the selectors with a comma. If you want all paragraphs and all list items to be green, your rule would look like this: p, li { color: green; } ## Changing Default behavior Choose the HTML element that you want to change and using a CSS rule to change the way it looks. A good example is
    , an unordered list. It has list bullets. If you don't want those bullets, you can remove them like so: li { list-style-type: none; } ## Adding a Class Find a way to select a subset of the elements without changing the others. The most common way to do this is to add a class to your HTML element and target that class. In your HTML document, add a class attribute to the second list item. Your list will now look like this:
    • Item one
    • Item two
    • Item three
    ## Styling based on location within document There are a number of selectors that can help you here, but for now we will look at just a couple. In our document, there are two elements — one inside a paragraph and the other inside a list item. To select only an that is nested inside an
  • element, you can use a selector called the descendant combinator, which takes the form of a space between two other selectors. li em { color: rebeccapurple; } Something else you might like to try is styling a paragraph when it comes directly after a heading at the same hierarchy level in the HTML. To do so, place a + (an adjacent sibling combinator) between the selectors. h1 + p { font-size: 200%; } ## Styling based on State a:link { color: pink; } a:visited { color: green; } ## Combining Selectors and Contributors /* selects any that is inside a

    , which is inside an

    */ article p span { ... } /* selects any

    that comes directly after a

      , which comes directly after an

      */ h1 + ul + p { ... } Multi types also body h1 + p .special { color: yellow; background-color: black; padding: 5px; } ## CSS Reset https://meyerweb.com/eric/tools/css/reset/ CSS is a language for specifying how documents are presented to users — how they are styled, laid out, etc. h1 { color: red; font-size: 5em; } The rule opens with a selector . This selects the HTML element that we are going to style. In this case we are styling level one headings (

      ). We then have a set of curly braces { }. Inside those will be one or more declarations, which take the form of property and value pairs. Each pair specifies a property of the element(s) we are selecting, then a value that we'd like to give the property. ## Adding CSS to your document. To link styles.css to index.html, add the following line somewhere inside the of the HTML document: CSS reference https://www.w3schools.com/css/default.asp to reference index of syntax 33 ways to insert CSS External- styles are defined within the element, inside the section of an HTML page: <!DOCTYPE html> Internal- styles are defined within the </head> Inline- styles are defined within the "style" attribute of the relevant element: <!DOCTYPE html>

      This is a heading

      This is a paragraph.

      ## CSS HTML elements To target all paragraphs in the document, you would use the selector p. To turn all paragraphs green, you would use: p { color: green; } You can target multiple selectors at the same time by separating the selectors with a comma. If you want all paragraphs and all list items to be green, your rule would look like this: p, li { color: green; } ## Changing Default behavior Choose the HTML element that you want to change and using a CSS rule to change the way it looks. A good example is
        , an unordered list. It has list bullets. If you don't want those bullets, you can remove them like so: li { list-style-type: none; } ## Adding a Class Find a way to select a subset of the elements without changing the others. The most common way to do this is to add a class to your HTML element and target that class. In your HTML document, add a class attribute to the second list item. Your list will now look like this:
        • Item one
        • Item two
        • Item three
        ## Styling based on location within document There are a number of selectors that can help you here, but for now we will look at just a couple. In our document, there are two elements — one inside a paragraph and the other inside a list item. To select only an that is nested inside an
      • element, you can use a selector called the descendant combinator, which takes the form of a space between two other selectors. li em { color: rebeccapurple; } Something else you might like to try is styling a paragraph when it comes directly after a heading at the same hierarchy level in the HTML. To do so, place a + (an adjacent sibling combinator) between the selectors. h1 + p { font-size: 200%; } ## Styling based on State a:link { color: pink; } a:visited { color: green; } ## Combining Selectors and Contributors /* selects any that is inside a

        , which is inside an

        */ article p span { ... } /* selects any

        that comes directly after a

          , which comes directly after an

          */ h1 + ul + p { ... } Multi types also body h1 + p .special { color: yellow; background-color: black; padding: 5px; } ## CSS Reset https://meyerweb.com/eric/tools/css/reset/