简体   繁体   English

HTML中的正文和Div对齐

[英]Body and Div alignment in HTML

i am giving body and div same height,width. 我给身体和股利相同的高度,宽度。 my css is 我的CSS是

 body {
background-repeat: no-repeat;
background-color: maroon;
width: 1280px;
height: 670px;
margin: 0;

} }

div {
background-color: yellow;
width: 1280px;
height: 670px;

} }

and my html is 和我的HTML是

<body>
<div   id='slider4' class='swipe'>
<div>
<div style='display:block' >1</div>
<div style='display:none'><div>2</div></div>
</div>

</body>

but when i open it in firefox it display like this i dont know 但是当我在Firefox中打开它时,它会像这样显示

size of html=size of body=size of div html的大小=正文的大小= div的大小

then also red color is beyond yellow. 然后红色也超过黄色。

在此处输入图片说明在此处输入图片说明在此处输入图片说明

The maroon shows because for backward compatibility reasons, by default the html element takes its background colour from the body element, and the viewport takes its background colour from the html element. 栗色显示是因为出于向后兼容性的原因,默认情况下html元素从body元素获取其背景颜色,而视口从html元素获取其背景颜色。

The CSS 2.1 spec says: CSS 2.1规范说:

For documents whose root element is an HTML "HTML" element or an XHTML "html" element that has computed values of 'transparent' for 'background-color' and 'none' for 'background-image', user agents must instead use the computed value of the background properties from that element's first HTML "BODY" element or XHTML "body" element child when painting backgrounds for the canvas, and must not paint a background for that child element. 对于其根元素是HTML“ HTML”元素或XHTML“ html”元素的文档,其值为“ background-color”为“ transparent”,为“ background-image”为“ none”,则用户代理必须改用在为画布绘制背景时,该元素的第一个HTML“ BODY”元素或XHTML“ body”元素子元素的背景属性的计算值,并且不得为该子元素绘制背景。

and

The background of the root element becomes the background of the canvas and covers the entire canvas 根元素的背景成为画布的背景,并覆盖整个画布

You can set the background colour of the html element to, say, "white" to stop the maroon area extending beyond the height of the body element. 您可以将html元素的背景色设置为“白色”,以停止褐红色区域超出body元素的高度。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM