gpt4 book ai didi

html - CSS 悬停和位置 : absolute not working

转载 作者:太空宇宙 更新时间:2023-11-04 01:24:23 24 4
gpt4 key购买 nike

我知道这个问题已经被问过几次,但没有一个答案很清楚,我已经写了一些基本代码,如果有人能解决代码并解释为什么会出现这个问题,我将不胜感激。问题是当页脚上的位置设置为绝对时,悬停动画被取消。

https://codepen.io/HamHat/pen/zpemYz

这是供以后使用的代码,似乎是一个常见问题。

HTML:

<footer>
<ul>
<li><a href="#about">About Us</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#privacy">Privacy</a></li>
</ul>
<div class="bear">
<a href="google.com"><img src="https://placebear.com/g/80/80"></a>
</div>
</footer>

CSS:

footer{
display: flex;
position: absolute;
justify-content: center;
right: 0;
bottom: 0;
left: 0;
background-color: red;
}

ul{
display: flex;
list-style-type: none;
border-radius: 5px;
}

li a{
color: black;
display: inline-block;
text-align: center;
padding: 16px;
text-decoration: none;
}

li a:hover{
background-color: white;
}

.bear {
width : 100%;
position: absolute;
text-align: right;
}

最佳答案

熊图像宽度是 100%,这就是它不起作用的原因

footer{
display: flex;
position: absolute;
justify-content: center;
right: 0;
bottom: 0;
left: 0;
background-color: red;
}

ul{
display: flex;
list-style-type: none;
border-radius: 5px;
}

li a{
color: black;
display: inline-block;
text-align: center;
padding: 16px;
text-decoration: none;
}

a:hover{
background-color: white;
}

.bear {
width : 10%;
position: absolute;
right:0;
}
<footer>
<ul>
<li><a href="#about">About Us</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#privacy">Privacy</a></li>
</ul>
<div class="bear">
<a href="google.com"><img src="https://placebear.com/g/80/80"></a>
</div>
</footer>

关于html - CSS 悬停和位置 : absolute not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48367056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com