[英]Position element relative to another doesn't work
I am trying to position my element with class name "adsense" over the half height of element with class name "publish-info" but it doesn't work. 我正在尝试将具有类名称“ adsense”的元素放置在具有类名称“ publish-info”的元素的一半高度上,但是它不起作用。 I should mention that I can't edit the html source of my template.
我应该提到我无法编辑模板的html源。 I've tried this code:
我已经试过这段代码:
.publish-info {
height: 150px!important;
position: relative!important;
}
.adsense {
top: 50px!important;
position: absolute!important;
}
...and javascript: ...和javascript:
<script type='text/javascript'>
//<![CDATA[
window.onload = function () {
$('.publish-info').append($('.adsense'));
} //]]>
</script>
But this doesn't work. 但这是行不通的。 Here's my site: http://www.musicep.com/2013/07/bt-aqualung-surrounded.html
这是我的网站: http : //www.musicep.com/2013/07/bt-aqualung-surrounded.html
Your script and styles are doing roughly what they should do, but the problem is that the javascript function that places the .adsense
element inside your .publish-info
runs before the adsense div is available. 您的脚本和样式大致上应执行其应做的工作,但是问题是,在adsense div可用之前,将
.adsense
元素放入.publish-info
中的javascript函数会运行。
Since you're using jQuery anyway, I'd suggest changing the window.onload
to: 由于您仍然使用jQuery,因此建议您将
window.onload
更改为:
$(document).ready(function(){
$('.publish-info').append($('.adsense'));
});
See if that helps. 看看是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.