Cascading Style Sheets (CSS) basic font color binding

Cascading Style Sheets (CSS)

Style used to define page elements

  • Set font and color
  • Set position and size
  • Add animation effects
h1 {
  color: white;
  font-size: 14px;
}

h1: Selector
color: selector Property
white: property Value
font-size:14px; : Declaration

Using CSS in pages

Outer chain

<link rel="stylesheet" href="/assets/ style.css " />

embed

<style>
  li {
    margin: 0;
    list-style: none;
  }
  p {
    margin: 1em 0;
  }
</style>

inline

<p style="margin:1em 0">Example Content</p>

Selector selector

  • Find the elements in the page to style them

  • Select elements in a variety of ways

    • By tag name, class name, or id
    • By attribute
    • By position in the DOM tree

universal selector

* {
  color: red;
}

tag chooser

Six level title
<h6>
    Six level title
</h6>
<style>
	h6{
	color:orange;
}
</style>

id selector

LOGO
<h6 id="logo">LOGO</h6>
<style>
  #logo {
    color: red;
    font-size: 20px;
    font-weight: 200;
  }
</style>

Class selector

Todo List

  • Learn HTML
  • Learn CSS
  • Learn JavaScript

attribute selectors

user name:

password:

<label>user name: </label>
<input value="zhao" disabled />
<label>password: </label>
<input value="123456" type="password" />

<style>
  [disabled] {
    background: #eee;
    color: #999;
  }
  input[type="password"] {
    border-color: red;
    color: red;
  }
</style>

Back to the top

view picture

