简体   繁体   English

CSS:HTML和正文标签的宽度设置为100%-为什么需要这样做?

[英]css: width of html and body tags set to 100% - why this is needed?

I'm curious what is the purpose of html, body{width:100%} in the css file? 我很好奇CSS文件中html, body{width:100%}的用途是什么? Is it kind of css reset code? 这是CSS重置代码吗?

Disabling this piece of code doesn't affect on what I see in the browser. 禁用这段代码不会影响我在浏览器中看到的内容。 Is it a "bugfix" for some old browser or for mobile devices? 它是某些旧浏览器还是移动设备的“错误修正”? Am I missing something? 我想念什么吗? Could anybody please explain? 有人可以解释吗?

Thank you. 谢谢。

As far as I know, width:100% is used when you want a block-level element to fill any remaining space inside it's parent or when an element is inheriting a set width value that you want to override. 据我所知,当您希望块级元素填充其父级内部的任何剩余空间时,或者当元素继承要覆盖的设置宽度值时,都会使用width:100%。 But in most cases it is unnecessary or will bring undesirable results. 但是在大多数情况下,这是不必要的,否则会带来不良结果。

As far I know it's not necessary maximum time, some time not mentioning this is creates problem with IE browser by improper formatting of the content. 据我所知,这不是不必要的最大时间,有一段时间没有提及这是由于内容格式不正确而导致IE浏览器出现问题。 otherwise there is no need. 否则没有必要。

Understand it this way. 这样理解。

HTML is parent of BODY. HTML是BODY的父级。
BODY is parent of the content. BODY是内容的父级。
Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have it's height set.And since the content of body will probably need to change dynamically. Body向其父级(HTML)寻求如何缩放动态属性,因此HTML元素需要设置其高度。由于body的内容可能需要动态更改。 Setting min-height of the body to 100% makes that happen. 将身体的最小高度设置为100%即可实现。

If we are using overflow:hidden with body and the body isn't able to take the height of dynamic content then the part outside the body height won't be visible . 如果我们在主体中使用了overflow:hidden ,而主体无法承受动态内容的高度,那么主体高度之外的部分将不可见。

Now the question is 现在的问题是
When doesn't the body take the height of the dynamic content ? 身体什么时候不吸收动态内容的高度?

When we are using floating elements .The height of the floating elements are not calculated by the parent until we use overflow:auto . 当我们使用浮动元素时,直到我们使用overflow:auto ,浮动元素的高度才由父级计算出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管在 CSS 中设置宽度为 100%,但 HTML 中的正文内容不是全屏? 响应时 - Body content in HTML not full screen although set width 100% in CSS? when responsive 图片在 HTML 中设置宽度高度属性,在 CSS 中设置宽度 100% - Image Set Width Height Attributes in HTML, Set Width 100% in CSS 为什么html元素的宽度未设置为页面的100%? - Why is width of the html element not set to 100% of the page? 为什么html,body {height 100%}会同时影响宽度和高度,而宽度100%仅影响宽度? - Why does html,body {height 100%} affect both width and height, but width 100% only affects width? 为什么在浏览器窗口调整大小时,主体宽度未设置为100%? - Why body width don't set to 100% on browser window resize? 高度CSS属性(100%,100vh)是否对 <html> 要么 <body> 标签? - Does height CSS attribute (100%, 100vh) have some meaning for <html> or <body> tags? html、正文和 div 设置为 100% 宽度,但它仍然没有占用全部 100% - html, body, and div set at 100% width but it's still not taking the full 100% 为什么不能100%的宽度在这里工作? (html / css) - Why isnt 100% width working here? (html/css) 为什么不能<tr>在 Tailwind css 中设置为 100% 宽度 - Why can't <tr> be set to its 100% width in Tailwind css 为什么要使用99.9%的HTML / CSS宽度而不是100%? - Why would you use a HTML/CSS width of 99.9% instead of 100%?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM