Your browser does not support JavaScript!
Upvotes Anonymous 0 User 0

How to Style Multiple Elements with CSS

If we want a style to be applied to multiple elements on the page, we can give each element a class:
  <title>My Page</title>
  <link rel="stylesheet" type="text/css" href="style.css"/>
  <div class="fruit">Apple</div>
  <div class="fruit">Pear</div>
  <div class="fruit">Orange</div>
Above we have three <div> elements that have the class fruit. If we put this style in our CSS file:
.fruit {
    border: 3px solid lightblue;
    font-size: 20px;
    font-weight: bold;
    font-family: Arial;
    margin-top: 20px;
    color: brown;
The . helps us select all elements by a class name.

The result is:
Was this helpful?


Leave a Comment

I agree to the Terms of Service
Design © 2015, Downranked, LLC.,
Original user code contributions under MIT License