css - 如何相对于 CSS 中另一个元素的位置引用 html 元素位置?
问题描述
假设我有 2 个 html 元素,位于 html 表单的不同部分:元素“first-element”和元素“second-element”。
“第一个元素”是一个弹性项目,它的位置随页面大小调整(弹性包装)而变化。当我将第一个元素悬停时,我想让“第二个元素”可见并将其放置在从“第一个元素”向下 20px 的位置。
我试过了:
#first-element:hover #second-element {
display:block;
position:absolute;
left:#first-element.left;
height:#first-element.top+20px;
}
其中,显然没有工作:)
你能告诉我这样的事情是否可能,正确的语法是什么?或者,也许建议另一种方法?谢谢!
解决方案
You need jQuery or Javascript to do this. It is not possible with only CSS.
See an example here with jQuery
$(document).ready(function{
$('#first-element').hover(function(){
$('#second-element').toggle(200);
})
})
Style the rest of what you want in your css.
#second-element{
position: absolute;
top: 20px;
}
推荐阅读
- spring - 如何从请求标头验证身份验证令牌
- php - 凭证必须是带有 SQS 的 PHP SDK 上的 Aws\\Credentials\\CredentialsInterface 错误的实例
- jtag - Atollic TrueStudio 中调试程序的问题
- javascript - 如何管理列表中的 Angular 元素更新
- python - mpmath 函数 hyperu 的默认精度是多少?
- flutter - WebView不能在flutter中加载两个不同的url?
- regex - 如何在 ruby 的正则表达式中对特殊字符和字母进行分组?
- dependency-injection - 如何从另一个程序集配置 Asp.Net 核心 WebAPI 中的服务
- reactjs - 将 JSX 元素声明为子元素
- reporting-services - 根据日期字段过滤 Tablix