我正在为 Google Chrome 开发一个工具栏作为扩展的一部分。假设工具栏是一个由以下 CSS 描述的简单矩形:
#top{
display: none;
width: 100%;
background: red;
z-index:9999999;
height:40px;
}
我注入(inject)了看起来更不像的工具栏:
<body>
<div id="panel_left">
....
</div>
<div id="panel_right">
....
</div>
</body>
我通过以下方式将它注入(inject) iframe:
$("body").before('<iframe name="top" id="top" frameborder="0"></iframe>');
var top = document.getElementById("top");
top.src = chrome.extension.getURL("top.html");
问题开始于某些网页,因为它们的 css 能够覆盖我的工具栏。我希望工具栏从网站的最顶部开始,高度为 40px,然后显示通常的网页内容。
你有没有想过如何去做(或者更确切地说是改进它,因为它在某些网页上有效)
最佳答案
您是否尝试添加:
top: 0;
left: 0;
margin: 0;
padding: 0;
在插入工具栏之前添加:
// Take down the webPage
document.getElementsByTagName('body')[0].style.marginTop = '39px';
// Or more if your toolbar is greater
关于css - 谷歌浏览器,html 工具栏 - 总是在最前面的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5437600/