把body中的html隐藏,html – 显示:chrome中的body标签上的none不会隐藏背景

W3 CSS2 spec,

For HTML documents, however, we recommend that authors specify the

background for the BODY element rather than the HTML element. User

agents should observe the following precedence rules to fill in the

background: if the value of the ‘background’ property for the HTML

element is different from ‘transparent’ then use it, else use the

value of the ‘background’ property for the BODY element. If the

resulting value is ‘transparent’, the rendering is undefined.

根据这个,如果你在主体上设置背景颜色或背景图像,但是没有在html上设置透明而不是透明,那么html将使用主体的背景.所以当你隐藏身体时,html仍将使用它的背景.

DEMO

var hideButton = $('#hide-body');

var toggleBGButton = $('#toggle-html-bg');

hideButton.on('click', function() {$('body').hide()} );

toggleBGButton.on('click', function() {$('html').toggleClass('bg')} );

html {

background-color: transparent;

}

html.bg {

background-color: orange;

}

body {

background-image: url("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png");

background-color: blue;

}

body.hide {

display: none;

}

Hide body

Toggle <html> background-color

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值