gpt4 book ai didi

html - CSS 悬停效果显示另一个 div

转载 作者:太空宇宙 更新时间:2023-11-04 04:09:29 26 4
gpt4 key购买 nike

我正在尝试创建一个 css 悬停效果,应该隐藏带有文本和圆圈上方向下箭头的 div,当我悬停圆圈时它们应该出现。

但是我做不到。在我使用的代码下方。

当我悬停在这个圆圈上时,上面的两个div应该是这样的

enter image description here

<head>
<title>CSS Hovering Effect Practical Class</title>
<style type="text/css">

* {
margin:0;
padding:0;
}

#wrap {
background:#4485F5;
margin:10px 0;
padding:30px;
text-align:center;
}

h1 {
color:#fff;
letter-spacing:2px;
font-size:50px;
margin-bottom:15px;
}

p {
color:#fff;
background:#944E90;
width:600px;
font-size:25px;
padding:3px;
margin:auto;
}

span {
font-style:italic;
}

#features {
margin: 25px 0;
}

#baloon {
color:#ddd;
margin:auto;
padding:15px;
font-size:16px;
letter-spacing:1px;
background:url('bg.png') repeat;
width:200px;
position:relative;
border-radius:5px;
}

#blackarrow {
background:url('blackarrow.png') no-repeat top center;
margin:auto;
height:15px;
width:15px;
margin-top:-7px;
}

#circle {
}

#circle img{
height:50px;
width:50px;
background:#fff;
padding:50px;
border:5px solid #00AEF0;
border-radius:500px;
transition:0.5s ease;
}

#circle img:hover {
height:60px;
width:60px;
background:#ddd;
padding:60px;
border:8px solid #00AEF0;
border-radius:500px;
}

#circle:hover > #baloon {
display: inline;
}

#inner {
}

#img {}

</style>
</head>

<body>
<div id="wrap">
<h1>Welcome to <span> CodeforBusiness</span> Site</h1>
<p>Your trusted web designing service provider for a decade</p>
<div id="features">
<div id="baloon">Best web designing services with our team</div>
<div id="blackarrow"></div>
<div id="circle"><img src="avatar.gif" /></div>
</div>
</div>

</body>

最佳答案

使用您的标记无法实现,因为当前的 css 选择器无法通过通用兄弟组合器~ 或更有用的相邻兄弟组合器以非常有限的方式定位父元素和兄弟元素+(See docs)。

您最好选择不同的嵌套结构,以使悬停效果起作用。

<div id="features">
<div id="circle"></div>
<div id="description">
<div id="baloon">Best web designing services with our team</div>
<div id="blackarrow"></div>
</div>
</div>

现在 #description div 是您圈子之后的相邻兄弟,您可以通过 + 定位它。 (如果你有多个元素,你需要这个容器,如果它只有一个 #baloon 元素在里面,你也可以直接定位这个)。

#circle:hover + #description {
display:none;
}

看看我的最小example .您只需要对定位进行一些固定就可以了。

关于html - CSS 悬停效果显示另一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20886230/

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