css id class code example

Example 1: css class and id

Select an element with the ID "id" and the class "class":
#id.class {
}
example:
<div>
  <strong id="id" class="class">
      Foobar
  </strong>
  <strong class="class">
      Foobar
  </strong>
</div>
=> Will select the first <strong> element

Select all elements with the class "class",
which are decendents of a element with an ID of "id":
#id .class {
}
example:
<div id="id">
	<strong class="class">Foobar</strong>
</div>
=> Will select the <strong> element

Example 2: id in css

#id{
    color:red;
}

Example 3: css how to style id

/*put a # infront of the id*/
/*<section id="example"></section>*/
#example{
	margin: auto;
}

Example 4: css class id

css
.class
#id

Example 5: html id

<style>
#grepperHeader {
  background-color: lightblue;
  color: navy;
  padding: 40px;
  text-align: center;
}
</style>

<h1 id="grepperHeader">grepperHeader</h1>

Example 6: referance html id css

<style>
  #test {
  /*Styleing here*/
  }
</style>
<h1 id="test"></h1>