HTML div and classes

By MBD DEV

NOTE: THIS PAGE IS A EMBED


The class attribute is often used to point to a class name in a style sheet.
In the following example we have a one <div> elements with a class attribute with the value of “card”.The <div> elements will be styled equally according to the .card style definition in the head section.

HTML

<body>

<div class="card">
<h2>This is a card</h2>
<p> The card is styled to have the backgorund color to red and the text color to white.</p>
</div> 

</body>

CSS

<style>
.card {
  background-color: red;
  color: white;
  border: 2px solid black;
  margin: 20px;
  padding: 20px;
}
</style>

Output

Useing the code above we ahve made a “card” with the background set to red and the text color set to white.

MBD CDN Error