Breif Introduction

CSS

Standing for Cascading stylesheet, CSS is used to style the visual apperance of a html document. It's a cascading because it arranges elements appear as we want. CSS is mainatined by the W3C organization who publishes it's especifications(A document containing how it's suppose to behave).

Declaring you're using CSS

the first thing to do in css is to tell that there is some css code to implement to our page. there are 3 ways to do it.

  1. <link rel="stylesheet" href="styles.css"> This line of code is put in the head tag and is one of the ways to declare that we have a css. The quotation in href contains the name of the css document which contains our csss.
Selecters

To style html, we target certain, or multiple elememts. for example, to change the color of every p tag in the page:

p{ color: red; }

p in here is the selecter.

innate behavior of elements

Browsers, by defeult, add styling. That is why lists show up in bullets to begin with without we adding style. We can, however, modify that imnnate style rendered by the bnrowser. For example, you can remove the bullets of li by:
>

li{ list-style-type: none; }
classes

Sometimes, we not only want styling certain elements of our page, such as all p tags, but we also want to apply a style to a subset of an element, like some of the p tags and not the others. this is why classes exit. You add a class="name" to the inside of the opening tags of the elements you need to add to your class. Later in the css, you cna target that class using the name u gave it. For example
:

.myClass{ color: orange }

Is a code that targets only the elements containing the class myclass. If you added this class to say, some li and p tags, and u only want to target the ptags this time. Your selecter know becomes:
p.myClass
>

Selecting based on on Location in Document

There are several ways to achieve this. (a) the descendant combinator. The code

li em{ color: blue; }

Changes the color of emphasis tag. only within an li. The em is a decendent of li.(b)Adjacent Sibling Combinator(+). The code:

h1+p{ font-size: 200%; } Styles a paragraph when it comes directly after a heading at the same hierarchy level in html.
Styling based on state

An element has states. For instance, wether it's being hovered over, was visited focused via keyboard and so on. Below, we style visited links green, unvisited once blue and hovered oevr once yellow.

a:visited{ color: green; } a:link{ color: blue; } a:hover{ color: yellow; }

You can combine the concepts above and be very abstract.s

functions

There are some functions(methods who do things) in CSS. For example, the culc function which allows you to do simple math with CSS. For example:

.outer-box{ border = 5px solid black; } .inner-box{ padding = 10px; width: calc(90%-30px); background-color: rebeccapurple; color: white }

gives the inner box is 90% of the containing element width -30 pixels. Another example is the values of the transform property. For example, transform: rotate(0.8turn);, which rotates it clockwise 80%; of a turn.

@rules

The at-rules are especiel rules that instruct CSS hwo to behave. Take for example:

@import 'styles2.css';

which simpy tells css to also follow the rules the file styles2.css

Another example is the @media rule, which allows you to use media quries to apply CSS only when certian conditions are true. Case in point:

@media (min-wdith: 30em){ body{ background-color: blue; } }

The CSS encapsulated by the @media (min-width: 30em) selecter. with viewport more than 30. A vieport is the part of the page visible to teh browser. When em is used in properties like font-size: 2em, it makes the fot size of the respective element twice it's parent.

Further, when loading a css we can either load it or not based on an attribute called media with value = "screen and (max-device-width: 40px)"

shorthands

Some proeprties like font, background, padding, border are known as shorthands because the allow you set multiple proeprty values in a single line. For instance
:

padding: 5px 3px 10px 11px; /*This sets padding in the order top, right, bottom, left.
comments

When tou come back to your code days later, you might not undrstand at all what your code. That is why we have comments, to explain code, in programming languages. In CSS, it's syntax is: /*The comment goes here*/

White Space

You don't have to write each proeprty and it's value in it's own line. You can justw rite another proeprty-value pair next to closing semicolon, and anotehr one and then anotether one. Although, each team and individual have their own prefreneces, it looks betetr to read the first.

A deeper Drink

float

Although it's very detailed, what you need to know mostly is that it can be used for multi column layouts with a bit of finicking.

Positions

By default elements are static. Just note that it's better to set the property box-sizing to border-box, that way any element will have nothing but your specifieid width.

flexbox
  • If you set the display property of a container to flex, element contained go in one line. This can be fixed by adding flex-wrap: wrap, or to nowrap or to wrap-reverse.
  • flex-direction proerty cna be set to row, column, row-reverse, and column-reverse to specify which direction elements go.
  • justify-content property for the parent especifies how to distribute elemenets. it can be flex-start, flex-end, center, space-between space-around or space-evently. The vertical vertion of this is align-content.
  • grid

    This is a 2d grid system working with columns and rows. Here is how it works:

  • You can setup a grid of parent through the display:grid; and then next line, put, grid-template-columns: x%,x%...n;,where n is the number of columns. To put an element in certain row and column, do Grid-column-start: 3;
  • If you want an element to span multiple columns, add grid-column-end.
  • -1 is the first grid column from right and so on. Or you cna just do span 2 for either of the properties.
  • Background
  • To make a background transparent set the backgroudn-color to grbpa, where last argument ishow transparent its.
  • Adding a background image: background-image: url("url");
  • to make backrgound fit all page, set background-rebeat to no-repeat, and set background-size: to cover.
  • an example of gradient is: background: linear-gradient(to right, skyblue, white); you cna change direction, lookup. there is also radial gradient
  • UX-User Experience

    Focus on efficiency and efefctiveness in which users cna use yoursite, then worry about the style.

    Responsive Design

    Media Quiries explaiend in @ rules ablove And Fluid layout deisgn(to use % instead of fixed px).