CSS === CSS (Cascading Style Sheets) is the default method for styling HTML documents. CSS files are always linked into HTML documents using the :code:`` element in the :code:``: .. code-block:: html You can provide CSS properties in the HTML code directly, but fundamentally you should **never** do this, as it makes the code much harder to maintain. When writing stylesheets, the core principle to keep in mind is that complex designs can be achieved by combining selectors, having multiple rules that match the same element with different properties, and to use media queries to adapt to screen sizes. Basic Syntax ------------ At the most basic level, a CSS stylesheet is an ordered list of CSS rules. Each CSS rule defines a selector that specifies which elements are styled by the rule and then a set of properties that are used for the styling. A single CSS rule looks like this: .. code-block:: css selector { property-name: property-value; property-name: property-value; } Selectors --------- Tag selector The tag selector allows you to apply the same set of styles to all elements with the given tag: .. code-block:: css h1 { } Id selector The id selector allows you to apply a set of styles to the element with the given :code:`id` attribute value: .. code-block:: html Logout .. code-block:: css #logout { } Class selector The class selector allows you to apply a set of styles to any element with the given :code:`class` attribute value: .. code-block:: html
Right-aligned text
.. code-block:: css .text-right { } .. important:: The :code:`class` attribute is actually interpreted not as a single value, but as a list of values separated by spaces. Thus .. code-block:: html has three classes set on it "cell", "shrink", and "small-hidden". Pseudo selector The pseudo selector actually represents a category of selectors, that allow you to select an element based on a computed property of some kind. Examples are selectors that apply only when the user hovers the mouse over the element: .. code-block:: css a:hover { } or where the elements have a specific position: .. code-block:: css tr:nth-child(2n) { } Attribute selector The attribute selector allows you to apply a set of styles to any element that has a given attribute with a given value: .. code-block:: css ul[role=menu] { } Full documentation on the available selectors can be found here: https://developer.mozilla.org/en/docs/Web/CSS/CSS_Selectors. Combining Selectors +++++++++++++++++++ Often you will want to combine multiple selectors to create CSS rules that only apply to a very specific set of elements. To achieve this there are multiple combination operators Descendant By simply separating multiple separators using spaces, they are combined via the descendant rule: .. code-block:: css ul li { } In this example the rule will be applied to all :code:`
  • ` elements that are descendants of a :code:`