An open API service indexing awesome lists of open source software.

https://github.com/foyez/css


https://github.com/foyez/css

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# CSS (Cascading Style Sheets)

- Used to describe the presentation of a document written in **HTML**

CSS Example đź§®

```css
selectorA {
property1: value1;
}

body {
color: white;
}
```

## Including CSS

View contents

External Style Sheet

```html

```

Embedded Styles

```html

body {
background-color: gray;
}

```

Inline Styles

```html

Lorem ipsum


```

## CSS Box Model

View contents

> The CSS box model refers to how HTML elements are modeled in browser engines and how the dimensions of those HTML elements are derived from CSS properties.

the box model

```css
/********************** CONTENT *************************
The box that contains the actual element content like text,
image, icon, gif, video,... */

tag_name {
height: 90px;
width: 200px;
}

/\***\*\*\*\*\***\*\*\***\*\*\*\*\*** PADDING \***\*\*\*\*\*\*\***\*\***\*\*\*\*\*\*\***
Distance between the content and the border. The background color,
of the element will never affect this space. But you can see this by
contrasting with the background color of the parent element that
contains your element\*/

tag_name {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}

/_OR: _/

tag*name {
padding: 25px 50px 75px 100px; /* top; right; bottom; left \_/
}

tag*name {
padding: 25px 50px 75px; /\* top; right*&\_left; bottom \*/
}

tag*name {
padding: 25px 50px; /\* top*&_bottom; right_&\_left \*/
}

tag*name {
padding: 25px; /\* top*&_bottom_&_right_&\_left \*/
}

/\***\*\*\*\*\***\*\*\***\*\*\*\*\*** BORDER \***\*\*\*\*\*\*\***\*\***\*\*\*\*\*\*\***
You can define a frame for your element's box. You can
only see the border, after you define a style for that
property \*/

tag*name {
border-width: 5px 70px 10px 28px; /* or border-bottom-width: 10px; ... _/
border-color: blue; /_ or border-top-color: #b52e2e; ... _/
border-style: dotted; /_ or dashed, or solid, or ... _/
border-radius: 70% /_ making the corners more rounded \_/
}

/_OR: _/

tag*name {
border: 5px solid red; /* all*widths; style; color */
}

tag*name {
border-left: 6px dotted green; /* width; style; color _/
border-top: 34px groove yellow; /_ width; style; color \_/
}

/\***\*\*\*\*\***\*\*\***\*\*\*\*\*** OUTLINE \***\*\*\*\*\*\*\***\*\***\*\*\*\*\*\*\***
It's a line that's drawn around your html element, but
contrary to the border, the dimensions of the outline
aren't taken into account. It's drawn around elements,
outside the borders, to make the element "stand out" \*/

tag*name {
outline-width: thin; /* or medium; thick; outline-width: 4px; ... _/
outline-color: blue; /_ or #b52e2e; invert; ... _/
outline-style: dotted; /_ or dashed, or solid, or ... _/
outline-offset: /_ making the corners more rounded \_/
}

/_OR: _/

tag_name {
outline: dashed;
}

tag_name {
outline: dotted red;
}

tag*name {
outline: 5px solid yellow; /* all*widths; style; color */
}

tag_name {
outline: thick ridge pink;
}

/\***\*\*\*\*\***\*\*\***\*\*\*\*\*** MARGIN \***\*\*\*\*\*\*\***\*\***\*\*\*\*\*\*\***
This is the distance that separates an html element,
from the other elements around it. The background color,
of the element will never afect this space, because the
margin doesn't have background color. The margin is an
invisible border or space between two objects \*/

tag_name {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}

/_OR: _/

tag*name {
margin: 25px 50px 75px 100px; /* top; right; bottom; left \_/
}

tag*name {
margin: 25px 50px 75px; /\* top; right*&\_left; bottom \*/
}

tag*name {
margin: 25px 50px; /\* top*&_bottom; right_&\_left \*/
}

tag*name {
margin: 25px; /\* top*&_bottom_&_right_&\_left \*/
}

````

## CSS Specificity

View contents

> Specificity is a weight that is applied to a given CSS declaration, determined by the number of each selector type in the matching selector. When multiple declarations have equal specificity, the last declaration found in the CSS is applied to the element. Specificity only applies when the same element is targeted by multiple declarations. As per CSS rules, directly targeted elements will always take precedence over rules which an element inherits from its ancestor. - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)

The higher the specificity, the more difficult to override the rule.

#### Specificity Hierarchy

1. **Inline styles** - `

`
2. **IDs** - #id-name
3. **Classes, attributes and pseudo-classes** - .className, [attributes] and pseudo-classes such as :hover, :focus etc.
4. **Elements and pseudo-elements** - h1, div, :before and :after.
5. **Universal selector `(*)`** - applies to all elements (zero specificity)

## CSS Selectors

View contents

1. Universal selector `(*)` - it applies to all elements universally

```css
*,
*::before,
*::after {
box-sizing: border-box;
}
````

all elements to include padding and borders in the box model calculation instead of adding those widths to any defined dimensions.

```css
element.class p.intro Selects all

elements with class="intro"
element,element div, p Selects all

elements and all

elements
element element div p Selects all


elements inside


elements
element>element div > p Selects all

elements where the parent is a


element
element+element div + p Selects the first

element that is placed immediately after


elements
element1~element2 p ~ ul Selects every