我有这个小图像,我想重复一遍,这样它看起来就像我的div上的一个阴影,就像一个cookie通知。我怎样才能把它放在我的div cookieConsent的顶部,就像一个阴影在上面?
图片:

#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 class="cookieContainer">
<p class="cookieConsent-txt">
This site uses cookies
</p>
<a class="cookieConsentOK">Aceitar Cookies</a>
</div>
</div>
发布于 2022-11-01 16:49:45
您不需要为此使用图像,您可以使用box-shadow属性和负值-特别是y和spread属性。
#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 class="cookieContainer">
<p class="cookieConsent-txt">
This site uses cookies
</p>
<a class="cookieConsentOK">Aceitar Cookies</a>
</div>
</div>
如果需要使用图像,请将图像设置为伪元素的背景:
#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 class="cookieContainer">
<p class="cookieConsent-txt">
This site uses cookies
</p>
<a class="cookieConsentOK">Aceitar Cookies</a>
</div>
</div>
https://stackoverflow.com/questions/74278727
复制相似问题