Home > OS >  How to use ::before to make a shadow on top of a div with an image
How to use ::before to make a shadow on top of a div with an image

Time:11-02

I have this small image and i want to repeat so that it looks like a shadow on top of my div that it's like a cookies notification. How can i position it on top of my div cookieConsent like a shadow on the top?

THE IMAGE: shadow

#cookieConsent {
  width: 100%;
  background-color: #474540F2;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  z-index: 9999;
}

.cookieContainer {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
}

.cookieConsent-txt {
  color: #FFFFFF;
  width: calc (100% - 101px);
  margin: 0;
}

#cookieConsent a.cookieConsentOK {
  width: 85px;
  height: 56px;
  background: #FFFFFF;
  display: inline-block;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
<div id="cookieConsent">
  <div >
    <p >
      This site uses cookies
    </p>
    <a >Aceitar Cookies</a>
  </div>
</div>

CodePudding user response:

You don't need to use an image for this, you can use the box-shadow properties and negative values - specifically the y and spread properties.

#cookieConsent {
  width: 100%;
  background-color: #474540F2;
  position: fixed;
  bottom: 50px;
  left: 0;
  right: 0;
  z-index: 9999;
  box-shadow: 0px -4px 10px -2px rgb(0, 0, 0,0.4);
}

.cookieContainer {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
}

.cookieConsent-txt {
  color: #FFFFFF;
  width: calc (100% - 101px);
  margin: 0;
}

#cookieConsent a.cookieConsentOK {
  width: 85px;
  height: 56px;
  background: #FFFFFF;
  display: inline-block;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
<div id="cookieConsent">
  <div >
    <p >
      This site uses cookies
    </p>
    <a >Aceitar Cookies</a>
  </div>
</div>

If you need to use an image, set the image as a background on a pseudo element:

#cookieConsent::before {
  content: '';
  display: block;
  background-image: url(https://via.placeholder.com/10);
  background-repeat: repeat-x;
  width: 100%;
  height: 10px;
  position: absolute;
  left: 0;
  top: -10px;
}

#cookieConsent {
  width: 100%;
  background-color: #474540F2;
  position: fixed;
  bottom: 50px;
  left: 0;
  right: 0;
  z-index: 9999;
}

#cookieConsent::before {
  content: '';
  display: block;
  background-image: url(https://via.placeholder.com/10);
  background-repeat: repeat-x;
  width: 100%;
  height: 10px;
  position: absolute;
  left: 0;
  top: -10px;
}

.cookieContainer {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
}

.cookieConsent-txt {
  color: #FFFFFF;
  width: calc (100% - 101px);
  margin: 0;
}

#cookieConsent a.cookieConsentOK {
  width: 85px;
  height: 56px;
  background: #FFFFFF;
  display: inline-block;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
<div id="cookieConsent">
  <div >
    <p >
      This site uses cookies
    </p>
    <a >Aceitar Cookies</a>
  </div>
</div>

  • Related