Affecting child elements by modifying the parent by CSS. is it possible?(通过 CSS 修改父元素来影响子元素.是否可以?)
问题描述
也许这是一个愚蠢的问题,但我相信它对许多初学者很有用.我已经构建了一个代码.我要做的是显示当前隐藏的文本(在 <p>
标签中),只有当实际的 <a>
悬停时.没有js可以吗?可以只对css/html进行操作吗?html代码在这里:
Maybe it's a silly question, but I'm sure it will be useful for many of beginners. I have constructed a code. What I'm trying to do is to display the text (in <p>
tags) which is currently hidden, only when the actual <a>
is hovered. Is this possible without js? Can it be done by operating on css / html only?
the html code is here:
<div class="promo2">
<a href="speakers-hire.html">
<div class="promo2a">
<p>SPEAKERS</p>
</div>
</a>
<a href="decks-hire.html">
<div class="promo2a">
<p>CD PLAYERS</p>
</div>
</a>
</div>
以及上面html对应的css:
and the css which correspond to the above html:
.promo2a:hover{
background:url(../_images/generic/glass5.png);
display:inline-block;
}
.promo2a p{
display:none;
}
所以基本上我希望在整个 div promo2a
悬停时显示 <p>
中的文本.
So basically I want the text in <p>
to be displayed when the whole div promo2a
is hovered.
非常感谢任何帮助.提前谢谢你.
Any help is kindly appreciated. Thank you in advance.
推荐答案
试试
.promo2a:hover > p {display:block;}
或任何适合您的需求
这篇关于通过 CSS 修改父元素来影响子元素.是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 CSS 修改父元素来影响子元素.是否可以?


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01