How can i change the position of price in the following code?

Viewed 73

After adding a position: fixed; to my header everything was in front of my header because they were using a position: absolute or position: relative I deleted them, and problem solved but now I want to change the position of price since I can not use a relative or absolute position because of this:

image

in this image price uses a relative position and header uses a fixed position but price is infront of the header so i decided to delete the position from price:

image

How can I change the position of price in the following code? For example I want to put it in bottom right without setting a position: absolute or position: relative.

Or if there is a better solution that can help me to put my content behind the fixed header without deleting the position property of contents what is it?

.header {
  width: 100%;
  height: 200px;
  position: fixed;
  background-color: darkcyan;
  top: 0;
  left: 0;
  right: 0;
  margin-top: 0;
  margin-right: 0;
}

body {
  margin-top: 333px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  margin-right: 0;
  margin-left: 0;
  margin-bottom: 0;
}

.footer {
  background: darkslateblue;
  margin-top: 100px;
  height: 100px;
  margin-right: 0px;
  width: 100%;
}

.card {
  max-width: 400px;
  margin: auto;
  text-align: center;
  font-family: arial;
  border-style: solid;
  border-width: 6px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-gap: 1em;
}

.card img {
  height: 400px;
  width: 400px;
  vertical-align: middle;
}

.price {
  background-color: #f44336;
  font-size: 22px;
  border-radius: 3px;
  width: 131px;
  padding: 5px;
}

.card button {
  border: none;
  color: white;
  background-color: #000;
  cursor: pointer;
  width: 100%;
  height: 100px;
  font-size: 44px;
  align-items: center;
}

.card button:hover {
  opacity: .5;
  background-color: #330;
}

#id {
  background-color: saddlebrown;
  color: white;
  margin: 0;
  font-size: 30px;
  height: 310px;
}

.number {
  width: 50px;
  height: 50px;
  background-color: #330;
  color: yellow;
  border-radius: 50%;
  position: absolute;
  top: -22px;
  right: -22px;
  justify-content: center;
  align-items: center;
  display: flex;
  font-size: 22px;
}

@media (max-width: 1864px) {
  .card {
    max-width: 300px;
  }
  .price {
    font-size: 20px;
  }
  .card img {
    height: 300px;
    width: 300px;
  }
}

@media (max-width: 1319px) {
  .grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
<head>
  <!-- <link rel="stylesheet" href="{% static 'main.css' %}"> -->

  <div class="header">
    <h1>header</h1>
  </div>
</head>

<body style="background-color: #36454F;">
  <div class="grid">
    <!-- {% for i in p%} -->
    <div class='card'>
      <div class="number">{{i.Number}}</div>

      <img src="{{i.image}}"></img>

      <p id="id">{{i.description}}</p>

      <a href="{{i.buy}}" target='_blank' rel='noopener noreferrer'>
        <button><span class="price"> ${{i.price}}</span> buy</button>
      </a>
    </div>
    <!-- {%endfor%} -->
  </div>

  <div class="footer">
    <h1>hello</h1>
  </div>
</body>

1 Answers

Add a z-index property in the header class.

.header{
    width: 100%;
    height: 200px;
    position: fixed;
    background-color: darkcyan;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    margin-top: 0;
    margin-right: 0;
}
Related