<p><a href="#Top "> back to top</a></p>
<p><a href="a.jpg">view picture</a></p>
<style>
  a[href^="#"] {
    //#Select the beginning of a specific combination
    color: #f54767;
    background: 0 center/1em url(https://assets.codepen.io/59477/arrow-up.png)
      no-repeat;
    padding-left: 1.1em;
  }
  a[href$=".jpg"] {
    //$end of selected combination
    color: deepskyblue;
    background: 0 center/1em url(https://assets.codepen.io/59477/image3.png)
      no-repeat;
    padding-left: 1.2em;
  }
</style>

Pseudo class

  • Elements are not located based on labels and attributes
  • Several pseudo classes
    • State pseudo class
    • Structural pseudo class

Stateful pseudo class

example.com user name:
```html example.com user name: ```

Structural pseudo class

  1. Titanic
  2. Star Wars: Awakening of the force
  3. Avengers 3
  4. Jurassic World
  5. Avatar
<ol>
<lib Avatar</li>
<li>Titanic</li>
<li>Star Wars:Force Awakening</li>
<li>Avengers 3</li>
<li>Jurassic World</li>
</ol>

<style>
li {
  list-style-position: inside;
  border-bottom: 1px solid;
  padding: 0.5em
}

 li:first-child { //*List first*/
  color: coral
}
 li:last-child { /* Last in list */
   border-bottom: none; /* No bottom line */
}
</style>
user name: Minimum 3 characters
<label>
  user name:
  <input class="error" value=" aal" />
</label>
<span class="error'"> Minimum 3 characters </span>
<style>
  .error {
    color: red;
  }
  input.error {
    border-color: red;
  }
</style>

combination

name grammar explain Example
Direct combination AB Meet both A and B input:focus
Offspring combination A B Check B if it is a descendant of A nav a
Parent-child combination A > B Check B if it is a child of A section > p
Sibling Combinators A ~ B Check B if it is after A and at the same level as A h2~p
sibling selector A + B Check B if it follows A h2+ p

Larsen Volcano National Park

Larsen Volcano National Park is located in

climate

Because Larsen Volcano National Park

Above this height, the climate is very cold

<article>
  <h1>Larsen Volcano National Park</h1>
  <p>Larsen Volcano National Park is located in...</p>
  <section>
    <h2>climate</h2>
    <p>Because Larsen Volcano National Park...</p>
    <p>Above this altitude, the climate is very cold...</p>
  </section>
</article>

<style>
  article p {
    color: black;
  }
  article > p {
    /* // Select the child element p under the article */
    color: blue;
  }
  h2 + p {
    /* //Select p immediately following h2 */
    color: red;
  }
</style>

Selector group

<style>
  body,h1,h2,h3,h4,h5,h6,ul,ol,li {
   {
    margin: 0;
    padding: 0;
  }
  [type="checkbox"],
  [type="radio"] {
    box-sizing: border-box;
    padding: 0;
  }
</style>

colour

Color test_ W3C

rgb(13, 255, 244)

#0dfff4

hsl(177, 100%, 53%)

Hue (H) Saturation (S) Lightness (L)
It is the basic attribute of color, such as red, yellow, etc; The value range is 0-360. Refers to the bright degree of color, the higher the bright degree; The value range is 0-100%. Refers to the brightness of the color; The higher the, the brighter the color; The value range is 0-100%.

keyword

red,blue,green,cyan

alpha transparency

<style>
  #ff000075;
  rgba(255, 0, 0, 0.46);
  hsla(0,100%, 50%, 0.46);
</style>

Font font family

Carlsbad caves

Carlsbad caves is a national park in the United States, located in the southeast of New Mexico. Visitors can enter on foot through the natural entrance or directly reach the 230 meter deep cave through the elevator.

<h1>Carlsbad Caverns (CarLsbad Caverns)</h1>
<p>
  Carlsbad Caverns (Carlsbad Caverns) It is a national park in the United States,
  Located in southeastern New Mexico. Visitors can pass through the day
  However, the entrance can be entered on foot, or you can directly reach the 230 meter deep cave through the elevator.
</p>
<style>
  h1 {
    font-family: Optima, Georgia, serif;
  }
  body {
    font-family: Helvetica, sans-serif;
  }
</style>

Generic font family

Font family Sample
Serif serif Georgia, Arial
Sans serif sans serif Arial, Helvetica, bold, Microsoft YaHei
Cursive script Caflisch Script, italics
Fantasy Comic Sans MS, Papyrus,
Monospace equal width font Consolas, Courier, Chinese font
Font family usage suggestions
  • The generic font family is written at the end of the font list. If the corresponding font cannot be found, it will be approximately replaced
  • English font is placed in front of Chinese font, and Chinese characters include English
Using Web Fonts

Web fonts are awesome !

<h1>Web fonts are awesome !</h1>
<style>
  @font-face {
  font-family: "Megrim" ;
  src:
  urL(https://fonts.gstatic.com/s/megrim/v11/46kulbz5WjvLqJZVam_hVUdI1w.woff2)
  format('woff2' );
  }
  h1 {
  font-family; Megrim, Cursive;
  }
</style>

Font size font size

  • keyword
    • small,medium,large
  • length
    • px,em
  • percentage
    • Font size relative to parent element

A web font example

Notes: Web fonts ...

With this in mind, let's build...

<section>
  <h2>A web font example</h2>
  <p class="note">Notes: Web fonts ...</p>
  <p>With this in mind, let's build...</p>
</section>
<style>
  section {
    font-size: 20px;
  }
  section h1 {
    /* // h1 Should be twice the parent 40px */
    font-size: 2em;
  }
  section .note {
    /* // Parent 80% 16px */
    font-size: 80%;
    color: orange;
  }
</style>
Font tilt

Normal Text

Italic Text

```html

Normal Text

Italic Text

```

Word weight

  • Fifty strings without reason (100)
  • Jinse groundless fifty strings (200)
  • Jinse groundless fifty strings (300)
  • Fifty strings without reason (400 normal)
  • Jinse unprovoked fifty strings (500)
  • Jinse unprovoked fifty strings (600)
  • Jinse unprovoked fifty strings (700 BOLD)
  • Fifty strings without reason (800)
  • Jinse groundless fifty strings (900)
<ul>
  <li class="w1">Fifty strings without reason(100)</li>
  <li class="w2">Fifty strings without reason(200)</li>
  <li class="w3">Fifty strings without reason(300)</li>
  <li class="w4">Fifty strings without reason(400-normal)</li>
  <li class="w5">Fifty strings without reason(500)</li>
  <li class="w6">Fifty strings without reason(600)</li>
  <li class="w7">Fifty strings without reason(700-bold)</li>
  <li class="w8">Fifty strings without reason(800)</li>
  <li class="w9">Fifty strings without reason(900)</li>
</ul>
<style>
  .W1 {
    font-weight: 100;
  }
  .W2 {
    font-weight: 200;
  }
  .W3 {
    font-weight: 300;
  }
  .W4 {
    font-weight: 400;
  }
  .w5 {
    font-weight: 500;
  }
  .W6 {
    font-weight: 600;
  }
  .w7 {
    font-weight: 700;
  }
  .w8 {
    font-weight: 800;
  }
  .w9 {
    font-weight: 900;
  }
</style>

Line height

Font families recap

As we looked at in fundamental text and font styling, the fonts applied to your HTML can be controlled using the font-family property. This takes one or more font family names.

<section>
  <h1>Font families recap</h1>
  <p>
    As we looked at in fundamental text and font styling, the fonts applied to
    your HTML can be controlled using the font-family property. This takes one
    or more font family names.
  </p>
</section>
<style>
  h1 {
    font-size: 30px;
    line-height: 45px;
  }
  p {
    font-size: 20px;
    /* For pure numbers, 20 * 1.6 = 32 will be calculated according to the font size  */
    line-height: 1.6;
  }
</style>

font: style weight size/height family

h1 {
  /* Italic weight size / line height font family */
  font: bold 14px/1.7 Helvetica, sans-serif;
}
p {
  font: 14px serif;
}

Text align text alignment:

--- left --- --- center --- --- right --- --- justify ---
Align left Center alignment Right align Scatter / align ends

Spacing spacing

Letter spacing: letter spacing
Word spacing: word spacing

Text indent
Can be set to negative

Text decoration

Text decoration: none, underline, line through middle underline, overline upper underline

underline: This text has a line underneath it.

overline: This text has a line over it.

line-through: This text has a line going through it.

none: This link will not be underlined

dashed underline overlin: This text has lines above and below it.

blink: This text might blink for you, depending on the browser you use.

White space blank

Newline character Spaces and tabs Text wrap End of line space
normal merge merge Line feed delete
nowrap merge merge nowrap delete
pre retain retain nowrap retain
pre-wrap retain retain Line feed Hang
pre-line retain merge Line feed delete
break-spaces retain retain Line feed Line feed

Debug CSS

  • Right click the page and select "check"
  • Use shortcut keys
    • Ctrl+Shift+I (Windows)
    • Cmd+Opt+I (Mac)

Q&A

vh: 1% of screen height
vw: 1% of screen width

rem: calculated from root element
em: parent element calculation
px: absolute size

Keywords: Front-end

Added by m3rajk on Fri, 21 Jan 2022 09:37:32 +0200