1

これはおそらく初心者の質問ですが、私は非常にイライラしています。スタイル タグで、上部の青いバーを上部にぴったりと合わせる必要があり、2 つのサイド パネルを側面にぴったり合わせる必要があることを明確に述べています。

しかし、何らかの理由で、HTML の周りに空白のスペースを自由に挿入することができました。

リンクは次のとおりです。http://popularn.com/nate/error.html

左側と上部に白いスペースがあるのがわかりますか?

top:0% と left:0% と言っても、まだ機能しません。それは私を笑っているようで、もう十分です。ドキュメントを top:2% と left:2% から開始しているようで、私にできることは何もありません...

4

3 に答える 3

4

本文からマージンを削除し、左上を 0 に設定し、もちろん position 属性を忘れないでください

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

また - に置くposition:absolute; top:0; left:0;ことbodyは何もしないようなものであり、意味を持たないべきpositionである#top_menuべきではないということですposition: fixedfixes

于 2012-06-18T08:37:13.957 に答える
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.

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.

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.

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.

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.

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.

Hope that helps!

于 2012-06-18T08:49:31.773 に答える
0

どのブラウザでも、デフォルトのパディングとマージンをリセットする必要があります。私は通常これを使用します:

*{padding:0;margin:0;}
于 2012-06-18T08:41:01.907 に答える