热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

HTML布局问题:设置top:0%和left:0%,但浏览器中仍出现空白填充

在HTML布局中,即使将`top:0%`和`left:0%`设置为元素的定位属性,浏览器中仍然会出现空白填充。这个问题通常与默认的浏览器样式、盒模型或父元素的定位方式有关。为了消除这些空白,可以考虑重置浏览器的默认样式,确保父元素的定位方式正确,并检查是否有其他CSS规则影响了元素的位置。

Alright this is probably a newbie question but it is very much frustrating me. I clearly say in the style tags that the top blue bar needs to be snug against the top and the two side panels need to be snug against the sides.

好吧,这可能是一个新手问题,但令我非常沮丧。我在风格标签中清楚地说,顶部的蓝色条需要紧贴顶部,两个侧面板需要紧贴侧面。

Yet for some reason it has taken the liberty of inserting a blank white space around my html.

然而出于某种原因,它已经冒昧地在我的html周围插入一个空白空格。

Here is the link: http://popularn.com/nate/error.html

这是链接:http://popularn.com/nate/error.html

See that white space on the left and at the top?

看到左边和顶部的空白区域?

Even when I say top:0% and left:0%, it still doesn't work. It's like it's laughing at me and I've had enough. It's like it is starting the document at top:2% and left:2% and there's nothing I can do...

即使我说顶部:0%而左:0%,它仍然无效。这就像它在嘲笑我,我已经受够了。这就像它在顶部开始文件:2%和左:2%,我无能为力......

3 个解决方案

#1


4  

remove margin from the body, set top left to 0, and off course don't forget the position attribute

从正文中删除边距,将左上角设置为0,然后当然不要忘记位置属性

 html,body{padding:0; margin:0;}
 #someElement{position: absolute; top:0; left:0}

also - putting position:absolute; top:0; left:0; to the body is like doing nothing and the position of the #top_menu should be position: fixed and not fixes which has no meaning

也 - 放置位置:绝对;顶部:0;左:0;身体就像什么都不做,#top_menu的位置应该是位置:固定而不是没有意义的修复

#2


1  

Browsers have a set of default styles which are known as 'User-agent styles'. These are a generic set of CSS rules that it applies to elements. You know when you put a H1 in a page, and it appears big, and in bold? These are those styles.

浏览器具有一组默认样式,称为“用户代理样式”。这些是适用于元素的一组通用CSS规则。你知道什么时候你把H1放在一个页面里,它看起来很大,而且是粗体?这些是那些风格。

The base elements in your pages are all styled with these UA rules. Body, HTML, div, etc - they all have a small amount of padding on them, which is where this is coming from.

页面中的基本元素都使用这些UA规则进行样式设置。正文,HTML,div等 - 它们都有少量的填充,这就是它的来源。

Consequently, it's good practice to always use a CSS reset, when you are developing beyond basic styles. There's a couple of good ones I'd recommend. As CSS is hierarchical (hence cascading!) you need to include resets first.

因此,当您开发超出基本样式时,最好始终使用CSS重置。我建议有几个好的。由于CSS是分层的(因此级联!),您需要先包含重置。

Firstly is Eric Meyer's CSS reset. This applies generally to everything, and is invisible for most purposes. You include the file, everything gets reset to base.

首先是Eric Meyer的CSS重置。这通常适用于所有事物,并且对于大多数目的而言是不可见的。您包含该文件,所有内容都将重置为base。

Secondly is Yahoo UI 3 (YUI) reset, which takes a slightly different approach. They let you selectively apply a reset to different areas of a page by including a class. This is useful for some things, but for almost every small/medium sized project I'd recommend Eric's reset linked above - but it's useful for comparison and learning.

其次是Yahoo UI 3(YUI)重置,这需要稍微不同的方法。它们允许您通过包含类来有选择地将重置应用于页面的不同区域。这对某些事情很有用,但对于几乎所有中小型项目,我都建议将Eric重置在上面 - 但它对比较和学习很有用。

Instead of trying to tune out inconsistencies as you go along - using a CSS reset will give you a baseline for all elements which is the same on every browser. Believe me - you want this. When you get further into html, forms for example or fun stuff like that, then this kind of thing is an absolute life saver.

而不是试图在你进行时调整不一致性 - 使用CSS重置将为每个浏览器上的所有元素提供相同的基线。相信我 - 你想要这个。当你进一步进入html,例如表格或类似的有趣的东西,那么这种事情是绝对的生命保护。

Hope that helps!

希望有所帮助!

#3


0  

You need to reset the default padding and margin on any browser. I usually use this:

您需要在任何浏览器上重置默认填充和边距。我通常使用这个:

*{padding:0;margin:0;}

推荐阅读
author-avatar
董白菜
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有