问题描述
我正在处理的这个页面上的HTML标签是一个给它顶部填充
的 28px
。单击按钮时我需要暂时离开,但似乎我无法更改HTML标签本身的样式。
The HTML tag on this page I'm working on is in a class that is giving it a top padding
of 28px
. I need this to go away temporarily when a button is clicked, but it doesn't appear that I can change the styling of the HTML tag itself.
我是否需要在body标签上使用 position:relative;
或类似的东西?有没有办法将CSS分配给我不知道的HTML标签?
Will I need to use position: relative;
on the body tag or something similar? Is there really a way to assign CSS to the HTML tag that I don't know about?
@ Comments:
@ Comments:
对不起,我在这里有点匆忙。这是有效的:
Sorry, I'm in a bit of a rush here. It's something to the effect of this:
<html class='pad_my_top'>
<head>
<style type='text/css'>
.pad_my_top{
padding-top: 28px;
}
body{
background: #000000;
}
</style>
<script type='text/javascript'>
function its_gone(){
// Something here to remove padding.
alert("It's gone. Hurray!");
// Something to put it back.
}
</script>
</html>
<body>
<button onClick='its_gone()'>Click me to get rid of the top padding</button>
</body>
</html>
我真的希望它消失,所以我可以用Javascript打印页面,但我宁愿不使用任何第三方代码,因为这是一个WordPress的插件,我不想要十亿依赖。我只需要隐藏/重新显示3个div并(重新)更改2个样式。
I really want it gone so I can print the page with Javascript, but I'd rather not use any 3rd party code because this is for a plugin for Wordpress and I don't want a billion dependencies. I only need to hide/re-display 3 divs and (re)change 2 styles.
推荐答案
使用此删除顶部填充:
document.documentElement.style.paddingTop = "0";
并将其设置回来:
document.documentElement.style.paddingTop = "28px";
这篇关于Javascript - 修改HTML标签上的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!