jquery - 使用 Jquery 将图像定位到 div 的顶部
问题描述
我有一个带有 id.css 的图像:
#imgP {
max-width:300px ;
max-height:300px ;
position: relative;
top:0 ;
left: calc(1em + 1vw);
}
我尝试将顶部定位到他的父 id.css:
#parent {
top:-60vh;
background-image: url('../Image/infome.png');
border-radius: 10px;
background-size: cover;
background-position: center;
background-repeat: none;
padding: 10px;
}
使用 jQuery
$(window).load(function() {
y = $('#parent').offset().top;
$("#imgP").css({top:-y});
});`
但是顶部设置为 px 数字并且不粘在 div 顶部位置。
解决方案
推荐阅读
- augmented-reality - Google Model Viewer AR-如何在没有海报或对象预览的情况下拥有“在 AR 中查看”按钮
- compiler-errors - 如何从 arrayList 中的不同对象调用方法?
- node.js - 错误:无法加载默认凭据
- java - 重复发送 HTTP 请求,即使应用程序在 Android 上处于后台也是如此
- html - 我可以在引导程序上编辑多个类吗?
- graphql - SubSelectionRequired 类型的验证错误:字段的类型为空需要子选择
- javascript - 时刻 - 从星期几计算日期
- java - 使用 JAAS 进行用户验证的最佳场所
- sql - 在PostgreSQL中将两个或多个不同的SELECT查询组合到具有不同条件的同一张表中
- java - 如何查看存储在 ArrayList 中的所有元素?