Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to differentiate between two of the same shape in HTML and CSS?

I’m trying to manipulate two different rectangles with CSS in two different ways.

Let’s say I have:

.header {
    background-color: #000000;

.rectangle {
    height: 2px;
    width: 100%;

<body>

<div class="header">
    <div class="rectangle"></div>
    <h1>Head</h1>
</div>

    <div class="rectangle"></div>

</body>

Can I alter the top rectangle without altering the bottom one? E.g is it possible to change the size of the top rectangle and not the bottom one?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, you can do it like this. Target the rectangle class that is inside of the header by using .header .rectangle. I hope this helps!

.rectangle {
  height: 10px;
  background: red;
}

.header .rectangle {
  background: blue;
}
<body>
  <div class="header">
    <div class="rectangle"></div>
    <h1>Head</h1>
  </div>

  <div class="rectangle"></div>

</body>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading