Yes — in CSS inside <style>, . and # are used to identify different kinds of selectors.

. — class selector

A dot selects an HTML element based on its class attribute.

<style>
  .button {
    color: white;
    background: blue;
  }
</style>

<button class="button">Click me</button>

Here:

.button

means “select every element whose class is button.”

You can give the same class to multiple elements:

<p class="highlight">One</p>
<p class="highlight">Two</p>

Both are affected by:

.highlight {
  color: red;
}

# — ID selector

A hash selects an HTML element based on its id attribute.

<style>
  #header {
    background: black;
    color: white;
  }
</style>

<div id="header">My Header</div>

Here:

#header

means “select the element whose ID is header.”

An id is normally intended to be unique within the page:

<div id="header">...</div>

The key difference

CSS HTML Meaning
.button class="button" Class
#header id="header" ID
button <button> HTML element/tag

Example

<style>
  p {
    font-size: 16px;
  }

  .warning {
    color: orange;
  }

  #main-title {
    font-size: 32px;
  }
</style>

<h1 id="main-title">Welcome</h1>

<p class="warning">Be careful!</p>

<p>Normal paragraph.</p>

A useful way to remember

  • . → class
  • # → id
  • no symbol → HTML element

Also, these are called CSS selectors, rather than function names.

Comments

Popular posts from this blog

[MAIN PROGRAM] UNDONE HOUSEHOLD WORKs WEB-PROGRAM v2/MAIN

PENDING ITEMs [REVISION] v0